can't get my game to work

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

can't get my game to work

Postby gillypie » Sat Mar 29, 2008 2:30 pm

hi!

im trying to make a game in allegro where you are a triangle that fires bullets towards objects to stop them hitting the ground. ive encountered a problem i seem un-able to fix, regarding the box i'm using as an enemy. here is the code:

Code: Select all
#include <allegro.h>


int main() {
   
int rocket_X;
int rocket_Temp_X;
int bullet_X;
int bullet_Y;
int bullet_Temp_X;
int bullet_Temp_Y;
int enemy_X = rand() % 499 + 1;
int enemy_Y;
int enemy_Temp_X;
int enemy_Temp_Y;
int enemy_Speed;
   
allegro_init();
install_keyboard();
set_gfx_mode( GFX_AUTODETECT, 500, 500, 0, 0);


enemy_Speed = 1;
rocket_X = 250;
bullet_Y = 450;

while (!key[KEY_ESC]) {
     
      rocket_Temp_X = rocket_X;
      bullet_Temp_X = bullet_X;
      bullet_Temp_Y = bullet_Y;
      enemy_Temp_X = enemy_X;
      enemy_Temp_Y = enemy_Y;
     
      acquire_screen();
     
      line( screen, 0, 490, 500, 490, makecol( 255, 255, 255));
     
      if (bullet_X > enemy_X) {
      if (bullet_X < (enemy_X + 20)) {
      if (bullet_Y > enemy_Y) {
      if (bullet_Y < (enemy_Y + 40)) {
      bullet_Y = 0;
      enemy_Y = 0;
      enemy_X = rand() % 499 + 1;
      enemy_Speed = enemy_Speed + 1;
      }
      }
      }
      }
     
           
      if (bullet_Y < 0) {
      if (key[KEY_SPACE]) {
      bullet_X = rocket_X;
      bullet_Y = 450; 
      }
      }
     
      if (key[KEY_LEFT]) {
      if (rocket_X > 30) {
      rocket_X = rocket_X - 4; } }
     
      if (rocket_X < 470) {
      if (key[KEY_RIGHT]) {
      rocket_X = rocket_X + 4; } }

      enemy_Y = enemy_Y + enemy_Speed;
      bullet_Y = bullet_Y - 5;
     
      triangle( screen, (rocket_Temp_X - 30), 480, (rocket_Temp_X + 30), 480, rocket_Temp_X, 450, makecol( 0, 0, 0));
      triangle( screen, (rocket_X - 30), 480, (rocket_X + 30), 480, rocket_X, 450, makecol( 255, 255, 255));
     
      circlefill ( screen, bullet_Temp_X, bullet_Temp_Y, 5, makecol( 0, 0, 0));
      circlefill ( screen, bullet_X, bullet_Y, 5, makecol( 255, 255, 255));
     
      rectfill( screen, enemy_Temp_X, (enemy_Temp_X + 20), enemy_Temp_Y, (enemy_Temp_Y + 40), makecol( 0, 0, 0));
      rectfill( screen, enemy_X, (enemy_X + 20), enemy_Y, (enemy_Y + 40), makecol( 255, 255, 255));
     
     
      rest(5);
     

     
      release_screen();      
   }

}
END_OF_MAIN()


thanks :wink:
gillypie
 
Posts: 5
Joined: Fri Mar 21, 2008 10:20 am

Postby MXP » Sat Mar 29, 2008 2:56 pm

What is the problem, exactly?
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby gillypie » Sat Mar 29, 2008 3:13 pm

well when i run it, it comes up with a massive flashing white block. everthing else works. run it and you'll see what i mean.
gillypie
 
Posts: 5
Joined: Fri Mar 21, 2008 10:20 am

Postby MXP » Sat Mar 29, 2008 5:30 pm

I dont have Allegro so I cant compile your program. Describing the problem helps me know what to look for in your program. I see now that you are using rectfill() incorrectly. You list the two x-coordinates and then the two y-coordinates when the parameters should be x1, y1, x2, y2, like this:

Code: Select all
rectfill( screen, enemy_Temp_X, enemy_Temp_Y, (enemy_Temp_X + 20), (enemy_Temp_Y + 40), makecol( 0, 0, 0));
      rectfill( screen, enemy_X, enemy_Y, (enemy_X + 20), (enemy_Y + 40), makecol( 255, 255, 255));
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby gillypie » Sun Mar 30, 2008 2:01 am

k i did this but now the box simply doesn't appear. btw thanks for your help :wink: .
gillypie
 
Posts: 5
Joined: Fri Mar 21, 2008 10:20 am


Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 2 guests

cron