Allegro Space-shooter Game
Octavarium XI

Hello, everyone!

I'm Octavarium XI. I've been programming C/C++ for about 10 months now.

Just today, I started programming a concept I've been thinking about a lot... And I already have a problem (Never good :p)

I use Dev-C++ and Notepad++ (just a quick note)

First, I tried using classes for drawing and key input, but it kept screwing up. So I decided to just use normal old functions.

Now, it'll compile, yes, but for some reason it just doesn't work. Can someone clarify the reason?

EDIT: Code removed, I'll attach it

Thanks!
Octavarium XI

verthex

I use Dev-C++ and Notepad++ (just a quick note)

I suggest switching to code::blocks and also please paste your code. Nothing personal but everyone here is a stranger and that could be a virus for all I know. I just dont have antivirus running right now. ;D

Octavarium XI

Yes, you have reasons to be suspicous. A C++/ASM programmer who has 2 posts?

Anyways, here's the code.

The parenthesis and spacing are screwed up because of Allegro.cc; I don't know why o_O

#SelectExpand
1#include <allegro.h> 2 3void init(); 4void deinit(); 5 6int endflag = 0 ; //Flag to end the game 7int curbul = 1 ; //Current bullet 8double bulx[10] ; //Bullet X coordinate 9double buly[10] ; //Bullet Y coordinate 10bool live[10] ; //Is the bullet live? 11double xturn = 0.0; //Bullet spin/turn 12double yturn = 5.0; //Bullet speed forward 13 14 15void left() 16{ 17 if (xturn >= -5) 18 xturn = (xturn - 0.1); 19} //void left() 20 21void right() 22{ 23 if (xturn <= 5) 24 xturn = (xturn + 0.1); 25} //void right() 26 27void checkforkey() 28{ 29 if (key[KEY_LEFT]){ 30 left(); 31 } 32 else if (key[KEY_RIGHT]){ 33 right(); 34 } 35 else if (key[KEY_SPACE]){ 36 if (curbul < 11) 37 { 38 live[curbul] = true; 39 bulx[curbul] = 120; 40 buly[curbul] = 450; 41 ++curbul; 42 } //if (curbul < 11) 43 } //else if (key[KEY_SPACE]) 44} //void checkforkey() 45 46void checkfordraw() 47{ 48 int counter = 0; 49 for( counter = 1 ; counter == 10 ; ++counter ) 50 { 51 if ( live[counter] = true ) 52 { 53 circlefill( 54 screen, 55 bulx[counter], 56 buly[counter], 57 3, 58 makecol( 59 255, 60 123, 61 123 62 ) //makecol() 63 );//circlefill() 64 bulx[counter] = bulx[counter] + xturn; 65 buly[counter] = buly[counter] - yturn; 66 } //if ( live[counter] = true ) 67 } //for( counter == 1 ; counter == 10 ; ++counter ) 68 69 circlefill( 70 screen, 71 120, 72 450, 73 20, 74 makecol( 75 255, 76 255, 77 255 78 ) //makecol() 79 ); //circlefill() 80} //void checkfordraw() 81 82int main() 83{ 84 init(); 85 86 while (endflag == 0) 87 { 88 acquire_screen(); 89 90 if (key[KEY_ESC]) 91 endflag = 1; 92 93 checkforkey(); 94 checkfordraw(); 95 96 release_screen(); 97 clear_keybuf(); 98 99 rest(50); 100 } 101 102 deinit(); 103 return 0; 104} //int main() 105END_OF_MAIN() 106 107void init() 108{ 109 int depth, res; 110 allegro_init(); 111 depth = desktop_color_depth(); 112 if (depth == 0) depth = 32; 113 set_color_depth(depth); 114 res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 240, 500, 0, 0); 115 if (res != 0) { 116 allegro_message(allegro_error); 117 exit(-1); 118 } 119 120 install_timer(); 121 install_keyboard(); 122 install_mouse(); 123} //void init() 124 125void deinit() 126{ 127 clear_keybuf(); 128} //void deinit()

verthex

You just have to click the help button and use the CODE tag to enclose your code.

Octavarium XI

Thanks, but why won't it work? o:

verthex

I might be mistaken but your global declaration for xturn is decremented until -5 and incremented until 5 only once and then it stops the motion. I think you need to somehow keep this variable in a different place, not globally.

void left() { if (xturn >= -5) xturn = (xturn - 0.1); } //void left() void right() { if (xturn <= 5) xturn = (xturn + 0.1); } //void right()

Octavarium XI

Well yah, but why won't it draw the bullets? o:

verthex

Is your live counter in sync with your bullet? I can't really tell cause

A. Im tired and my eyes are like :o
B. I'm going to pass out. ;)

kenmasters1976

Haven't tried your program, just checked your code. I'm guessing you want to draw the bullets in your checkfordraw() function, right?. Then I guess the problem is your for loop. The second expression in a for is a condition, so for( counter = 1 ; counter == 10 ; ++counter ) will never be executed, you probably meant for( counter = 1 ; counter <= 10 ; ++counter ).

Octavarium XI

Oshi- that explains alot >_< /facepalm

Thanks for the help!

gnolam

If you're wondering why so few people are responding, it's because "it doesn't work" is never, ever an acceptable problem description. Is it not compiling? Is it crashing? Is it running but showing some sort of wrong result? Until you describe what the problem actually is, in detail (e.g. "When I compile it, I get the following error: ...", "It compiles without warnings, but when I run it the colors are all weird - here's a screenshot"), few people are going to take the time to read through your code. I know I won't. :P

But from the one line kenmasters1976 quoted, there's a good chance you have a buffer overrun...

kenmasters1976
gnolam said:

But from the one line kenmasters1976 quoted, there's a good chance you have a buffer overrun...

Let me have another look at his code... yes, you're right.

OnlineCop
gnolam said:

"it doesn't work" is never, ever an acceptable problem description

Yeah... it doesn't work.

Ron Novy

Shouldn't it be for(counter = 0; counter < 10 ; counter++) ?

type568
Ron Novy said:

Shouldn't it be for(counter = 0; counter < 10 ; counter++) ?

He has his own concept, he said.. Respect the youth!

Bob Keane

bool live[10] ; //Is the bullet live?

I've got nothing to help you, but I was wondering if you are using a bool on an array to account for multiple bullets on the screen?

kenmasters1976
Ron Novy said:

Shouldn't it be for(counter = 0; counter < 10 ; counter++) ?

Hopefully he'll be able to fix that.

Bob Keane said:

I've got nothing to help you, but I was wondering if you are using a bool on an array to account for multiple bullets on the screen?

Up to 10 live bullets on screen. Maybe he should change that hardcoded 10 with a #define MAX_BULLETS 10. Of course, he'll also have to take care of if (curbul < 11) 'cause that would mean a crash if he actually ever called checkforkey() with curbul = 10.

Thread #602027. Printed from Allegro.cc