Commit b793d23f authored by Fan FEI's avatar Fan FEI

version "0.1"

  add notes
parent 36e2a683
...@@ -43,8 +43,8 @@ typedef struct Food { ...@@ -43,8 +43,8 @@ typedef struct Food {
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Global Variables Declaration // Global Variables Declaration
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
static const int screenWidth = 800; static const int screenWidth = 1500; //Set the width of the game interface
static const int screenHeight = 450; static const int screenHeight = 1500; //Set the Height of the game interface
static int framesCounter = 0; static int framesCounter = 0;
static bool gameOver = false; static bool gameOver = false;
...@@ -73,9 +73,9 @@ int main(void) ...@@ -73,9 +73,9 @@ int main(void)
{ {
// Initialization (Note windowTitle is unused on Android) // Initialization (Note windowTitle is unused on Android)
//--------------------------------------------------------- //---------------------------------------------------------
InitWindow(screenWidth, screenHeight, "sample game: snake"); InitWindow(screenWidth, screenHeight, "sample game: snake By FanFEI"); //Initialize the interface and title
InitGame(); InitGame();//Initialize the game
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 60, 1); emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
...@@ -110,10 +110,10 @@ int main(void) ...@@ -110,10 +110,10 @@ int main(void)
void InitGame(void) void InitGame(void)
{ {
framesCounter = 0; framesCounter = 0;
gameOver = false; gameOver = false; //Game state
pause = false; pause = false;
counterTail = 1; counterTail = 2; //The initial length of the snake
allowMove = false; allowMove = false;
offset.x = screenWidth%SQUARE_SIZE; offset.x = screenWidth%SQUARE_SIZE;
...@@ -125,8 +125,8 @@ void InitGame(void) ...@@ -125,8 +125,8 @@ void InitGame(void)
snake[i].size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; snake[i].size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE };
snake[i].speed = (Vector2){ SQUARE_SIZE, 0 }; snake[i].speed = (Vector2){ SQUARE_SIZE, 0 };
if (i == 0) snake[i].color = DARKBLUE; if (i == 0) snake[i].color = DARKBLUE; //Snake head color
else snake[i].color = BLUE; else snake[i].color = BLUE; //Snake body color
} }
for (int i = 0; i < SNAKE_LENGTH; i++) for (int i = 0; i < SNAKE_LENGTH; i++)
...@@ -134,7 +134,7 @@ void InitGame(void) ...@@ -134,7 +134,7 @@ void InitGame(void)
snakePosition[i] = (Vector2){ 0.0f, 0.0f }; snakePosition[i] = (Vector2){ 0.0f, 0.0f };
} }
fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; //The color, coordinates and status of the props
fruit.color = SKYBLUE; fruit.color = SKYBLUE;
fruit.active = false; fruit.active = false;
} }
...@@ -144,7 +144,7 @@ void UpdateGame(void) ...@@ -144,7 +144,7 @@ void UpdateGame(void)
{ {
if (!gameOver) if (!gameOver)
{ {
if (IsKeyPressed('P')) pause = !pause; if (IsKeyPressed('P')) pause = !pause; //Keyboard input p pause
if (!pause) if (!pause)
{ {
...@@ -204,10 +204,10 @@ void UpdateGame(void) ...@@ -204,10 +204,10 @@ void UpdateGame(void)
// Fruit position calculation // Fruit position calculation
if (!fruit.active) if (!fruit.active)
{ {
fruit.active = true; fruit.active = true; //Randomly generate a fruit on the map
fruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 }; fruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 };
for (int i = 0; i < counterTail; i++) for (int i = 0; i < counterTail; i++) //The position of the fruit will not overlap with the snake
{ {
while ((fruit.position.x == snake[i].position.x) && (fruit.position.y == snake[i].position.y)) while ((fruit.position.x == snake[i].position.x) && (fruit.position.y == snake[i].position.y))
{ {
...@@ -231,7 +231,7 @@ void UpdateGame(void) ...@@ -231,7 +231,7 @@ void UpdateGame(void)
} }
else else
{ {
if (IsKeyPressed(KEY_ENTER)) if (IsKeyPressed(KEY_ENTER)) //Press enter to start the game
{ {
InitGame(); InitGame();
gameOver = false; gameOver = false;
......
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