Home » Posts tagged "Allegro"

Setup Allegro tutorial part 1

Introduction:
I haven’t seen any up-to-date Allegro 5 tutorial that focuses on learning via making games. All I found online were either small examples (like moving rectangle) about particular functions of Allegro 5, or complete guides for older versions. That’s why I decided to write down this small series of articles.
My goal is to teach various parts of Allegro gaming library, and basics of game programming concepts via making some – at first simple – game prototypes.
Tutorial assumes at least a basic knowledge of C/C++ programming, and although all examples were written and tested on Visual Studio 2010 under Windows 7 you can use any other IDE you like.

You can view code for this tutorial on github!
Read more

One thing at one time.

I decided to do more often, but shorter sessions. It suits these short free time gaps I have lately.
These last sessions were another Refactoring ones with aim of extracting functions, so one could do only one thing, instead of all purpose procedures like DeleteSpritesAndFonts(), or two purpose DrawScene().

Soo little changes list:

-> Cutted PrepareSpritesAndFonts() and DeleteSpritesAndFonts() to four functions:
PrepareSprites, PrepareFonts, DeleteSprites, DeleteFonts.
Now all that’s inside PrepareSpritesAndFonts is:

bool Game::PrepareSpritesAndFonts()
{

	if( PrepareSprites())
	{
		bool ret = PrepareFonts();
		return ret;
	}
	else
		return false;
} 

I think it looks better this way. Now it’s easy to tell what’s really inside, and extracting DeleteSprites() helped to delete redundant cleaning after failing with preparing fonts.

-> Also I properly named arguments in headers, so that intelisense can help what’s the meaning of what variable passed to methods (yeah, the fact I haven’t done it at the begining sucks).

-> Bid farewell to victory, running and pause variables, and welcome our new datatype GameState enum! Now with all new Defeat state.
Although it was a little confusing to replace them at first, because of

while(running)
{
   // Loop with redrawing and listening to keyboard events
} 

loop, that created a little confusion. If I’d replace ‘running’ with a condition like (gameState != Victory && gameState != Defeat) it’d be confusing. Why game should run in paused state, but should not in Victory, nor Defeat?
After putting some thoughts I decided to make while a simple infinite loop with breaks after goint into Victory or Defeat. I bet it’s still far from perfection but I like it. For now.

-> Extracted “DrawPause()” from DrawScene – it was unnecessary to check all the time whether game is running and then if it’s paused.

-> Probably it’s a bit obvious, but al_flip_display() can be called only once. It’s unnecessary to do something like that:

	if (gameState == GameState::Running)
		DrawScene();
	else if (gameState == GameState::Pause) 
		DrawPause();
	else 
		DrawEnd();

with ending all procedures with al_flip_display. It’s enough to call it at the end of Draw calling function.

-> Slight renaming. Variable Hp is now known as Lives, and pong is now a pongSprite.

As always you can find changes in repository.

A new begining.

Soo… hello.

The sole reason for creating this developement blog was to widen audience, whom can read my thoughts and ideas. For the time being ideas for One game a month challenge, maybe from time to time about past projects done for graduation. Time will tell what exactly you’ll find on this devblog in future (:

For the moment:
Here is a link to repository with a Pongoid, simple (done in a ~1 hour) arcanoid clone done with cpp and allegro library.

It’s still more a draft than finished project, so I didn’t uploaded it to ogam yet, but… maybe in a few weeks after exams (: