sry for the late reply, i uh, sorta forgot
CODE
* ttmt -> tom's ten minute tron */
#include
#define TICK_INTERVAL 20
int board[100][80];
int redX, redY, blueX, blueY;
int redDir, blueDir;
int redScore, blueScore;
volatile int count;
int lastcount;
static Uint32 next_time;
SDL_Surface *screen;
SDL_Event event;
int exitloop;
void drawBoard();
void redCrash();
void blueCrash();
void clearBoard();
void moveBlue();
Uint32 time_left(void)
{
Uint32 now;
now = SDL_GetTicks();
if (next_time <= now)
return 0;
else
return next_time - now;
}
void startGame()
{
clearBoard();
redX = 25;
redY = 40;
redDir = 0;
blueX = 75;
blueY = 40;
blueDir = 0;
board[25][40] = 1;
board[75][40] = 2;
}
void clearBoard()
{
int a,b;
for (a=0;a<100;a++)
{
for (b=0;b<80;b++)
{
if (a == 0 || a == 99 || b == 0 || b == 79)
board[a]=3;
else
board[a]=0;
}
}
}
void drawBoard()
{
char text[20];
SDL_Rect r;
//clear_to_color(buffer,makecol(50,50,50));
//SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 50,50,50));
r.w = 500;
r.h = 400;
r.x = 70;
r.y = 40;
SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0,0,0));
//rectfill(buffer, (SCREEN_W-500)/2, (SCREEN_H-400)/2, 500 + ((SCREEN_W-500)/2), 400 + ((SCREEN_H-400)/2),makecol(0,0,0));
int a,b;
r.w = 5;
r.h = 5;
for (a=0;a<100;a++)
{
for (b=0;b<80;b++)
{
r.x = 70 + (a*5);
r.y = 40 + (b*5);
if (board[a] == 1)
SDL_FillRect(screen,&r,SDL_MapRGB(screen->format, 255,0,0));
else if (board[a] == 2)
SDL_FillRect(screen,&r,SDL_MapRGB(screen->format, 0,0,255));
else if (board[a] == 3)
SDL_FillRect(screen,&r,SDL_MapRGB(screen->format, 0,200,0));
}
}
//sprintf(text, "%i", redScore);
//textout(buffer,font,text,25,25,makecol(255,0,0));
//sprintf(text, "%i", blueScore);
//textout(buffer,font,text,SCREEN_W-25,25,makecol(0,0,255));
//blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
SDL_Flip(screen);
}
void counter ()
{
count++;
}
int nextObj(int dirA)
{
int a;
int moveX, moveY;
moveX = 0;
moveY = 0;
if (dirA == 0)
{
moveY = -1;
} else if (dirA == 1) {
moveX = 1;
} else if (dirA == 2) {
moveY = 1;
} else if (dirA == 3) {
moveX = -1;
}
for (a=1;a<15;a++)
{
/*if (blueX+(moveX*a) < 100 && blueY+(moveY*a) < 80 && blueX+(moveX*a) > -1 && blueY+ (moveY*a) > -1)
{*/
if (board[blueX+(moveX*a)][blueY+(moveY*a)] != 0)
return a;
/*}*/
}
return a;
}
void moveBlue()
{
int moveX = 0;
int moveY = 0;
int a;
int trouble= 0;
int choiceA;
int choiceB;
/*
if (blueDir == 0)
{
moveY = -1;
} else if (blueDir == 1) {
moveX = 1;
} else if (blueDir == 2) {
moveY = 1;
} else if (blueDir == 3) {
moveX = -1;
}
for (a=1;a<4;a++)
{
if (blueX+(moveX*a) < 100 && blueY+(moveY*a) < 80)
{
if (board[blueX+(moveX*a)][blueY+(moveY*a)] != 0)
trouble = 1;
}
} */
if (nextObj(blueDir) < 5 || rand() % 50 == 7)
{
choiceA = blueDir + 1;
choiceB = blueDir - 1;
if (choiceB < 0) choiceB = 3;
if (choiceA > 3) choiceA = 0;
if (nextObj(choiceA) > nextObj(choiceB))
{
blueDir = choiceA;
} else if (nextObj(choiceA) < nextObj(choiceB)) {
blueDir = choiceB;
} else if (nextObj(choiceA) != 1){
a = (rand() % 2);
if (a == 0) a = -1;
blueDir+= a;
if (blueDir < 0) blueDir = 3;
if (blueDir > 3) blueDir = 0;
}
}
}
void playgame()
{
int c;
startGame();
lastcount = count;
next_time = SDL_GetTicks() + TICK_INTERVAL;
//while ();
while (exitloop == 0)
{
while (time_left() > 0)
{
if (SDL_PollEvent(&event) && event.type == SDL_JoyHatMotion)
{
if (event.jhat.value == SDL_HAT_UP)
{
reDir = 0;
}
else if (event.jhat.value == SDL_HAT_RIGHT)
{
reDir = 1;
}
else if (event.jhat.value == SDL_HAT_DOWN)
{
reDir = 2;
}
else if (event.jhat.value == SDL_HAT_LEFT)
{
reDir = 3;
}
else
{
SDL_Quit();
}
}
/*
//SDL_PollEvent( &event);
if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_UP && redDir != 2) {
redDir = 0;
} else if (event.key.keysym.sym == SDLK_RIGHT && redDir != 3) {
redDir = 1;
} else if (event.key.keysym.sym == SDLK_DOWN && redDir != 0) {
redDir = 2;
} else if (event.key.keysym.sym == SDLK_LEFT && redDir != 1) {
redDir = 3;
//} else if (c == KEY_ESC) {
//exitloop = 1;
} else {
SDL_Quit();
}
*/ }
}
next_time+= TICK_INTERVAL;
if (redDir == 0) {
if (board[redX][redY-1] == 0)
{
redY--;
board[redX][redY] = 1;
} else {
redCrash();
}
} else if (redDir == 1) {
if (board[redX+1][redY] == 0)
{
redX++;
board[redX][redY] = 1;
} else {
redCrash();
}
} else if (redDir == 2) {
if (board[redX][redY+1] == 0)
{
redY++;
board[redX][redY] = 1;
} else {
redCrash();
}
} else if (redDir == 3) {
if (board[redX-1][redY] == 0)
{
redX--;
board[redX][redY] = 1;
} else {
redCrash();
}
}
moveBlue();
if (blueDir == 0) {
if (board[blueX][blueY-1] == 0)
{
blueY--;
board[blueX][blueY] = 2;
} else {
blueCrash();
}
} else if (blueDir == 1) {
if (board[blueX+1][blueY] == 0)
{
blueX++;
board[blueX][blueY] = 2;
} else {
blueCrash();
}
} else if (blueDir == 2) {
if (board[blueX][blueY+1] == 0)
{
blueY++;
board[blueX][blueY] = 2;
} else {
blueCrash();
}
} else if (blueDir == 3) {
if (board[blueX-1][blueY] == 0)
{
blueX--;
board[blueX][blueY] = 2;
} else {
blueCrash();
}
}
drawBoard();
lastcount = count;
}
}
Void XboxStartup(int argc, char *argv[])
{
int a=0;
exitloop = 0;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK);
screen = SDL_SetVideoMode(640,480,32, SDL_HWSURFACE | SDL_DOUBLEBUF);
int c;
count = 0;
//LOCK_VARIABLE(count);
//LOCK_FUNCTION(counter);
//install_int_ex(counter, BPS_TO_TIMER(40));
playgame();
}
//END_OF_MAIN();
void redCrash()
{
blueScore++;
playgame();
}
void blueCrash()
{
redScore++;
playgame();
}
there ya go... gl