Commit aaab82b0 authored by Fan FEI's avatar Fan FEI

version "3.1"

  Add wormhole: snakes can cross the border
parent 1294c380
......@@ -33,7 +33,7 @@
// Some Defines
//----------------------------------------------------------------------------------
#define SNAKE_LENGTH 256
#define SQUARE_SIZE 31
#define SQUARE_SIZE 39
Music soundtrack;
......@@ -196,7 +196,7 @@ void UpdateGame(void)
// Snake movement
for (int i = 0; i < counterTail; i++) snakePosition[i] = snake[i].position;
if ((framesCounter%5) == 0)
if ((framesCounter%5) == 0) // The snake advances by one step every five frames
{
for (int i = 0; i < counterTail; i++)
{
......@@ -211,17 +211,26 @@ void UpdateGame(void)
}
// Wall behaviour
if (((snake[0].position.x) > (screenWidth - offset.x)) ||
((snake[0].position.y) > (screenHeight - offset.y)) ||
(snake[0].position.x < 0) || (snake[0].position.y < 0))
/*
if (((snake[0].position.y) > (screenHeight - offset.y)) || (snake[0].position.y < 0))
{
gameOver = true;
}
*/
if ((snake[0].position.x) > (screenWidth - offset.x))
snake[0].position.x = offset.x/2;
if ((snake[0].position.y) > (screenHeight - offset.y))
snake[0].position.y = offset.y/2;
if ((snake[0].position.x < 0))
snake[0].position.x += (screenWidth - offset.x);
if ((snake[0].position.y < 0))
snake[0].position.y += (screenHeight - offset.y);
// Collision with yourself
for (int i = 1; i < counterTail; i++)
{
if ((snake[0].position.x == snake[i].position.x) && (snake[0].position.y == snake[i].position.y)) gameOver = true;
if ((snake[0].position.x == snake[i].position.x) && (snake[0].position.y == snake[i].position.y))
gameOver = true;
}
// Fruit position calculation
......@@ -290,8 +299,8 @@ void DrawGame(void)
DrawRectangleV(fruit.position, fruit.size, fruit.color);
// Show time and score
DrawText(TextFormat("TIME : %.1f s", (float)framesCounter/60), SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE, DARKGRAY);
DrawText(TextFormat("SCORE: %03d", counterTail), SQUARE_SIZE, SQUARE_SIZE*2, SQUARE_SIZE, DARKGRAY);
DrawText(TextFormat("TIME : %.1f s", (float)framesCounter/60), screenWidth-SQUARE_SIZE*8, SQUARE_SIZE, SQUARE_SIZE, DARKGRAY);
DrawText(TextFormat("SCORE: %03d", counterTail), screenWidth-SQUARE_SIZE*8, SQUARE_SIZE*2, SQUARE_SIZE, DARKGRAY);
// Show pause
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment