void snakeclass::start() { while(1) { if(collision()) { SDL_Surface* messege; SDL_Color brown = {255, 123, 98}; messege = TTF_RenderText_Solid(font, "GAME OVER!", brown); SDL_Rect gameover = {640/2-40, 170}; SDL_BlitSurface(messege, NULL, screen, &gameover);//========================================================================================= SDL_FreeSurface(messege); SDL_Flip(screen); SDL_Delay(6000); break; } movesnake(); if(direction=='q') break; SDL_Flip(screen); SDL_Delay(del); } }
static int _move(void) { if (!perfs[0] || !perfs[1]) exitSnake(0); /* keep ghostbuster away */ perfs[0]->p_ghostbuster = 0; perfs[1]->p_ghostbuster = 0; if (s_clock == 5) startsnake(); else if (s_clock > 5) { check_explode(); if (!explode) { movesnake(); } else if ((perfs[0]->p_ntorp == 0 && perfs[1]->p_ntorp == 0 && perfs[0]->p_nplasmatorp == 0 && perfs[1]->p_nplasmatorp == 0) || /* xx -- sometimes above doesn't work? */ s_clock - explode > 56) exitSnake(0); } return 1; }
void Snake_GO(SNAKE *snake, int vel, int bound_x, int bound_y, int spawnx, int spawny, FOOD *foo, int foo_num) { SNAKE tsnake = *snake; if(tsnake.ON) { if(tsnake.dead>=1) { tsnake.dead++; //Waits for 50 refreshes before dead snake respawns if(tsnake.dead>50) { //respawns snake start(&tsnake, 0, spawnx, spawny); tsnake.dead=0; } } else { movesnake(&tsnake, tsnake.movin.x, tsnake.movin.y); eatfood(&tsnake, foo, foo_num); edges(&tsnake, bound_x, bound_y); checksnake(&tsnake); } } *snake = tsnake; }
void displaymovement(int snakeXY[][MAX_SIZE], int snakelength, int dir) { int x,y; x = snakeXY[0][snakelength - 1]; y = snakeXY[1][snakelength - 1]; gotoxy(x,y); printf(" "); gotoxy(snakeXY[0][0],snakeXY[1][0]); printf("*"); movesnake(snakeXY, snakelength, dir); gotoxy(snakeXY[0][0],snakeXY[1][0]); printf("X"); gotoxy(1,1); }
void snakeclass::Play() { while (1) { if (collision()) { printw("Game over"); break ; } movesnake(); aff_map(); if (direction == 'q') break ; usleep(del); } }
void gameClass::start() { const int FPS = 60; Uint32 start; while(1) { start = SDL_GetTicks(); movesnake(); if(direction=='q') { break; } SDL_Flip(screen); if(1000/FPS > SDL_GetTicks()-start) { SDL_Delay(1000/FPS-(SDL_GetTicks()-start)); } } }
/** * \brief movesnake Procedure de mise à jour et de deplacement du serpent dans * une direction donne * \param s le serpent a deplacer * \param dir la direction souhaitee */ void movesnake(snake s,direction dir){ if(!estInverse(s.dir[0],dir)){ int i; switch (dir){ case right: for(i=s.taille-1;i>0;i--){ s.pos[i].x=s.pos[i-1].x; s.pos[i].y=s.pos[i-1].y; } s.pos[0].x++; s.dir[0]=dir; break; case left: for(i=s.taille-1;i>0;i--){ s.pos[i].x=s.pos[i-1].x; s.pos[i].y=s.pos[i-1].y; } s.pos[0].x--; s.dir[0]=dir; break; case up: for(i=s.taille-1;i>0;i--){ s.pos[i].x=s.pos[i-1].x; s.pos[i].y=s.pos[i-1].y; } s.pos[0].y--; s.dir[0]=dir; break; case down: for(i=s.taille-1;i>0;i--){ s.pos[i].x=s.pos[i-1].x; s.pos[i].y=s.pos[i-1].y; } s.pos[0].y++; s.dir[0]=dir; break; } } else { movesnake(s,s.dir[0]); } }