Commit 1e42d88b authored by Fan FEI's avatar Fan FEI

version "1.0"

  add notes
parent b793d23f
......@@ -9,6 +9,14 @@
*
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
*
* Expanded on this basis by Fan FEI
*
*
*
*
*
*
********************************************************************************************/
#include "raylib.h"
......@@ -26,7 +34,7 @@
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef struct Snake {
typedef struct Snake { //
Vector2 position;
Vector2 size;
Vector2 speed;
......@@ -51,8 +59,8 @@ static bool gameOver = false;
static bool pause = false;
static Food fruit = { 0 };
static Snake snake[SNAKE_LENGTH] = { 0 };
static Vector2 snakePosition[SNAKE_LENGTH] = { 0 };
static Snake snake[SNAKE_LENGTH] = { 0 }; //Maximum length of snake
static Vector2 snakePosition[SNAKE_LENGTH] = { 0 }; //The coordinates of the snake body
static bool allowMove = false;
static Vector2 offset = { 0 };
static int counterTail = 0;
......@@ -73,12 +81,12 @@ int main(void)
{
// Initialization (Note windowTitle is unused on Android)
//---------------------------------------------------------
InitWindow(screenWidth, screenHeight, "sample game: snake By FanFEI"); //Initialize the interface and title
InitWindow(screenWidth, screenHeight, "sample game: snake By FanFEI"); // Initialize the interface and title
InitGame();//Initialize the game
InitGame(); //Initialize the game
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
emscripten_set_main_loop(UpdateDrawFrame, 60, 1); // The number of frames can adjust the game speed
#else
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
......@@ -110,10 +118,10 @@ int main(void)
void InitGame(void)
{
framesCounter = 0;
gameOver = false; //Game state
gameOver = false; // Game state
pause = false;
counterTail = 2; //The initial length of the snake
counterTail = 2; // The initial length of the snake
allowMove = false;
offset.x = screenWidth%SQUARE_SIZE;
......@@ -123,10 +131,11 @@ void InitGame(void)
{
snake[i].position = (Vector2){ offset.x/2, offset.y/2 };
snake[i].size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE };
snake[i].speed = (Vector2){ SQUARE_SIZE, 0 };
snake[i].speed = (Vector2){ SQUARE_SIZE, 0 }; // Initial direction to the right
if (i == 0) snake[i].color = DARKBLUE; //Snake head color
else snake[i].color = BLUE; //Snake body color
if (i == 0) snake[i].color = PINK; // Snake head color
else if (i%3 != 0) snake[i].color = PURPLE; // Snake body color
else snake[i].color = DARKPURPLE;
}
for (int i = 0; i < SNAKE_LENGTH; i++)
......@@ -134,8 +143,8 @@ void InitGame(void)
snakePosition[i] = (Vector2){ 0.0f, 0.0f };
}
fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; //The color, coordinates and status of the props
fruit.color = SKYBLUE;
fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; // The color, coordinates and status of the props
fruit.color = RED;
fruit.active = false;
}
......@@ -144,11 +153,12 @@ void UpdateGame(void)
{
if (!gameOver)
{
if (IsKeyPressed('P')) pause = !pause; //Keyboard input p pause
if (IsKeyPressed('P')) pause = !pause; // Keyboard input p pause
if (!pause)
{
// Player control
// Only when the snake is moving in the vertical direction can it be turned horizontally
if (IsKeyPressed(KEY_RIGHT) && (snake[0].speed.x == 0) && allowMove)
{
snake[0].speed = (Vector2){ SQUARE_SIZE, 0 };
......@@ -173,7 +183,7 @@ void UpdateGame(void)
// Snake movement
for (int i = 0; i < counterTail; i++) snakePosition[i] = snake[i].position;
if ((framesCounter%5) == 0)
if ((framesCounter%10) == 0)
{
for (int i = 0; i < counterTail; i++)
{
......
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