mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-16 23:06:07 +00:00
Review sample games
This commit is contained in:
@@ -43,19 +43,19 @@ typedef struct Food {
|
||||
//------------------------------------------------------------------------------------
|
||||
// Global Variables Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static int screenWidth = 800;
|
||||
static int screenHeight = 450;
|
||||
static const int screenWidth = 800;
|
||||
static const int screenHeight = 450;
|
||||
|
||||
static int framesCounter;
|
||||
static bool gameOver;
|
||||
static bool pause;
|
||||
static int framesCounter = 0;
|
||||
static bool gameOver = false;
|
||||
static bool pause = false;
|
||||
|
||||
static Food fruit;
|
||||
static Snake snake[SNAKE_LENGTH];
|
||||
static Vector2 snakePosition[SNAKE_LENGTH];
|
||||
static bool allowMove;
|
||||
static Vector2 offset;
|
||||
static int counterTail;
|
||||
static Food fruit = { 0 };
|
||||
static Snake snake[SNAKE_LENGTH] = { 0 };
|
||||
static Vector2 snakePosition[SNAKE_LENGTH] = { 0 };
|
||||
static bool allowMove = false;
|
||||
static Vector2 offset = { 0 };
|
||||
static int counterTail = 0;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration (local)
|
||||
@@ -80,7 +80,6 @@ int main(void)
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -93,7 +92,6 @@ int main(void)
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
#endif
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadGame(); // Unload loaded data (textures, sounds, models...)
|
||||
@@ -150,7 +148,7 @@ void UpdateGame(void)
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
// control
|
||||
// Player control
|
||||
if (IsKeyPressed(KEY_RIGHT) && (snake[0].speed.x == 0) && allowMove)
|
||||
{
|
||||
snake[0].speed = (Vector2){ SQUARE_SIZE, 0 };
|
||||
@@ -172,7 +170,7 @@ void UpdateGame(void)
|
||||
allowMove = false;
|
||||
}
|
||||
|
||||
// movement
|
||||
// Snake movement
|
||||
for (int i = 0; i < counterTail; i++) snakePosition[i] = snake[i].position;
|
||||
|
||||
if ((framesCounter%5) == 0)
|
||||
@@ -189,7 +187,7 @@ void UpdateGame(void)
|
||||
}
|
||||
}
|
||||
|
||||
// wall behaviour
|
||||
// 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))
|
||||
@@ -197,13 +195,13 @@ void UpdateGame(void)
|
||||
gameOver = true;
|
||||
}
|
||||
|
||||
// collision with yourself
|
||||
// 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;
|
||||
}
|
||||
|
||||
// fruit.position calculation
|
||||
// Fruit position calculation
|
||||
if (!fruit.active)
|
||||
{
|
||||
fruit.active = true;
|
||||
@@ -219,7 +217,7 @@ void UpdateGame(void)
|
||||
}
|
||||
}
|
||||
|
||||
// collision
|
||||
// Collision
|
||||
if ((snake[0].position.x < (fruit.position.x + fruit.size.x) && (snake[0].position.x + snake[0].size.x) > fruit.position.x) &&
|
||||
(snake[0].position.y < (fruit.position.y + fruit.size.y) && (snake[0].position.y + snake[0].size.y) > fruit.position.y))
|
||||
{
|
||||
|
Reference in New Issue
Block a user