EOSERV Forum > Lounge > My First Allegro Game (Pong/Snake)
Topic is locked.
Page: << 1 2 >>
My First Allegro Game (Pong/Snake)
Author Message
Post #87514 My First Allegro Game (Pong/Snake)

Yesterday I decided to learn how to use the Allegro library because everyone else is making cool games and things. Today I decided to make a pong game because its a simple game. What I ended up doing was making a snake game (also simple), so the .exe is named pong but it is actually snake!

Move using the arrow keys, pause using 'p', quit by losing, clicking the X or hitting 'esc'.

For some reason it won't let me run it without the .dll in the same directory, I figure there's a way around this but I'm not sure how to do it. It was created on a windows 7 64-bit machine in Visual Studio 2010.

As of right now it just does all text output to std::cout, I'm too tired to teach myself how to put text on the screen tonight :P

As for graphics, it uses no external files; all (3) bitmaps are generated internally. In case you're wondering why its such a boring screen.

I'd like comments and stuff. Things I should add/try to add, etc. I'm looking to challenge myself and learn something. I'm going to try and attempt pong/breakout later on this week in my free time and slowly add concepts from there. I know that putting the text on the actual screen instead ofcommand prompt is next on my list :D

Download: http://ethanmoffat.web44.net/download/snake-release.rar
Newer: http://ethanmoffat.web44.net/download/snake-release-2.rar
Screenie:

---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};
13 years, 49 weeks ago
Post #87515 Re: My First Allegro Game (Pong/Snake)

Statically link to get it to work without a dll.

---
http://www.addipop.com
13 years, 49 weeks ago
Post #87518 Re: My First Allegro Game (Pong/Snake)

Its good :D but how come the foods arnt randomly positioned? 

---
Andrewbob - I would be on the fucking copter of rofls

Programmer, Web Developer, and Graphics Designer
13 years, 49 weeks ago
Post #87615 Re: My First Allegro Game (Pong/Snake)

I don't think visual studio will let me statically link it..oh well. 

Foods are randomly positioned, there's a random function that generates their location.

---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};
13 years, 49 weeks ago
Post #87622 Re: My First Allegro Game (Pong/Snake)
ethanmoffat posted: (12th Jul 2011 08:03 pm)

I don't think visual studio will let me statically link it..oh well. 

Foods are randomly positioned, there's a random function that generates their location.


Visual studios? Noob, just use codeblocks :P
---
http://www.addipop.com
13 years, 49 weeks ago
Post #87638 Re: My First Allegro Game (Pong/Snake)
Addison posted: (12th Jul 2011 08:19 pm)

ethanmoffat posted: (12th Jul 2011 08:03 pm)

I don't think visual studio will let me statically link it..oh well. 

Foods are randomly positioned, there's a random function that generates their location.


Visual studios? Noob, just use codeblocks :P
I like IntelliSense! And the debugger :P

---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};
13 years, 49 weeks ago
Post #87664 Re: My First Allegro Game (Pong/Snake)
ethanmoffat posted: (12th Jul 2011 08:03 pm)

I don't think visual studio will let me statically link it..oh well. 

Foods are randomly positioned, there's a random function that generates their location.

O.O their in the same spot everytime i play :O takes the fun out of it cuz i no where their going.

---
Andrewbob - I would be on the fucking copter of rofls

Programmer, Web Developer, and Graphics Designer
13 years, 49 weeks ago
Post #87666 Re: My First Allegro Game (Pong/Snake)

Oh yeah. Of course you can statically link.

Select:


Select whichever one applies to you.


Anyways, finally tried out your game. Outputting text isn't hard, except loading the font sucks. You can either put a .ttf font with the file, or make a bitmap font. (I prefer ttf, but for a small game, just building in the bitmap font won't hurt)

Why not make a menu instead of the 5 second countdown. I thought it was broken but then I noticed the countdown :P

Wildsurvival: It randomizes the food for me. It could be his code(unlikely), or something with your OS. Not sure.
---
http://www.addipop.com
13 years, 49 weeks ago
Post #87673 Re: My First Allegro Game (Pong/Snake)
Addison posted: (13th Jul 2011 01:15 am)

Oh yeah. Of course you can statically link.

Select:


Select whichever one applies to you.


Anyways, finally tried out your game. Outputting text isn't hard, except loading the font sucks. You can either put a .ttf font with the file, or make a bitmap font. (I prefer ttf, but for a small game, just building in the bitmap font won't hurt)

Why not make a menu instead of the 5 second countdown. I thought it was broken but then I noticed the countdown :P

Wildsurvival: It randomizes the food for me. It could be his code(unlikely), or something with your OS. Not sure.

I've been trying to set it up to link statically and that guide was the one I used to set it up in the first place. 

For the food - if you're talking about the first time it places the food, that is always in the same place. But it randomizes the location after that.

Here's my random function anyways (makes it a multiple of 10). I seed srand() to time(0):

int RandomInRange(int floor, int cieling)
{
int range = (cieling - floor) + 1;
int ret = floor + (int)(range * rand() / (RAND_MAX + 1.0));

while(ret % 10 != 0)
ret++;

return ret;
}

For fonts - do you know a good tutorial? It initializes my font object to NULL every time I try to load.


ALLEGRO_FONT *font = NULL;
font = al_load_font("font.pcx",10,0);

Where "font.pcx" is the font in the output directory. I used a converter that takes the .ttf file and outputs a .pcx I found on the Allegro site.
---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};
13 years, 49 weeks ago
Post #87675 Re: My First Allegro Game (Pong/Snake)

Actually, linking it statically just depends on what libs you link.


Instead of

liballegro-5.0.3-monolith-md.a

use

liballegro-5.0.3-monolith-static-mt.a


That's really all.


You need to call srand once before calling rand. That might be why.

Yes, that code should work for loading the font.

Instead of two lines though, it can just be:

ALLEGRO_FONT *font = al_load_font("font.pcx", 10, 0);

if (!font)

    printf("Failure...\n");


---
http://www.addipop.com
13 years, 49 weeks ago
Post #87701 Re: My First Allegro Game (Pong/Snake)

Or write a nice font manager :)

---
I am an alien and not crazy!
13 years, 49 weeks ago
Post #87708 Re: My First Allegro Game (Pong/Snake)

For a snake game, yeah right. Not worth it.

---
http://www.addipop.com
13 years, 49 weeks ago
Post #87709 Re: My First Allegro Game (Pong/Snake)

I have a skeleton that I have saved as a template so to me it don't matter if it's a basic snake game I'd still use my font loader :P

---
I am an alien and not crazy!
13 years, 49 weeks ago
Post #87823 Re: My First Allegro Game (Pong/Snake)
Addison posted: (13th Jul 2011 02:47 am)

Actually, linking it statically just depends on what libs you link.


Instead of

liballegro-5.0.3-monolith-md.a

use

liballegro-5.0.3-monolith-static-mt.a


That's really all.


Linking the static libraries just gives me build errors. I don't know if this matters but the ones I have are all .lib files. 

As for random, it is already seeded at the beginning of the program.

As for the fonts, it's still not loading the .pcx file. I'm going to keep playing around with that one.
---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};
13 years, 49 weeks ago
Post #87824 Re: My First Allegro Game (Pong/Snake)

the gameplay is a lot faster than the snake I made in pascal :L! Kinda difficult :X

---
If money doesn't grow on trees, then why do banks have branches?
13 years, 49 weeks ago
Page: << 1 2 >>
Topic is locked.
EOSERV Forum > Lounge > My First Allegro Game (Pong/Snake)