Advertisement

allegro running ewrror..

Started by May 16, 2011 10:45 AM
-1 comments, last by instantpig 13 years, 6 months ago
Im working on game programming, this is compiled n run well. However, after few second after running, it just stop!. I don't understand why.. please somebody help me. :(


/*Start Scrolling game */

#define DOWN_LEFT 0
#define UP_LEFT 1
#define FOWARD 2

#include<allegro.h>

/* prototypes */
void respondToKeyboard(void);
void moveBall();
void moveTimmer();
void redirection();


// BITMAP *bgp;
BITMAP *pnter;
BITMAP *buffer;
BITMAP *ball;
BITMAP *bgp;
BITMAP *timmer;

int arrow;
int ball_x =600; /* coordinate of ball */
int ball_y = 240;
int time_shot_x;
int dct = 0, *direction = &dct;
int ball_position = 2; /* ball start position */
// int score; /* score of the star */
// int life; /* chance of playing game. */

int main(void)
{

allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
bgp = load_bitmap("pictures\\bgp.bmp", NULL);
pnter = load_bitmap("pictures\\pnter.bmp", NULL);
ball = load_bitmap("pictures\\ball.bmp", NULL); /* ball is the moving obstarcle */
timmer = load_bitmap("pictures\\time.bmp",NULL);
time_shot_x = 599;
// ball_x = 600;
// ball_y = SCREEN_H / ball_position; /*************** right now ball keep comming out from 240 ********/
buffer = create_bitmap(SCREEN_W, SCREEN_H);
arrow = SCREEN_H / 2;
srand(time(NULL));
*direction = rand() % 3;/*ball move three differences direction, */

while( !key[KEY_ESC])
{
// moveBall();
moveTimmer();
respondToKeyboard();
blit( ball, screen, 0, 0, ball_x, ball_y, ball->w, ball->h);
blit( bgp, screen, 0, 0, 0, 0, bgp->w, bgp->h);
blit( pnter, screen, 0, 0, 0, arrow, pnter->w, pnter->h);
blit( timmer, screen, 0, 0, time_shot_x, 0, timmer->w, timmer->h);
clear_bitmap(buffer);
}

destroy_bitmap(ball);
destroy_bitmap(timmer);
destroy_bitmap(buffer);
destroy_bitmap(pnter);
destroy_bitmap(bgp);

return 0;
}
END_OF_MAIN()

void moveTimmer()
{
moveBall();
--time_shot_x;
if(time_shot_x == 1){
ball_position = rand() % 6; /* ball's different start position */
*direction = rand() % 3;
ball_y = SCREEN_H / ball_position;
ball_x = 600;
}
else if(time_shot_x <= 0){
time_shot_x = 660;
}

}


void moveBall()
{
switch(*direction) {
case DOWN_LEFT:
--ball_x; /* move the ball to the left */
++ball_y; /* move the ball down */
break;
case UP_LEFT:
--ball_x; /* move the ball to the left */
--ball_y; /* move the ball down */
break;
case FOWARD:
--ball_x; /* move the ball to the left */
break;
} /*end switch */

if(ball_y <= 5 || ball_y >=440)
redirection(); /* bounce the ball */

/* if the ball is in range of the */
if(ball_x < 30 &&(*direction == DOWN_LEFT|| *direction == UP_LEFT))
{
/*if the arrow in the way */
if( ball_y > (arrow - 30) || ball_y < (arrow + 30))
redirection(); // later on add crush, and point down. when point is 0. game over.
else if(ball_x <= -20){}
// call the another ball from right.
} // end if
}

void respondToKeyboard()
{
if(key[KEY_UP])
arrow -= 3;
if(key[KEY_DOWN])
arrow += 3;

if( arrow < 5)
arrow = 5;
else if( arrow > 410)
arrow = 410;
}

void redirection()
{
if(*direction == 0)
*direction = 1;
else if(*direction == 1)
*direction = 0;
}

This topic is closed to new replies.

Advertisement