|
贪吃蛇源程序(20) traceon->posy = traceon->pre->posy + SCALE; break; case MOVE_LEFT: traceon->posx = traceon->pre->posx + SCALE; traceon->posy = traceon->pre->posy; break; case MOVE_DOWN: traceon->posx = traceon->pre->posx; traceon->posy = traceon->pre->posy - SCALE; break; case MOVE_RIGHT: traceon->posx = traceon->pre->posx - SCALE; traceon->posy = traceon->pre->posy; break; default: break; } traceon->next_move = traceon->pre->next_move; traceon->pre_move = traceon->pre->next_move; traceon->beEaten = 1; } } /* sub function: sort_all() */ /* function:this function will calculate the next position of snake */ /* and it is assume the snake has move to next position,but*/ /* haven't appeared yet. */ void sort_all() { /* sort all food,include snake head,and virtual place */ FOOD_INFOR_PTR traceon; void *buf; int size; size = imagesize(snake_head.posx - SCALE / 2,snake_head.posy - SCALE / 2, snake_head.posx + SCALE / 2,snake_head.posy + SCALE / 2); buf = malloc(size); getimage(snake_head.posx - SCALE / 2,snake_head.posy - SCALE / 2, snake_head.posx + SCALE / 2,snake_head.posy + SCALE / 2,buf); putimage(snake_head.posx - SCALE / 2,snake_head.posy - SCALE / 2,
|