A89: Help debugging program...
[Prev][Next][Index][Thread]
A89: Help debugging program...
Hi. Sorry to have to keep asking this, but can someone help me debug my C
program? It's just a very simple game (very early demo right now) in which
you must dodge the oncoming balls. The balls drop straight down, and after
the first ball drops 10 pixels, then a second one drops down (in a different
location). Right now only one ball drops down at a time, but I'll add more in
the final version. For some reason, the sprites are displayed wrong and the
program doesn't erase the old sprite before replacing it with a new one (when
the balls drop and you (the ship) move, it makes a line). Also, once I press
an arrow key to move the ship, it just continues on in that direction until
it loops around the screen and then starts again, but only 1 pixel higher and
just makes a black line, as do the balls. I've been trying to debug this for
a few hours, but as soon as I solve one problem, more arise. Maybe if someone
else looks at it they'll see the bug(s). Keep in mind that I'm only a
beginner, and this is my first C game (sorry for the long e-mail) :)
Thanks,
Josh
<A HREF="http://pa.ticalc.org">Programmers Anonymous</A> Member
#include <nostub.h>
#include <printf.h>
#include <kbd.h>
#include <graph.h>
#include <system.h>
int _ti89;
unsigned int rand_seed=0;
static int highscore=0;
int score=0;
int random(int x)
{
return ((rand_seed=(75*rand_seed+1))>>4)%x;
}
void end(int score)
{
ClrScr();
printf_xy(0,0,"Game Over");
if(score>highscore)
{
highscore=score;
printf_xy(0,5,"New High Score of %d!",score);
}
}
void _main(void)
{
int ball_x[10]={0,0,0,0,0,0,0,0,0,0};
int ball_y[10]={0,0,0,0,0,0,0,0,0,0};
int ship_x=72;
int ship_y=84;
int key_value=0;
int count=0;
int ball[16] = { 0x0000,
0x0000,
0x0000,
0x0000,
0x03C0,
0x07E0,
0x0FF0,
0x0FF0,
0x0FF0,
0x0FF0,
0x07E0,
0x03C0,
0x0000,
0x0000,
0x0000,
0x0};
int ship[16] = { 0x0180,
0x03C0,
0x07E0,
0x0FF0,
0x1FF8,
0x3FFC,
0x7FFE,
0xFFFF,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0};
int blank[16] = { 0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0};
ICON* ball_pt=&ball[0];
ICON* ship_pt=&ship[0];
ICON* blank_pt=&blank[0];
ClrScr();
printf_xy(0,0,"Dodge-Em's v0.1");
printf_xy(0,10,"by Josh Hill");
ngetchx();
GKeyFlush();
DrawIcon(ship_x,ship_y,ship_pt,A_REPLACE);
while(1)
{
ball_x[0]=random(149);
ball_y[0]=-5;
for(count=1;count<=10;count++)
{
DrawIcon(ball_x[0],ball_y[0]++,blank_pt,A_REPLACE);
DrawIcon(ball_x[0],ball_y[0],ball_pt,A_REPLACE);
if((ball_x[0]+12>=ship_x && ball_x[0]-4>=ship_x+8) && (ball_y[0]+8>=ship_y && ball_y[0]-8<=ship_y+16))
end(score);
key_value=kbhit();
GKeyFlush;
if(key_value!=0)
{
if(key_value==344)
{
DrawIcon(ship_x++,ship_y,blank_pt,A_REPLACE);
DrawIcon(ship_x,ship_y,ship_pt,A_REPLACE);
}
if(key_value==338)
{
DrawIcon(ship_x--,ship_y,blank_pt,A_REPLACE);
DrawIcon(ship_x,ship_y,ship_pt,A_REPLACE);
}
if(key_value==264)
end(score);
if(key_value==263)
off();
}
if(ball_x[0]+4==100) score+=100;
}
}
}