Code: Select all
if (snake.state != RETREATING)
//if snake isn't within a certain radius of the player, set state to slithering
if (player.hb_x < snake.x)
if (snake.x - player.hb_x > 120)
snake.state = SLITHERING;
else
snake.state = ATTACKING;
else if (snake.hb_x < player.x)
if (player.x - snake.hb_x > 120)
snake.state = SLITHERING;
else
snake.state = ATTACKING;
else if (player.hb_y < snake.y)
if (snake.y - player.hb_y > 100)
snake.state = SLITHERING;
else
snake.state = ATTACKING;
else if (snake.hb_y < player.y)
if (player.y - snake.hb_y > 100)
snake.state = SLITHERING;
else
snake.state = ATTACKING;
else
snake.state = ATTACKING;
else
//move snake in its direction at 1 pixel per frame
//resolve collision with background
if (snake.phi_timer == 0) //end of post-hit invincibility
snake.state = SLITHERING;
//exit routine
if (snake.state == SLITHERING)
//randomly move about at .5 pixels per frame, changing directions every second
//resolve collision with the background
else if (snake.state == ATTACKING)
if (player.hb_y < snake.y)
snake.dir = UP;
//move snake up 1 pixel per frame
//resolve collision with background
else if (player.y > snake.hb_y)
snake.dir = DOWN;
//move snake down 1 pixel per frame
//resolve collision with background
else if (player.hb_x < snake.x)
snake.dir = LEFT;
//move snake left 1 pixel per frame
//resolve collision with background
else if (player.x > snake.hb_x)
snake.dir = RIGHT;
//move snake right 1 pixel per frame
//resolve collision with background
else
if (snake collided with player's weapon)
snake.state = RETREATING;
snake.phi_timer = 60;
//set snake direction to opposite of player's direction
//hurt snake, play a sound effect, etc
else
//snake collided with player
//hurt player, put player into post-hit invincibility, play a sound effect, etc