aboutsummaryrefslogtreecommitdiff
path: root/games/samples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-02-20 20:25:01 +0100
committerraysan5 <raysan5@gmail.com>2016-02-20 20:25:01 +0100
commit7b360d8579c63658ee05377b44d2e0b478d12b74 (patch)
tree16c1553ba117869aeb370ae40f99bb4086701b55 /games/samples
parent83459159f4c8622cefe93a062138e7e2391b6761 (diff)
downloadraylib-7b360d8579c63658ee05377b44d2e0b478d12b74.tar.gz
raylib-7b360d8579c63658ee05377b44d2e0b478d12b74.zip
Reorganized games folder
Simplified to match raylib installer package folder structure
Diffstat (limited to 'games/samples')
-rw-r--r--games/samples/arkanoid.c349
-rw-r--r--games/samples/asteroids.c579
-rw-r--r--games/samples/asteroids_survival.c383
-rw-r--r--games/samples/floppy.c246
-rw-r--r--games/samples/gold_fever.c288
-rw-r--r--games/samples/gorilas.c571
-rw-r--r--games/samples/missile_commander.c539
-rw-r--r--games/samples/pang.c630
-rw-r--r--games/samples/snake.c293
-rw-r--r--games/samples/space_invaders.c406
-rw-r--r--games/samples/tetris.c836
11 files changed, 0 insertions, 5120 deletions
diff --git a/games/samples/arkanoid.c b/games/samples/arkanoid.c
deleted file mode 100644
index f10f9383..00000000
--- a/games/samples/arkanoid.c
+++ /dev/null
@@ -1,349 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: arkanoid
-*
-* Sample game Marc Palau and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <math.h>
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-
-#define PLAYER_MAX_LIFE 5
-#define LINES_OF_BRICKS 5
-#define BRICKS_PER_LINE 20
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef enum GameScreen { LOGO, TITLE, GAMEPLAY, ENDING } GameScreen;
-
-typedef struct Player {
- Vector2 position;
- Vector2 size;
- int life;
-} Player;
-
-typedef struct Ball {
- Vector2 position;
- Vector2 speed;
- int radius;
- bool active;
-} Ball;
-
-typedef struct Brick {
- Vector2 position;
- bool active;
-} Brick;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-
-static Player player;
-static Ball ball;
-static Brick brick[LINES_OF_BRICKS][BRICKS_PER_LINE];
-static Vector2 brickSize;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-// Additional module functions
-static void UpdateBall(void);
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: arkanoid");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- brickSize = (Vector2){ GetScreenWidth()/BRICKS_PER_LINE, 40 };
-
- // Initialize player
- player.position = (Vector2){ screenWidth/2, screenHeight*7/8 };
- player.size = (Vector2){ screenWidth/10, 20 };
- player.life = PLAYER_MAX_LIFE;
-
- // Initialize ball
- ball.position = (Vector2){ screenWidth/2, screenHeight*7/8 - 30 };
- ball.speed = (Vector2){ 0, 0 };
- ball.radius = 7;
- ball.active = false;
-
- // Initialize bricks
- int initialDownPosition = 50;
-
- for (int i = 0; i < LINES_OF_BRICKS; i++)
- {
- for (int j = 0; j < BRICKS_PER_LINE; j++)
- {
- brick[i][j].position = (Vector2){ j*brickSize.x + brickSize.x/2, i*brickSize.y + initialDownPosition };
- brick[i][j].active = true;
- }
- }
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- // Player movement
- if (IsKeyDown(KEY_LEFT)) player.position.x -= 5;
- if ((player.position.x - player.size.x/2) <= 0) player.position.x = player.size.x/2;
- if (IsKeyDown(KEY_RIGHT)) player.position.x += 5;
- if ((player.position.x + player.size.x/2) >= screenWidth) player.position.x = screenWidth - player.size.x/2;
-
- // Launch ball
- if (!ball.active)
- {
- if (IsKeyPressed(KEY_SPACE))
- {
- ball.active = true;
- ball.speed = (Vector2){ 0, -5 };
- }
- }
-
- UpdateBall();
-
- // Game over logic
- if (player.life <= 0) gameOver = true;
- else
- {
- gameOver = true;
-
- for (int i = 0; i < LINES_OF_BRICKS; i++)
- {
- for (int j = 0; j < BRICKS_PER_LINE; j++)
- {
- if (brick[i][j].active) gameOver = false;
- }
- }
- }
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-
-
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw player bar
- DrawRectangle(player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y, BLACK);
-
- // Draw player lives
- for (int i = 0; i < player.life; i++) DrawRectangle(20 + 40*i, screenHeight - 30, 35, 10, LIGHTGRAY);
-
- // Draw ball
- DrawCircleV(ball.position, ball.radius, MAROON);
-
- // Draw bricks
- for (int i = 0; i < LINES_OF_BRICKS; i++)
- {
- for (int j = 0; j < BRICKS_PER_LINE; j++)
- {
- if (brick[i][j].active)
- {
- if ((i + j) % 2 == 0) DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, GRAY);
- else DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, DARKGRAY);
- }
- }
- }
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-}
-
-//--------------------------------------------------------------------------------------
-// Additional module functions
-//--------------------------------------------------------------------------------------
-static void UpdateBall()
-{
- // Update position
- if (ball.active)
- {
- ball.position.x += ball.speed.x;
- ball.position.y += ball.speed.y;
- }
- else
- {
- ball.position = (Vector2){ player.position.x, screenHeight*7/8 - 30 };
- }
-
- // Bounce in x
- if (((ball.position.x + ball.radius) >= screenWidth) || ((ball.position.x - ball.radius) <= 0)) ball.speed.x *= -1;
-
- // Bounce in y
- if ((ball.position.y - ball.radius) <= 0) ball.speed.y *= -1;
-
- // Ball reaches bottom of the screen
- if ((ball.position.y + ball.radius) >= screenHeight)
- {
- ball.speed = (Vector2){ 0, 0 };
- ball.active = false;
-
- player.life--;
- }
-
- // Collision logic: ball vs player
- if (CheckCollisionCircleRec(ball.position, ball.radius,
- (Rectangle){ player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y}))
- {
- if (ball.speed.y > 0)
- {
- ball.speed.y *= -1;
- ball.speed.x = (ball.position.x - player.position.x)/(player.size.x/2)*5;
- }
- }
-
- // Collision logic: ball vs bricks
- for (int i = 0; i < LINES_OF_BRICKS; i++)
- {
- for (int j = 0; j < BRICKS_PER_LINE; j++)
- {
- if (brick[i][j].active)
- {
- // Hit below
- if (((ball.position.y - ball.radius) <= (brick[i][j].position.y + brickSize.y/2)) &&
- ((ball.position.y - ball.radius) > (brick[i][j].position.y + brickSize.y/2 + ball.speed.y)) &&
- ((fabs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) && (ball.speed.y < 0))
- {
- brick[i][j].active = false;
- ball.speed.y *= -1;
- }
- // Hit above
- else if (((ball.position.y + ball.radius) >= (brick[i][j].position.y - brickSize.y/2)) &&
- ((ball.position.y + ball.radius) < (brick[i][j].position.y - brickSize.y/2 + ball.speed.y)) &&
- ((fabs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) && (ball.speed.y > 0))
- {
- brick[i][j].active = false;
- ball.speed.y *= -1;
- }
- // Hit left
- else if (((ball.position.x + ball.radius) >= (brick[i][j].position.x - brickSize.x/2)) &&
- ((ball.position.x + ball.radius) < (brick[i][j].position.x - brickSize.x/2 + ball.speed.x)) &&
- ((fabs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) && (ball.speed.x > 0))
- {
- brick[i][j].active = false;
- ball.speed.x *= -1;
- }
- // Hit right
- else if (((ball.position.x - ball.radius) <= (brick[i][j].position.x + brickSize.x/2)) &&
- ((ball.position.x - ball.radius) > (brick[i][j].position.x + brickSize.x/2 + ball.speed.x)) &&
- ((fabs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) && (ball.speed.x < 0))
- {
- brick[i][j].active = false;
- ball.speed.x *= -1;
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/games/samples/asteroids.c b/games/samples/asteroids.c
deleted file mode 100644
index 53ebbd8e..00000000
--- a/games/samples/asteroids.c
+++ /dev/null
@@ -1,579 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: asteroids
-*
-* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <math.h>
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define PLAYER_BASE_SIZE 20.0f
-#define PLAYER_SPEED 6.0f
-#define PLAYER_MAX_SHOOTS 10
-
-#define METEORS_SPEED 2
-#define MAX_BIG_METEORS 4
-#define MAX_MEDIUM_METEORS 8
-#define MAX_SMALL_METEORS 16
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-
-typedef struct Player {
- Vector2 position;
- Vector2 speed;
- float acceleration;
- float rotation;
- Vector3 collider;
- Color color;
-} Player;
-
-typedef struct Shoot {
- Vector2 position;
- Vector2 speed;
- float radius;
- float rotation;
- int lifeSpawn;
- bool active;
- Color color;
-} Shoot;
-
-typedef struct Meteor {
- Vector2 position;
- Vector2 speed;
- float radius;
- bool active;
- Color color;
-} Meteor;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-static bool victory;
-
-// NOTE: Defined triangle is isosceles with common angles of 70 degrees.
-static float shipHeight;
-
-static Player player;
-static Shoot shoot[PLAYER_MAX_SHOOTS];
-static Meteor bigMeteor[MAX_BIG_METEORS];
-static Meteor mediumMeteor[MAX_MEDIUM_METEORS];
-static Meteor smallMeteor[MAX_SMALL_METEORS];
-
-static int countMediumMeteors;
-static int countSmallMeteors;
-static int meteorsDestroyed;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-static void InitShoot(Shoot shoot);
-static void DrawSpaceship(Vector2 position, float rotation, Color color);
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: asteroids");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- int posx, posy;
- int velx, vely;
- bool correctRange = false;
- victory = false;
- pause = false;
-
- shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD);
-
- // Initialization player
- player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2};
- player.speed = (Vector2){0, 0};
- player.acceleration = 0;
- player.rotation = 0;
- player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
- player.color = LIGHTGRAY;
-
- meteorsDestroyed = 0;
-
- // Initialization shoot
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- shoot[i].position = (Vector2){0, 0};
- shoot[i].speed = (Vector2){0, 0};
- shoot[i].radius = 2;
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- shoot[i].color = WHITE;
- }
-
- for (int i = 0; i < MAX_BIG_METEORS; i++)
- {
- posx = GetRandomValue(0, screenWidth);
-
- while(!correctRange)
- {
- if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth);
- else correctRange = true;
- }
-
- correctRange = false;
-
- posy = GetRandomValue(0, screenHeight);
-
- while(!correctRange)
- {
- if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight);
- else correctRange = true;
- }
-
- bigMeteor[i].position = (Vector2){posx, posy};
-
- correctRange = false;
- velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
-
- while(!correctRange)
- {
- if (velx == 0 && vely == 0)
- {
- velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- }
- else correctRange = true;
- }
-
- bigMeteor[i].speed = (Vector2){velx, vely};
- bigMeteor[i].radius = 40;
- bigMeteor[i].active = true;
- bigMeteor[i].color = BLUE;
- }
-
- for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
- {
- mediumMeteor[i].position = (Vector2){-100, -100};
- mediumMeteor[i].speed = (Vector2){0,0};
- mediumMeteor[i].radius = 20;
- mediumMeteor[i].active = false;
- mediumMeteor[i].color = BLUE;
- }
-
- for (int i = 0; i < MAX_SMALL_METEORS; i++)
- {
- smallMeteor[i].position = (Vector2){-100, -100};
- smallMeteor[i].speed = (Vector2){0,0};
- smallMeteor[i].radius = 10;
- smallMeteor[i].active = false;
- smallMeteor[i].color = BLUE;
- }
-
- countMediumMeteors = 0;
- countSmallMeteors = 0;
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- // Player logic
-
- // Rotation
- if (IsKeyDown(KEY_LEFT)) player.rotation -= 5;
- if (IsKeyDown(KEY_RIGHT)) player.rotation += 5;
-
- // Speed
- player.speed.x = sin(player.rotation*DEG2RAD)*PLAYER_SPEED;
- player.speed.y = cos(player.rotation*DEG2RAD)*PLAYER_SPEED;
-
- // Controller
- if (IsKeyDown(KEY_UP))
- {
- if (player.acceleration < 1) player.acceleration += 0.04f;
- }
- else
- {
- if (player.acceleration > 0) player.acceleration -= 0.02f;
- else if (player.acceleration < 0) player.acceleration = 0;
- }
- if (IsKeyDown(KEY_DOWN))
- {
- if (player.acceleration > 0) player.acceleration -= 0.04f;
- else if (player.acceleration < 0) player.acceleration = 0;
- }
-
- // Movement
- player.position.x += (player.speed.x*player.acceleration);
- player.position.y -= (player.speed.y*player.acceleration);
-
- // Wall behaviour for player
- if (player.position.x > screenWidth + shipHeight) player.position.x = -(shipHeight);
- else if (player.position.x < -(shipHeight)) player.position.x = screenWidth + shipHeight;
- if (player.position.y > (screenHeight + shipHeight)) player.position.y = -(shipHeight);
- else if (player.position.y < -(shipHeight)) player.position.y = screenHeight + shipHeight;
-
- // Activation of shoot
- if (IsKeyPressed(KEY_SPACE))
- {
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (!shoot[i].active)
- {
- shoot[i].position = (Vector2){ player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight) };
- shoot[i].active = true;
- shoot[i].speed.x = 1.5*sin(player.rotation*DEG2RAD)*PLAYER_SPEED;
- shoot[i].speed.y = 1.5*cos(player.rotation*DEG2RAD)*PLAYER_SPEED;
- shoot[i].rotation = player.rotation;
- break;
- }
- }
- }
-
- // Shoot life timer
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (shoot[i].active) shoot[i].lifeSpawn++;
- }
-
- // Shot logic
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (shoot[i].active)
- {
- // Movement
- shoot[i].position.x += shoot[i].speed.x;
- shoot[i].position.y -= shoot[i].speed.y;
-
- // Wall behaviour for shoot
- if (shoot[i].position.x > screenWidth + shoot[i].radius)
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- }
- else if (shoot[i].position.x < 0 - shoot[i].radius)
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- }
- if (shoot[i].position.y > screenHeight + shoot[i].radius)
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- }
- else if (shoot[i].position.y < 0 - shoot[i].radius)
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- }
-
- // Life of shoot
- if (shoot[i].lifeSpawn >= 60)
- {
- shoot[i].position = (Vector2){0, 0};
- shoot[i].speed = (Vector2){0, 0};
- shoot[i].lifeSpawn = 0;
- shoot[i].active = false;
- }
- }
- }
-
- // Collision Player to meteors
- player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
-
- for (int a = 0; a < MAX_BIG_METEORS; a++)
- {
- if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, bigMeteor[a].position, bigMeteor[a].radius) && bigMeteor[a].active) gameOver = true;
- }
-
- for (int a = 0; a < MAX_MEDIUM_METEORS; a++)
- {
- if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true;
- }
-
- for (int a = 0; a < MAX_SMALL_METEORS; a++)
- {
- if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true;
- }
-
- // Meteor logic
- for (int i = 0; i < MAX_BIG_METEORS; i++)
- {
- if (bigMeteor[i].active)
- {
- // movement
- bigMeteor[i].position.x += bigMeteor[i].speed.x;
- bigMeteor[i].position.y += bigMeteor[i].speed.y;
-
- // wall behaviour
- if (bigMeteor[i].position.x > screenWidth + bigMeteor[i].radius) bigMeteor[i].position.x = -(bigMeteor[i].radius);
- else if (bigMeteor[i].position.x < 0 - bigMeteor[i].radius) bigMeteor[i].position.x = screenWidth + bigMeteor[i].radius;
- if (bigMeteor[i].position.y > screenHeight + bigMeteor[i].radius) bigMeteor[i].position.y = -(bigMeteor[i].radius);
- else if (bigMeteor[i].position.y < 0 - bigMeteor[i].radius) bigMeteor[i].position.y = screenHeight + bigMeteor[i].radius;
- }
- }
-
- for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
- {
- if (mediumMeteor[i].active)
- {
- // movement
- mediumMeteor[i].position.x += mediumMeteor[i].speed.x;
- mediumMeteor[i].position.y += mediumMeteor[i].speed.y;
-
- // wall behaviour
- if (mediumMeteor[i].position.x > screenWidth + mediumMeteor[i].radius) mediumMeteor[i].position.x = -(mediumMeteor[i].radius);
- else if (mediumMeteor[i].position.x < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.x = screenWidth + mediumMeteor[i].radius;
- if (mediumMeteor[i].position.y > screenHeight + mediumMeteor[i].radius) mediumMeteor[i].position.y = -(mediumMeteor[i].radius);
- else if (mediumMeteor[i].position.y < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.y = screenHeight + mediumMeteor[i].radius;
- }
- }
-
- for (int i = 0; i < MAX_SMALL_METEORS; i++)
- {
- if (smallMeteor[i].active)
- {
- // movement
- smallMeteor[i].position.x += smallMeteor[i].speed.x;
- smallMeteor[i].position.y += smallMeteor[i].speed.y;
-
- // wall behaviour
- if (smallMeteor[i].position.x > screenWidth + smallMeteor[i].radius) smallMeteor[i].position.x = -(smallMeteor[i].radius);
- else if (smallMeteor[i].position.x < 0 - smallMeteor[i].radius) smallMeteor[i].position.x = screenWidth + smallMeteor[i].radius;
- if (smallMeteor[i].position.y > screenHeight + smallMeteor[i].radius) smallMeteor[i].position.y = -(smallMeteor[i].radius);
- else if (smallMeteor[i].position.y < 0 - smallMeteor[i].radius) smallMeteor[i].position.y = screenHeight + smallMeteor[i].radius;
- }
- }
-
- // Collision behaviour
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if ((shoot[i].active))
- {
- for (int a = 0; a < MAX_BIG_METEORS; a++)
- {
- if (bigMeteor[a].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, bigMeteor[a].position, bigMeteor[a].radius))
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- bigMeteor[a].active = false;
- meteorsDestroyed++;
- for (int j = 0; j < 2; j ++)
- {
- if (countMediumMeteors%2 == 0)
- {
- mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y};
- mediumMeteor[countMediumMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1};
- }
- else
- {
- mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y};
- mediumMeteor[countMediumMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED};
- }
-
- mediumMeteor[countMediumMeteors].active = true;
- countMediumMeteors ++;
- }
- //bigMeteor[a].position = (Vector2){-100, -100};
- bigMeteor[a].color = RED;
- a = MAX_BIG_METEORS;
- }
- }
- }
- if ((shoot[i].active))
- {
- for (int b = 0; b < MAX_MEDIUM_METEORS; b++)
- {
- if (mediumMeteor[b].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, mediumMeteor[b].position, mediumMeteor[b].radius))
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- mediumMeteor[b].active = false;
- meteorsDestroyed++;
- for (int j = 0; j < 2; j ++)
- {
- if (countSmallMeteors%2 == 0)
- {
- smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y};
- smallMeteor[countSmallMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1};
- }
- else
- {
- smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y};
- smallMeteor[countSmallMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED};
- }
-
- smallMeteor[countSmallMeteors].active = true;
- countSmallMeteors ++;
- }
- //mediumMeteor[b].position = (Vector2){-100, -100};
- mediumMeteor[b].color = GREEN;
- b = MAX_MEDIUM_METEORS;
- }
- }
- }
- if ((shoot[i].active))
- {
- for (int c = 0; c < MAX_SMALL_METEORS; c++)
- {
- if (smallMeteor[c].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, smallMeteor[c].position, smallMeteor[c].radius))
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- smallMeteor[c].active = false;
- meteorsDestroyed++;
- smallMeteor[c].color = YELLOW;
- // smallMeteor[c].position = (Vector2){-100, -100};
- c = MAX_SMALL_METEORS;
- }
- }
- }
- }
- }
-
- if (meteorsDestroyed == MAX_BIG_METEORS + MAX_MEDIUM_METEORS + MAX_SMALL_METEORS) victory = true;
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw spaceship
- Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) };
- Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
- Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
- DrawTriangle(v1, v2, v3, MAROON);
-
- // Draw meteors
- for (int i = 0; i < MAX_BIG_METEORS; i++)
- {
- if (bigMeteor[i].active) DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, DARKGRAY);
- else DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
- {
- if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, GRAY);
- else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- for (int i = 0; i < MAX_SMALL_METEORS; i++)
- {
- if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, GRAY);
- else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- // Draw shoot
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (shoot[i].active) DrawCircleV(shoot[i].position, shoot[i].radius, BLACK);
- }
-
- if (victory) DrawText("VICTORY", screenWidth/2 - MeasureText("VICTORY", 20)/2, screenHeight/2, 20, LIGHTGRAY);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-} \ No newline at end of file
diff --git a/games/samples/asteroids_survival.c b/games/samples/asteroids_survival.c
deleted file mode 100644
index aa21112d..00000000
--- a/games/samples/asteroids_survival.c
+++ /dev/null
@@ -1,383 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: asteroids survival
-*
-* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <math.h>
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define PLAYER_BASE_SIZE 20.0f
-#define PLAYER_SPEED 6.0f
-#define PLAYER_MAX_SHOOTS 10
-
-#define METEORS_SPEED 2
-#define MAX_MEDIUM_METEORS 8
-#define MAX_SMALL_METEORS 16
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-
-typedef struct Player {
- Vector2 position;
- Vector2 speed;
- float acceleration;
- float rotation;
- Vector3 collider;
- Color color;
-} Player;
-
-typedef struct Meteor {
- Vector2 position;
- Vector2 speed;
- float radius;
- bool active;
- Color color;
-} Meteor;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-
-// NOTE: Defined triangle is isosceles with common angles of 70 degrees.
-static float shipHeight;
-
-static Player player;
-static Meteor mediumMeteor[MAX_MEDIUM_METEORS];
-static Meteor smallMeteor[MAX_SMALL_METEORS];
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: asteroids survival");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- int posx, posy;
- int velx, vely;
- bool correctRange = false;
-
- pause = false;
-
- framesCounter = 0;
-
- shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD);
-
- // Initialization player
- player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2};
- player.speed = (Vector2){0, 0};
- player.acceleration = 0;
- player.rotation = 0;
- player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
- player.color = LIGHTGRAY;
-
- for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
- {
- posx = GetRandomValue(0, screenWidth);
-
- while(!correctRange)
- {
- if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth);
- else correctRange = true;
- }
-
- correctRange = false;
-
- posy = GetRandomValue(0, screenHeight);
-
- while(!correctRange)
- {
- if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight);
- else correctRange = true;
- }
-
- correctRange = false;
- velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
-
- while(!correctRange)
- {
- if (velx == 0 && vely == 0)
- {
- velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- }
- else correctRange = true;
- }
- mediumMeteor[i].position = (Vector2){posx, posy};
- mediumMeteor[i].speed = (Vector2){velx, vely};
- mediumMeteor[i].radius = 20;
- mediumMeteor[i].active = true;
- mediumMeteor[i].color = GREEN;
- }
-
- for (int i = 0; i < MAX_SMALL_METEORS; i++)
- {
- posx = GetRandomValue(0, screenWidth);
-
- while(!correctRange)
- {
- if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth);
- else correctRange = true;
- }
-
- correctRange = false;
-
- posy = GetRandomValue(0, screenHeight);
-
- while(!correctRange)
- {
- if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight);
- else correctRange = true;
- }
-
- correctRange = false;
- velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
-
- while(!correctRange)
- {
- if (velx == 0 && vely == 0)
- {
- velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
- }
- else correctRange = true;
- }
- smallMeteor[i].position = (Vector2){posx, posy};
- smallMeteor[i].speed = (Vector2){velx, vely};
- smallMeteor[i].radius = 10;
- smallMeteor[i].active = true;
- smallMeteor[i].color = YELLOW;
- }
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- framesCounter++;
-
- // Player logic
-
- // Rotation
- if (IsKeyDown(KEY_LEFT)) player.rotation -= 5;
- if (IsKeyDown(KEY_RIGHT)) player.rotation += 5;
-
- // Speed
- player.speed.x = sin(player.rotation*DEG2RAD)*PLAYER_SPEED;
- player.speed.y = cos(player.rotation*DEG2RAD)*PLAYER_SPEED;
-
- // Controller
- if (IsKeyDown(KEY_UP))
- {
- if (player.acceleration < 1) player.acceleration += 0.04f;
- }
- else
- {
- if (player.acceleration > 0) player.acceleration -= 0.02f;
- else if (player.acceleration < 0) player.acceleration = 0;
- }
- if (IsKeyDown(KEY_DOWN))
- {
- if (player.acceleration > 0) player.acceleration -= 0.04f;
- else if (player.acceleration < 0) player.acceleration = 0;
- }
-
- // Movement
- player.position.x += (player.speed.x*player.acceleration);
- player.position.y -= (player.speed.y*player.acceleration);
-
- // Wall behaviour for player
- if (player.position.x > screenWidth + shipHeight) player.position.x = -(shipHeight);
- else if (player.position.x < -(shipHeight)) player.position.x = screenWidth + shipHeight;
- if (player.position.y > (screenHeight + shipHeight)) player.position.y = -(shipHeight);
- else if (player.position.y < -(shipHeight)) player.position.y = screenHeight + shipHeight;
-
- // Collision Player to meteors
- player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
-
- for (int a = 0; a < MAX_MEDIUM_METEORS; a++)
- {
- if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true;
- }
-
- for (int a = 0; a < MAX_SMALL_METEORS; a++)
- {
- if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true;
- }
-
- // Meteor logic
-
- for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
- {
- if (mediumMeteor[i].active)
- {
- // movement
- mediumMeteor[i].position.x += mediumMeteor[i].speed.x;
- mediumMeteor[i].position.y += mediumMeteor[i].speed.y;
-
- // wall behaviour
- if (mediumMeteor[i].position.x > screenWidth + mediumMeteor[i].radius) mediumMeteor[i].position.x = -(mediumMeteor[i].radius);
- else if (mediumMeteor[i].position.x < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.x = screenWidth + mediumMeteor[i].radius;
- if (mediumMeteor[i].position.y > screenHeight + mediumMeteor[i].radius) mediumMeteor[i].position.y = -(mediumMeteor[i].radius);
- else if (mediumMeteor[i].position.y < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.y = screenHeight + mediumMeteor[i].radius;
- }
- }
-
- for (int i = 0; i < MAX_SMALL_METEORS; i++)
- {
- if (smallMeteor[i].active)
- {
- // movement
- smallMeteor[i].position.x += smallMeteor[i].speed.x;
- smallMeteor[i].position.y += smallMeteor[i].speed.y;
-
- // wall behaviour
- if (smallMeteor[i].position.x > screenWidth + smallMeteor[i].radius) smallMeteor[i].position.x = -(smallMeteor[i].radius);
- else if (smallMeteor[i].position.x < 0 - smallMeteor[i].radius) smallMeteor[i].position.x = screenWidth + smallMeteor[i].radius;
- if (smallMeteor[i].position.y > screenHeight + smallMeteor[i].radius) smallMeteor[i].position.y = -(smallMeteor[i].radius);
- else if (smallMeteor[i].position.y < 0 - smallMeteor[i].radius) smallMeteor[i].position.y = screenHeight + smallMeteor[i].radius;
- }
- }
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw spaceship
- Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) };
- Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
- Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
- DrawTriangle(v1, v2, v3, MAROON);
-
- // Draw meteor
- for (int i = 0;i < MAX_MEDIUM_METEORS; i++)
- {
- if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, GRAY);
- else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- for (int i = 0;i < MAX_SMALL_METEORS; i++)
- {
- if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, DARKGRAY);
- else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- DrawText(FormatText("TIME: %.02f", (float)framesCounter/60), 10, 10, 20, BLACK);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
- //----------------------------------------------------------------------------------
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-} \ No newline at end of file
diff --git a/games/samples/floppy.c b/games/samples/floppy.c
deleted file mode 100644
index f48ea235..00000000
--- a/games/samples/floppy.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: floppy
-*
-* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define MAX_TUBES 100
-#define FLOPPY_RADIUS 24
-#define TUBES_WIDTH 80
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef struct Floppy {
- Vector2 position;
- int radius;
- Color color;
-} Floppy;
-
-typedef struct Tubes {
- Rectangle rec;
- Color color;
- bool active;
-} Tubes;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-static int score;
-static int hiScore = 0;
-
-static Floppy floppy;
-static Tubes tubes[MAX_TUBES*2];
-static Vector2 tubesPos[MAX_TUBES];
-static int tubesSpeedX;
-static bool superfx;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: floppy");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- floppy.radius = FLOPPY_RADIUS;
- floppy.position = (Vector2){80, screenHeight/2 - floppy.radius};
- tubesSpeedX = 2;
-
- for (int i = 0; i < MAX_TUBES; i++)
- {
- tubesPos[i].x = 400 + 280*i;
- tubesPos[i].y = -GetRandomValue(0, 120);
- }
-
- for (int i = 0; i < MAX_TUBES*2; i += 2)
- {
- tubes[i].rec.x = tubesPos[i/2].x;
- tubes[i].rec.y = tubesPos[i/2].y;
- tubes[i].rec.width = TUBES_WIDTH;
- tubes[i].rec.height = 255;
-
- tubes[i+1].rec.x = tubesPos[i/2].x;
- tubes[i+1].rec.y = 600 + tubesPos[i/2].y - 255;
- tubes[i+1].rec.width = TUBES_WIDTH;
- tubes[i+1].rec.height = 255;
-
- tubes[i/2].active = true;
- }
-
- score = 0;
-
- gameOver = false;
- superfx = false;
- pause = false;
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX;
-
- for (int i = 0; i < MAX_TUBES*2; i += 2)
- {
- tubes[i].rec.x = tubesPos[i/2].x;
- tubes[i+1].rec.x = tubesPos[i/2].x;
- }
-
- if (IsKeyDown(KEY_SPACE) && !gameOver) floppy.position.y -= 3;
- else floppy.position.y += 1;
-
- // Check Collisions
- for (int i = 0; i < MAX_TUBES*2; i++)
- {
- if (CheckCollisionCircleRec(floppy.position, floppy.radius, tubes[i].rec))
- {
- gameOver = true;
- pause = false;
- }
- else if ((tubesPos[i/2].x < floppy.position.x) && tubes[i/2].active && !gameOver)
- {
- score += 100;
- tubes[i/2].active = false;
-
- superfx = true;
-
- if (score > hiScore) hiScore = score;
- }
- }
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- DrawCircle(floppy.position.x, floppy.position.y, floppy.radius, DARKGRAY);
-
- // Draw tubes
- for (int i = 0; i < MAX_TUBES; i++)
- {
- DrawRectangle(tubes[i*2].rec.x, tubes[i*2].rec.y, tubes[i*2].rec.width, tubes[i*2].rec.height, GRAY);
- DrawRectangle(tubes[i*2 + 1].rec.x, tubes[i*2 + 1].rec.y, tubes[i*2 + 1].rec.width, tubes[i*2 + 1].rec.height, GRAY);
- }
-
- // Draw flashing fx (one frame only)
- if (superfx)
- {
- DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
- superfx = false;
- }
-
- DrawText(FormatText("%04i", score), 20, 20, 40, GRAY);
- DrawText(FormatText("HI-SCORE: %04i", hiScore), 20, 70, 20, LIGHTGRAY);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-} \ No newline at end of file
diff --git a/games/samples/gold_fever.c b/games/samples/gold_fever.c
deleted file mode 100644
index 5a435027..00000000
--- a/games/samples/gold_fever.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: gold fever
-*
-* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef struct Player {
- Vector2 position;
- Vector2 speed;
- int radius;
-} Player;
-
-typedef struct Enemy {
- Vector2 position;
- Vector2 speed;
- int radius;
- int radiusBounds;
- bool moveRight; // RAY: o__O
-} Enemy;
-
-typedef struct Points {
- Vector2 position;
- int radius;
- int value;
- bool active;
-} Points;
-
-typedef struct Home {
- Rectangle rec;
- bool active;
- bool save;
- Color color;
-} Home;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-static int score;
-static int hiScore = 0;
-
-static Player player;
-static Enemy enemy;
-static Points points;
-static Home home;
-static bool follow;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
-
- InitWindow(screenWidth, screenHeight, "sample game: gold fever");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- pause = false;
- score = 0;
-
- player.position = (Vector2){50, 50};
- player.radius = 20;
- player.speed = (Vector2){5, 5};
-
- enemy.position = (Vector2){screenWidth - 50, screenHeight/2};
- enemy.radius = 20;
- enemy.radiusBounds = 150;
- enemy.speed = (Vector2){3, 3};
- enemy.moveRight = true;
- follow = false;
-
- points.radius = 10;
- points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)};
- points.value = 100;
- points.active = true;
-
- home.rec.width = 50;
- home.rec.height = 50;
- home.rec.x = GetRandomValue(0, screenWidth - home.rec.width);
- home.rec.y = GetRandomValue(0, screenHeight - home.rec.height);
- home.active = false;
- home.save = false;
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- //Control player
- if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x;
- if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x;
- if (IsKeyDown(KEY_UP)) player.position.y -= player.speed.y;
- if (IsKeyDown(KEY_DOWN)) player.position.y += player.speed.y;
-
- //wall behaviour player
- if (player.position.x - player.radius <= 0) player.position.x = player.radius;
- if (player.position.x + player.radius >= screenWidth) player.position.x = screenWidth - player.radius;
- if (player.position.y - player.radius <= 0) player.position.y = player.radius;
- if (player.position.y + player.radius >= screenHeight) player.position.y = screenHeight - player.radius;
-
- //IA Enemy
- if ( (follow || CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radiusBounds)) && !home.save)
- {
- if (player.position.x > enemy.position.x) enemy.position.x += enemy.speed.x;
- if (player.position.x < enemy.position.x) enemy.position.x -= enemy.speed.x;
-
- if (player.position.y > enemy.position.y) enemy.position.y += enemy.speed.y;
- if (player.position.y < enemy.position.y) enemy.position.y -= enemy.speed.y;
- }
- else
- {
- if (enemy.moveRight) enemy.position.x += enemy.speed.x;
- else enemy.position.x -= enemy.speed.x;
- }
-
- //wall behaviour enemy
- if (enemy.position.x - enemy.radius <= 0) enemy.moveRight = true;
- if (enemy.position.x + enemy.radius >= screenWidth) enemy.moveRight = false;
-
- if (enemy.position.x - enemy.radius <= 0) enemy.position.x = enemy.radius;
- if (enemy.position.x + enemy.radius >= screenWidth) enemy.position.x = screenWidth - enemy.radius;
- if (enemy.position.y - enemy.radius <= 0) enemy.position.y = enemy.radius;
- if (enemy.position.y + enemy.radius >= screenHeight) enemy.position.y = screenHeight - enemy.radius;
-
- //Collisions
- if (CheckCollisionCircles(player.position, player.radius, points.position, points.radius) && points.active)
- {
- follow = true;
- points.active = false;
- home.active = true;
- }
-
- if (CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radius) && !home.save)
- {
- gameOver = true;
-
- if (hiScore < score) hiScore = score;
- }
-
- if (CheckCollisionCircleRec(player.position, player.radius, home.rec))
- {
- follow = false;
-
- if (!points.active)
- {
- score += points.value;
- points.active = true;
- enemy.speed.x += 0.5;
- enemy.speed.y += 0.5;
- points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)};
- }
-
- home.save = true;
- }
- else home.save = false;
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- if (follow)
- {
- DrawRectangle(0, 0, screenWidth, screenHeight, RED);
- DrawRectangle(10, 10, screenWidth - 20, screenHeight - 20, RAYWHITE);
- }
-
- DrawRectangleLines(home.rec.x, home.rec.y, home.rec.width, home.rec.height, BLUE);
-
- DrawCircleLines(enemy.position.x, enemy.position.y, enemy.radiusBounds, RED);
- DrawCircleV(enemy.position, enemy.radius, MAROON);
-
- DrawCircleV(player.position, player.radius, GRAY);
- if (points.active) DrawCircleV(points.position, points.radius, GOLD);
-
- DrawText(FormatText("SCORE: %04i", score), 20, 15, 20, GRAY);
- DrawText(FormatText("HI-SCORE: %04i", hiScore), 300, 15, 20, GRAY);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-} \ No newline at end of file
diff --git a/games/samples/gorilas.c b/games/samples/gorilas.c
deleted file mode 100644
index 86fd3f5b..00000000
--- a/games/samples/gorilas.c
+++ /dev/null
@@ -1,571 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: gorilas
-*
-* Sample game Marc Palau and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <math.h>
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define MAX_BUILDINGS 15
-#define MAX_EXPLOSIONS 200
-#define MAX_PLAYERS 2
-
-#define BUILDING_RELATIVE_ERROR 30 // Building size random range %
-#define BUILDING_MIN_RELATIVE_HEIGHT 20 // Minimum height in % of the screenHeight
-#define BUILDING_MAX_RELATIVE_HEIGHT 60 // Maximum height in % of the screenHeight
-#define BUILDING_MIN_GRAYSCALE_COLOR 120 // Minimum gray color for the buildings
-#define BUILDING_MAX_GRAYSCALE_COLOR 200 // Maximum gray color for the buildings
-
-#define MIN_PLAYER_POSITION 5 // Minimum x position %
-#define MAX_PLAYER_POSITION 20 // Maximum x position %
-
-#define GRAVITY 9.81f
-#define DELTA_FPS 60
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef struct Player {
- Vector2 position;
- Vector2 size;
-
- Vector2 aimingPoint;
- int aimingAngle;
- int aimingPower;
-
- Vector2 previousPoint;
- int previousAngle;
- int previousPower;
-
- Vector2 impactPoint;
-
- bool isLeftTeam; // This player belongs to the left or to the right team
- bool isPlayer; // If is a player or an AI
- bool isAlive;
-} Player;
-
-typedef struct Building {
- Rectangle rectangle;
- Color color;
-} Building;
-
-typedef struct Explosion {
- Vector2 position;
- int radius;
- bool active;
-} Explosion;
-
-typedef struct Ball {
- Vector2 position;
- Vector2 speed;
- int radius;
- bool active;
-} Ball;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static bool gameOver = false;
-static bool pause = false;
-
-static Player player[MAX_PLAYERS];
-static Building building[MAX_BUILDINGS];
-static Explosion explosion[MAX_EXPLOSIONS];
-static Ball ball;
-
-static int playerTurn = 0;
-static bool ballOnAir = false;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-// Additional module functions
-static void InitBuildings(void);
-static void InitPlayers(void);
-static bool UpdatePlayer(int playerTurn);
-static bool UpdateBall(int playerTurn);
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: gorilas");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- // Init shoot
- ball.radius = 10;
- ballOnAir = false;
- ball.active = false;
-
- InitBuildings();
- InitPlayers();
-
- // Init explosions
- for (int i = 0; i < MAX_EXPLOSIONS; i++)
- {
- explosion[i].position = (Vector2){ 0.0f, 0.0f };
- explosion[i].radius = 30;
- explosion[i].active = false;
- }
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- if (!ballOnAir) ballOnAir = UpdatePlayer(playerTurn); // If we are aiming
- else
- {
- if (UpdateBall(playerTurn)) // If collision
- {
- // Game over logic
- bool leftTeamAlive = false;
- bool rightTeamAlive = false;
-
- for (int i = 0; i < MAX_PLAYERS; i++)
- {
- if (player[i].isAlive)
- {
- if (player[i].isLeftTeam) leftTeamAlive = true;
- if (!player[i].isLeftTeam) rightTeamAlive = true;
- }
- }
-
- if (leftTeamAlive && rightTeamAlive)
- {
- ballOnAir = false;
- ball.active = false;
-
- playerTurn++;
-
- if (playerTurn == MAX_PLAYERS) playerTurn = 0;
- }
- else
- {
- gameOver = true;
-
- // if (leftTeamAlive) left team wins
- // if (rightTeamAlive) right team wins
- }
- }
- }
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw buildings
- for (int i = 0; i < MAX_BUILDINGS; i++) DrawRectangleRec(building[i].rectangle, building[i].color);
-
- // Draw explosions
- for (int i = 0; i < MAX_EXPLOSIONS; i++)
- {
- if (explosion[i].active) DrawCircle(explosion[i].position.x, explosion[i].position.y, explosion[i].radius, RAYWHITE);
- }
-
- // Draw players
- for (int i = 0; i < MAX_PLAYERS; i++)
- {
- if (player[i].isAlive)
- {
- if (player[i].isLeftTeam) DrawRectangle(player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2,
- player[i].size.x, player[i].size.y, BLUE);
- else DrawRectangle(player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2,
- player[i].size.x, player[i].size.y, RED);
- }
- }
-
- // Draw ball
- if (ball.active) DrawCircle(ball.position.x, ball.position.y, ball.radius, MAROON);
-
- // Draw the angle and the power of the aim, and the previous ones
- if (!ballOnAir)
- {
- // Draw shot information
- /*
- if (player[playerTurn].isLeftTeam)
- {
- DrawText(FormatText("Previous Point %i, %i", (int)player[playerTurn].previousPoint.x, (int)player[playerTurn].previousPoint.y), 20, 20, 20, DARKBLUE);
- DrawText(FormatText("Previous Angle %i", player[playerTurn].previousAngle), 20, 50, 20, DARKBLUE);
- DrawText(FormatText("Previous Power %i", player[playerTurn].previousPower), 20, 80, 20, DARKBLUE);
- DrawText(FormatText("Aiming Point %i, %i", (int)player[playerTurn].aimingPoint.x, (int)player[playerTurn].aimingPoint.y), 20, 110, 20, DARKBLUE);
- DrawText(FormatText("Aiming Angle %i", player[playerTurn].aimingAngle), 20, 140, 20, DARKBLUE);
- DrawText(FormatText("Aiming Power %i", player[playerTurn].aimingPower), 20, 170, 20, DARKBLUE);
- }
- else
- {
- DrawText(FormatText("Previous Point %i, %i", (int)player[playerTurn].previousPoint.x, (int)player[playerTurn].previousPoint.y), screenWidth*3/4, 20, 20, DARKBLUE);
- DrawText(FormatText("Previous Angle %i", player[playerTurn].previousAngle), screenWidth*3/4, 50, 20, DARKBLUE);
- DrawText(FormatText("Previous Power %i", player[playerTurn].previousPower), screenWidth*3/4, 80, 20, DARKBLUE);
- DrawText(FormatText("Aiming Point %i, %i", (int)player[playerTurn].aimingPoint.x, (int)player[playerTurn].aimingPoint.y), screenWidth*3/4, 110, 20, DARKBLUE);
- DrawText(FormatText("Aiming Angle %i", player[playerTurn].aimingAngle), screenWidth*3/4, 140, 20, DARKBLUE);
- DrawText(FormatText("Aiming Power %i", player[playerTurn].aimingPower), screenWidth*3/4, 170, 20, DARKBLUE);
- }
- */
-
- // Draw aim
- if (player[playerTurn].isLeftTeam)
- {
- // Previous aiming
- DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
- (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
- player[playerTurn].previousPoint, GRAY);
-
- // Actual aiming
- DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
- (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
- player[playerTurn].aimingPoint, DARKBLUE);
- }
- else
- {
- // Previous aiming
- DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
- (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
- player[playerTurn].previousPoint, GRAY);
-
- // Actual aiming
- DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
- (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
- player[playerTurn].aimingPoint, MAROON);
- }
- }
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-}
-
-//--------------------------------------------------------------------------------------
-// Additional module functions
-//--------------------------------------------------------------------------------------
-static void InitBuildings(void)
-{
- // Horizontal generation
- int currentWidth = 0;
-
- // We make sure the absolute error randomly generated for each building, has as a minimum value the screenWidth.
- // This way all the screen will be filled with buildings. Each building will have a different, random width.
-
- float relativeWidth = 100/(100 - BUILDING_RELATIVE_ERROR);
- float buildingWidthMean = (screenWidth*relativeWidth/MAX_BUILDINGS) + 1; // We add one to make sure we will cover the whole screen.
-
- // Vertical generation
- int currentHeighth = 0;
- int grayLevel;
-
- // Creation
- for (int i = 0; i < MAX_BUILDINGS; i++)
- {
- // Horizontal
- building[i].rectangle.x = currentWidth;
- building[i].rectangle.width = GetRandomValue(buildingWidthMean*(100 - BUILDING_RELATIVE_ERROR/2)/100 + 1, buildingWidthMean*(100 + BUILDING_RELATIVE_ERROR)/100);
-
- currentWidth += building[i].rectangle.width;
-
- // Vertical
- currentHeighth = GetRandomValue(BUILDING_MIN_RELATIVE_HEIGHT, BUILDING_MAX_RELATIVE_HEIGHT);
- building[i].rectangle.y = screenHeight - (screenHeight*currentHeighth/100);
- building[i].rectangle.height = screenHeight*currentHeighth/100 + 1;
-
- // Color
- grayLevel = GetRandomValue(BUILDING_MIN_GRAYSCALE_COLOR, BUILDING_MAX_GRAYSCALE_COLOR);
- building[i].color = (Color){ grayLevel, grayLevel, grayLevel, 255 };
- }
-}
-
-static void InitPlayers(void)
-{
- for (int i = 0; i < MAX_PLAYERS; i++)
- {
- player[i].isAlive = true;
-
- // Decide the team of this player
- if (i % 2 == 0) player[i].isLeftTeam = true;
- else player[i].isLeftTeam = false;
-
- // Now there is no AI
- player[i].isPlayer = true;
-
- // Set size, by default by now
- player[i].size = (Vector2){ 40, 40 };
-
- // Set position
- if (player[i].isLeftTeam) player[i].position.x = GetRandomValue(screenWidth*MIN_PLAYER_POSITION/100, screenWidth*MAX_PLAYER_POSITION/100);
- else player[i].position.x = screenWidth - GetRandomValue(screenWidth*MIN_PLAYER_POSITION/100, screenWidth*MAX_PLAYER_POSITION/100);
-
- for (int j = 0; j < MAX_BUILDINGS; j++)
- {
- if (building[j].rectangle.x > player[i].position.x)
- {
- // Set the player in the center of the building
- player[i].position.x = building[j-1].rectangle.x + building[j-1].rectangle.width/2;
- // Set the player at the top of the building
- player[i].position.y = building[j-1].rectangle.y - player[i].size.y/2;
- break;
- }
- }
-
- // Set statistics to 0
- player[i].aimingPoint = player[i].position;
- player[i].previousAngle = 0;
- player[i].previousPower = 0;
- player[i].previousPoint = player[i].position;
- player[i].aimingAngle = 0;
- player[i].aimingPower = 0;
-
- player[i].impactPoint = (Vector2){ -100, -100 };
- }
-}
-
-static bool UpdatePlayer(int playerTurn)
-{
- // If we are aiming at the firing quadrant, we calculate the angle
- if (GetMousePosition().y <= player[playerTurn].position.y)
- {
- // Left team
- if (player[playerTurn].isLeftTeam && GetMousePosition().x >= player[playerTurn].position.x)
- {
- // Distance (calculating the fire power)
- player[playerTurn].aimingPower = sqrt(pow(player[playerTurn].position.x - GetMousePosition().x, 2) + pow(player[playerTurn].position.y - GetMousePosition().y, 2));
- // Calculates the angle via arcsin
- player[playerTurn].aimingAngle = asin((player[playerTurn].position.y - GetMousePosition().y)/player[playerTurn].aimingPower)*RAD2DEG;
- // Point of the screen we are aiming at
- player[playerTurn].aimingPoint = GetMousePosition();
-
- // Ball fired
- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
- {
- player[playerTurn].previousPoint = player[playerTurn].aimingPoint;
- player[playerTurn].previousPower = player[playerTurn].aimingPower;
- player[playerTurn].previousAngle = player[playerTurn].aimingAngle;
- ball.position = player[playerTurn].position;
-
- return true;
- }
- }
- // Right team
- else if (!player[playerTurn].isLeftTeam && GetMousePosition().x <= player[playerTurn].position.x)
- {
- // Distance (calculating the fire power)
- player[playerTurn].aimingPower = sqrt(pow(player[playerTurn].position.x - GetMousePosition().x, 2) + pow(player[playerTurn].position.y - GetMousePosition().y, 2));
- // Calculates the angle via arcsin
- player[playerTurn].aimingAngle = asin((player[playerTurn].position.y - GetMousePosition().y)/player[playerTurn].aimingPower)*RAD2DEG;
- // Point of the screen we are aiming at
- player[playerTurn].aimingPoint = GetMousePosition();
-
- // Ball fired
- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
- {
- player[playerTurn].previousPoint = player[playerTurn].aimingPoint;
- player[playerTurn].previousPower = player[playerTurn].aimingPower;
- player[playerTurn].previousAngle = player[playerTurn].aimingAngle;
- ball.position = player[playerTurn].position;
-
- return true;
- }
- }
- else
- {
- player[playerTurn].aimingPoint = player[playerTurn].position;
- player[playerTurn].aimingPower = 0;
- player[playerTurn].aimingAngle = 0;
- }
- }
- else
- {
- player[playerTurn].aimingPoint = player[playerTurn].position;
- player[playerTurn].aimingPower = 0;
- player[playerTurn].aimingAngle = 0;
- }
-
- return false;
-}
-
-static bool UpdateBall(int playerTurn)
-{
- static int explosionNumber = 0;
-
- // Activate ball
- if (!ball.active)
- {
- if (player[playerTurn].isLeftTeam)
- {
- ball.speed.x = cos(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
- ball.speed.y = -sin(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
- ball.active = true;
- }
- else
- {
- ball.speed.x = -cos(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
- ball.speed.y = -sin(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
- ball.active = true;
- }
- }
-
- ball.position.x += ball.speed.x;
- ball.position.y += ball.speed.y;
- ball.speed.y += GRAVITY/DELTA_FPS;
-
- // Collision
- if (ball.position.x + ball.radius < 0) return true;
- else if (ball.position.x - ball.radius > screenWidth) return true;
- else
- {
- // Player collision
- for (int i = 0; i < MAX_PLAYERS; i++)
- {
- if (CheckCollisionCircleRec(ball.position, ball.radius, (Rectangle){ player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2,
- player[i].size.x, player[i].size.y }))
- {
- // We can't hit ourselves
- if (i == playerTurn) return false;
- else
- {
- // We set the impact point
- player[playerTurn].impactPoint.x = ball.position.x;
- player[playerTurn].impactPoint.y = ball.position.y + ball.radius;
-
- // We destroy the player
- player[i].isAlive = false;
- return true;
- }
- }
- }
-
- // Building collision
- // NOTE: We only check building collision if we are not inside an explosion
- for (int i = 0; i < MAX_BUILDINGS; i++)
- {
- if (CheckCollisionCircles(ball.position, ball.radius, explosion[i].position, explosion[i].radius - ball.radius))
- {
- return false;
- }
- }
-
- for (int i = 0; i < MAX_BUILDINGS; i++)
- {
- if (CheckCollisionCircleRec(ball.position, ball.radius, building[i].rectangle))
- {
- // We set the impact point
- player[playerTurn].impactPoint.x = ball.position.x;
- player[playerTurn].impactPoint.y = ball.position.y + ball.radius;
-
- // We create an explosion
- explosion[explosionNumber].position = player[playerTurn].impactPoint;
- explosion[explosionNumber].active = true;
- explosionNumber++;
-
- return true;
- }
- }
- }
-
- return false;
-} \ No newline at end of file
diff --git a/games/samples/missile_commander.c b/games/samples/missile_commander.c
deleted file mode 100644
index 6317c41a..00000000
--- a/games/samples/missile_commander.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: missile commander
-*
-* Sample game Marc Palau and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <math.h>
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define MAX_MISSILES 100
-#define MAX_INTERCEPTORS 30
-#define MAX_EXPLOSIONS 100
-#define LAUNCHERS_AMOUNT 3 // Not a variable, should not be changed
-#define BUILDINGS_AMOUNT 6 // Not a variable, should not be changed
-
-#define LAUNCHER_SIZE 80
-#define BUILDING_SIZE 60
-#define EXPLOSION_RADIUS 40
-
-#define MISSILE_SPEED 1
-#define MISSILE_LAUNCH_FRAMES 80
-#define INTERCEPTOR_SPEED 10
-#define EXPLOSION_INCREASE_TIME 90 // In frames
-#define EXPLOSION_TOTAL_TIME 210 // In frames
-
-#define EXPLOSION_COLOR (Color){ 125, 125, 125, 125 }
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef struct Missile {
- Vector2 origin;
- Vector2 position;
- Vector2 objective;
- Vector2 speed;
-
- bool active;
-} Missile;
-
-typedef struct Interceptor {
- Vector2 origin;
- Vector2 position;
- Vector2 objective;
- Vector2 speed;
-
- bool active;
-} Interceptor;
-
-typedef struct Explosion {
- Vector2 position;
- float radiusMultiplier;
- int frame;
- bool active;
-} Explosion;
-
-typedef struct Launcher {
- Vector2 position;
- bool active;
-} Launcher;
-
-typedef struct Building {
- Vector2 position;
- bool active;
-} Building;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter = 0;
-static bool gameOver = false;
-static bool pause = false;
-static int score = 0;
-
-static Missile missile[MAX_MISSILES];
-static Interceptor interceptor[MAX_INTERCEPTORS];
-static Explosion explosion[MAX_EXPLOSIONS];
-static Launcher launcher[LAUNCHERS_AMOUNT];
-static Building building[BUILDINGS_AMOUNT];
-static int explosionIndex = 0;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-// Additional module functions
-static void UpdateOutgoingFire();
-static void UpdateIncomingFire();
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: missile commander");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//--------------------------------------------------------------------------------------
-// Game Module Functions Definition
-//--------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- // Initialize missiles
- for (int i = 0; i < MAX_MISSILES; i++)
- {
- missile[i].origin = (Vector2){ 0, 0 };
- missile[i].speed = (Vector2){ 0, 0 };
- missile[i].position = (Vector2){ 0, 0 };
-
- missile[i].active = false;
- }
-
- // Initialize interceptors
- for (int i = 0; i < MAX_INTERCEPTORS; i++)
- {
- interceptor[i].origin = (Vector2){ 0, 0 };
- interceptor[i].speed = (Vector2){ 0, 0 };
- interceptor[i].position = (Vector2){ 0, 0 };
-
- interceptor[i].active = false;
- }
-
- // Initialize explosions
- for (int i = 0; i < MAX_EXPLOSIONS; i++)
- {
- explosion[i].position = (Vector2){ 0, 0 };
- explosion[i].frame = 0;
- explosion[i].active = false;
- }
-
- // Initialize buildings and launchers
- int sparcing = screenWidth/(LAUNCHERS_AMOUNT + BUILDINGS_AMOUNT + 1);
-
- // Buildings and launchers placing
- launcher[0].position = (Vector2){ 1*sparcing, screenHeight - LAUNCHER_SIZE/2 };
- building[0].position = (Vector2){ 2*sparcing, screenHeight - BUILDING_SIZE/2 };
- building[1].position = (Vector2){ 3*sparcing, screenHeight - BUILDING_SIZE/2 };
- building[2].position = (Vector2){ 4*sparcing, screenHeight - BUILDING_SIZE/2 };
- launcher[1].position = (Vector2){ 5*sparcing, screenHeight - LAUNCHER_SIZE/2 };
- building[3].position = (Vector2){ 6*sparcing, screenHeight - BUILDING_SIZE/2 };
- building[4].position = (Vector2){ 7*sparcing, screenHeight - BUILDING_SIZE/2 };
- building[5].position = (Vector2){ 8*sparcing, screenHeight - BUILDING_SIZE/2 };
- launcher[2].position = (Vector2){ 9*sparcing, screenHeight - LAUNCHER_SIZE/2 };
-
- // Buildings and launchers activation
- for (int i = 0; i < LAUNCHERS_AMOUNT; i++) launcher[i].active = true;
- for (int i = 0; i < BUILDINGS_AMOUNT; i++) building[i].active = true;
-
- // Initialize game variables
- score = 0;
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- framesCounter++;
-
- static
- float distance;
-
- // Interceptors update
- for (int i = 0; i < MAX_INTERCEPTORS; i++)
- {
- if (interceptor[i].active)
- {
- // Update position
- interceptor[i].position.x += interceptor[i].speed.x;
- interceptor[i].position.y += interceptor[i].speed.y;
-
- // Distance to objective
- distance = sqrt( pow(interceptor[i].position.x - interceptor[i].objective.x, 2) +
- pow(interceptor[i].position.y - interceptor[i].objective.y, 2));
-
- if (distance < INTERCEPTOR_SPEED)
- {
- // Interceptor dissapears
- interceptor[i].active = false;
-
- // Explosion
- explosion[explosionIndex].position = interceptor[i].position;
- explosion[explosionIndex].active = true;
- explosion[explosionIndex].frame = 0;
- explosionIndex++;
- if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;
-
- break;
- }
- }
- }
-
- // Missiles update
- for (int i = 0; i < MAX_MISSILES; i++)
- {
- if (missile[i].active)
- {
- // Update position
- missile[i].position.x += missile[i].speed.x;
- missile[i].position.y += missile[i].speed.y;
-
- // Collision and missile out of bounds
- if (missile[i].position.y > screenHeight) missile[i].active = false;
- else
- {
- // CHeck collision with launchers
- for (int j = 0; j < LAUNCHERS_AMOUNT; j++)
- {
- if (launcher[j].active)
- {
- if (CheckCollisionPointRec(missile[i].position, (Rectangle){ launcher[j].position.x - LAUNCHER_SIZE/2, launcher[j].position.y - LAUNCHER_SIZE/2,
- LAUNCHER_SIZE, LAUNCHER_SIZE }))
- {
- // Missile dissapears
- missile[i].active = false;
-
- // Explosion and destroy building
- launcher[j].active = false;
-
- explosion[explosionIndex].position = missile[i].position;
- explosion[explosionIndex].active = true;
- explosion[explosionIndex].frame = 0;
- explosionIndex++;
- if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;
-
- break;
- }
- }
- }
-
- // CHeck collision with buildings
- for (int j = 0; j < BUILDINGS_AMOUNT; j++)
- {
- if (building[j].active)
- {
- if (CheckCollisionPointRec(missile[i].position, (Rectangle){ building[j].position.x - BUILDING_SIZE/2, building[j].position.y - BUILDING_SIZE/2,
- BUILDING_SIZE, BUILDING_SIZE }))
- {
- // Missile dissapears
- missile[i].active = false;
-
- // Explosion and destroy building
- building[j].active = false;
-
- explosion[explosionIndex].position = missile[i].position;
- explosion[explosionIndex].active = true;
- explosion[explosionIndex].frame = 0;
- explosionIndex++;
- if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;
-
- break;
- }
- }
- }
-
- // CHeck collision with explosions
- for (int j = 0; j < MAX_EXPLOSIONS; j++)
- {
- if (explosion[j].active)
- {
- if (CheckCollisionPointCircle(missile[i].position, explosion[j].position, EXPLOSION_RADIUS*explosion[j].radiusMultiplier))
- {
- // Missile dissapears and we earn 100 points
- missile[i].active = false;
- score += 100;
-
- explosion[explosionIndex].position = missile[i].position;
- explosion[explosionIndex].active = true;
- explosion[explosionIndex].frame = 0;
- explosionIndex++;
- if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;
-
- break;
- }
- }
- }
- }
- }
- }
-
- // Explosions update
- for (int i = 0; i < MAX_EXPLOSIONS; i++)
- {
- if (explosion[i].active)
- {
- explosion[i].frame++;
-
- if (explosion[i].frame <= EXPLOSION_INCREASE_TIME) explosion[i].radiusMultiplier = explosion[i].frame/(float)EXPLOSION_INCREASE_TIME;
- else if (explosion[i].frame <= EXPLOSION_TOTAL_TIME) explosion[i].radiusMultiplier = 1 - (explosion[i].frame - (float)EXPLOSION_INCREASE_TIME)/(float)EXPLOSION_TOTAL_TIME;
- else
- {
- explosion[i].frame = 0;
- explosion[i].active = false;
- }
- }
- }
-
- // Fire logic
- UpdateOutgoingFire();
- UpdateIncomingFire();
-
- // Game over logic
- int checker = 0;
-
- for (int i = 0; i < LAUNCHERS_AMOUNT; i++)
- {
- if (!launcher[i].active) checker++;
- if (checker == LAUNCHERS_AMOUNT) gameOver = true;
- }
-
- checker = 0;
- for (int i = 0; i < BUILDINGS_AMOUNT; i++)
- {
- if (!building[i].active) checker++;
- if (checker == BUILDINGS_AMOUNT) gameOver = true;
- }
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw missiles
- for (int i = 0; i < MAX_MISSILES; i++)
- {
- if (missile[i].active)
- {
- DrawLine(missile[i].origin.x, missile[i].origin.y, missile[i].position.x, missile[i].position.y, RED);
-
- if (framesCounter % 16 < 8) DrawCircle(missile[i].position.x, missile[i].position.y, 3, YELLOW);
- }
- }
-
- // Draw interceptors
- for (int i = 0; i < MAX_INTERCEPTORS; i++)
- {
- if (interceptor[i].active)
- {
- DrawLine(interceptor[i].origin.x, interceptor[i].origin.y, interceptor[i].position.x, interceptor[i].position.y, GREEN);
-
- if (framesCounter % 16 < 8) DrawCircle(interceptor[i].position.x, interceptor[i].position.y, 3, BLUE);
- }
- }
-
- // Draw explosions
- for (int i = 0; i < MAX_EXPLOSIONS; i++)
- {
- if (explosion[i].active) DrawCircle(explosion[i].position.x, explosion[i].position.y, EXPLOSION_RADIUS*explosion[i].radiusMultiplier, EXPLOSION_COLOR);
- }
-
- // Draw buildings and launchers
- for (int i = 0; i < LAUNCHERS_AMOUNT; i++)
- {
- if (launcher[i].active) DrawRectangle(launcher[i].position.x - LAUNCHER_SIZE/2, launcher[i].position.y - LAUNCHER_SIZE/2, LAUNCHER_SIZE, LAUNCHER_SIZE, GRAY);
- }
-
- for (int i = 0; i < BUILDINGS_AMOUNT; i++)
- {
- if (building[i].active) DrawRectangle(building[i].position.x - BUILDING_SIZE/2, building[i].position.y - BUILDING_SIZE/2, BUILDING_SIZE, BUILDING_SIZE, LIGHTGRAY);
- }
-
- // Draw score
- DrawText(FormatText("SCORE %4i", score), 20, 20, 40, LIGHTGRAY);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-}
-
-//--------------------------------------------------------------------------------------
-// Additional module functions
-//--------------------------------------------------------------------------------------
-static void UpdateOutgoingFire()
-{
- static int interceptorNumber = 0;
- int launcherShooting = 0;
-
- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) launcherShooting = 1;
- if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) launcherShooting = 2;
- if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) launcherShooting = 3;
-
- if (launcherShooting > 0 && launcher[launcherShooting - 1].active)
- {
- float module;
- float sideX;
- float sideY;
-
- // Activate the interceptor
- interceptor[interceptorNumber].active = true;
-
- // Assign start position
- interceptor[interceptorNumber].origin = launcher[launcherShooting - 1].position;
- interceptor[interceptorNumber].position = interceptor[interceptorNumber].origin;
- interceptor[interceptorNumber].objective = GetMousePosition();
-
- // Calculate speed
- module = sqrt( pow(interceptor[interceptorNumber].objective.x - interceptor[interceptorNumber].origin.x, 2) +
- pow(interceptor[interceptorNumber].objective.y - interceptor[interceptorNumber].origin.y, 2));
-
- sideX = (interceptor[interceptorNumber].objective.x - interceptor[interceptorNumber].origin.x)*INTERCEPTOR_SPEED/module;
- sideY = (interceptor[interceptorNumber].objective.y - interceptor[interceptorNumber].origin.y)*INTERCEPTOR_SPEED/module;
-
- interceptor[interceptorNumber].speed = (Vector2){ sideX, sideY };
-
- // Update
- interceptorNumber++;
- if (interceptorNumber == MAX_INTERCEPTORS) interceptorNumber = 0;
- }
-}
-
-static void UpdateIncomingFire()
-{
- static int missileIndex = 0;
-
- // Launch missile
- if (framesCounter % MISSILE_LAUNCH_FRAMES == 0)
- {
- float module;
- float sideX;
- float sideY;
-
- // Activate the missile
- missile[missileIndex].active = true;
-
- // Assign start position
- missile[missileIndex].origin = (Vector2){ GetRandomValue(20, screenWidth - 20), -10 };
- missile[missileIndex].position = missile[missileIndex].origin;
- missile[missileIndex].objective = (Vector2){ GetRandomValue(20, screenWidth - 20), screenHeight + 10 };
-
- // Calculate speed
- module = sqrt( pow(missile[missileIndex].objective.x - missile[missileIndex].origin.x, 2) +
- pow(missile[missileIndex].objective.y - missile[missileIndex].origin.y, 2));
-
- sideX = (missile[missileIndex].objective.x - missile[missileIndex].origin.x)*MISSILE_SPEED/module;
- sideY = (missile[missileIndex].objective.y - missile[missileIndex].origin.y)*MISSILE_SPEED/module;
-
- missile[missileIndex].speed = (Vector2){ sideX, sideY };
-
- // Update
- missileIndex++;
- if (missileIndex == MAX_MISSILES) missileIndex = 0;
- }
-} \ No newline at end of file
diff --git a/games/samples/pang.c b/games/samples/pang.c
deleted file mode 100644
index fe1c3005..00000000
--- a/games/samples/pang.c
+++ /dev/null
@@ -1,630 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: pang
-*
-* Sample game developed by Ian Eito and Albert Martos and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <math.h>
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define PLAYER_BASE_SIZE 20.0f
-#define PLAYER_SPEED 5.0f
-#define PLAYER_MAX_SHOOTS 1
-
-#define MAX_BIG_BALLS 2
-#define BALLS_SPEED 2.0f
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-
-typedef struct Player {
- Vector2 position;
- Vector2 speed;
- Vector3 collider;
- float rotation;
-} Player;
-
-typedef struct Shoot {
- Vector2 position;
- Vector2 speed;
- float radius;
- float rotation;
- int lifeSpawn;
- bool active;
-} Shoot;
-
-typedef struct Ball {
- Vector2 position;
- Vector2 speed;
- float radius;
- int points;
- bool active;
-} Ball;
-
-typedef struct Points {
- Vector2 position;
- int value;
- float alpha;
-} Points;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-static int score;
-
-static Player player;
-static Shoot shoot[PLAYER_MAX_SHOOTS];
-static Ball bigBalls[MAX_BIG_BALLS];
-static Ball mediumBalls[MAX_BIG_BALLS*2];
-static Ball smallBalls[MAX_BIG_BALLS*4];
-static Points points[5];
-
-// NOTE: Defined triangle is isosceles with common angles of 70 degrees.
-static float shipHeight;
-static float gravity;
-
-static int countmediumBallss;
-static int countsmallBallss;
-static int meteorsDestroyed;
-static Vector2 linePosition;
-
-static bool victory;
-static bool lose;
-static bool awake;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- InitWindow(screenWidth, screenHeight, "sample game: pang");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-static void InitGame(void)
-{
- int posx, posy;
- int velx = 0;
- int vely = 0;
-
- framesCounter = 0;
- gameOver = false;
- pause = false;
- score = 0;
-
- victory = false;
- lose = false;
- awake = true;
- gravity = 0.25f;
-
- linePosition = (Vector2){ 0.0f , 0.0f };
- shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD);
-
- // Initialization player
- player.position = (Vector2){ screenWidth/2, screenHeight };
- player.speed = (Vector2){ PLAYER_SPEED, PLAYER_SPEED };
- player.rotation = 0;
- player.collider = (Vector3){ player.position.x, player.position.y - shipHeight/2.0f, 12.0f };
-
- meteorsDestroyed = 0;
-
- // Initialize shoots
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- shoot[i].position = (Vector2){ 0, 0 };
- shoot[i].speed = (Vector2){ 0, 0 };
- shoot[i].radius = 2;
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- }
-
- // Initialize big meteors
- for (int i = 0; i < MAX_BIG_BALLS; i++)
- {
- bigBalls[i].radius = 40.0f;
- posx = GetRandomValue(0 + bigBalls[i].radius, screenWidth - bigBalls[i].radius);
- posy = GetRandomValue(0 + bigBalls[i].radius, screenHeight/2);
-
- bigBalls[i].position = (Vector2){ posx, posy };
-
- while ((velx == 0) || (vely == 0))
- {
- velx = GetRandomValue(-BALLS_SPEED, BALLS_SPEED);
- vely = GetRandomValue(-BALLS_SPEED, BALLS_SPEED);
- }
-
- bigBalls[i].speed = (Vector2){ velx, vely };
- bigBalls[i].points = 200;
- bigBalls[i].active = true;
- }
-
- // Initialize medium meteors
- for (int i = 0; i < MAX_BIG_BALLS*2; i++)
- {
- mediumBalls[i].position = (Vector2){-100, -100};
- mediumBalls[i].speed = (Vector2){0,0};
- mediumBalls[i].radius = 20.0f;
- mediumBalls[i].points = 100;
- mediumBalls[i].active = false;
- }
-
- // Initialize small meteors
- for (int i = 0; i < MAX_BIG_BALLS*4; i++)
- {
- smallBalls[i].position = (Vector2){ -100, -100 };
- smallBalls[i].speed = (Vector2){ 0, 0 };
- smallBalls[i].radius = 10.0f;
- smallBalls[i].points = 50;
- smallBalls[i].active = false;
- }
-
- // Initialize animated points
- for (int i = 0; i < 5; i++)
- {
- points[i].position = (Vector2){ 0, 0 };
- points[i].value = 0;
- points[i].alpha = 0.0f;
- }
-
- countmediumBallss = 0;
- countsmallBallss = 0;
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver && !victory)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- // Player logic
- if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x;
- if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x;
-
- // Player vs wall collision logic
- if (player.position.x + PLAYER_BASE_SIZE/2 > screenWidth) player.position.x = screenWidth - PLAYER_BASE_SIZE/2;
- else if (player.position.x - PLAYER_BASE_SIZE/2 < 0) player.position.x = 0 + PLAYER_BASE_SIZE/2;
-
- // Player shot logic
- if (IsKeyPressed(KEY_SPACE))
- {
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (!shoot[i].active)
- {
- shoot[i].position = (Vector2){ player.position.x, player.position.y - shipHeight };
- shoot[i].speed.y = PLAYER_SPEED;
- shoot[i].active = true;
-
- linePosition = (Vector2){ player.position.x, player.position.y};
-
- break;
- }
- }
- }
-
- // Shoot life timer
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (shoot[i].active) shoot[i].lifeSpawn++;
- }
-
- // Shot logic
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (shoot[i].active)
- {
- shoot[i].position.y -= shoot[i].speed.y;
-
- // Shot vs walls collision logic
- if ((shoot[i].position.x > screenWidth + shoot[i].radius) || (shoot[i].position.x < 0 - shoot[i].radius) ||
- (shoot[i].position.y > screenHeight + shoot[i].radius) || (shoot[i].position.y < 0 - shoot[i].radius))
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- }
-
- // Player shot life spawn
- if (shoot[i].lifeSpawn >= 120)
- {
- shoot[i].position = (Vector2){ 0.0f, 0.0f };
- shoot[i].speed = (Vector2){ 0.0f, 0.0f };
- shoot[i].lifeSpawn = 0;
- shoot[i].active = false;
- }
- }
- }
-
- // Player vs meteors collision logic
- player.collider = (Vector3){player.position.x, player.position.y - shipHeight/2, 12};
-
- for (int i = 0; i < MAX_BIG_BALLS; i++)
- {
- if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, bigBalls[i].position, bigBalls[i].radius) && bigBalls[i].active)
- {
- gameOver = true;
- }
- }
-
- for (int i = 0; i < MAX_BIG_BALLS*2; i++)
- {
- if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, mediumBalls[i].position, mediumBalls[i].radius) && mediumBalls[i].active)
- {
- gameOver = true;
- }
- }
-
- for (int i = 0; i < MAX_BIG_BALLS*4; i++)
- {
- if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, smallBalls[i].position, smallBalls[i].radius) && smallBalls[i].active)
- {
- gameOver = true;
- }
- }
-
- // Meteors logic (big)
- for (int i = 0; i < MAX_BIG_BALLS; i++)
- {
- if (bigBalls[i].active)
- {
- // Meteor movement logic
- bigBalls[i].position.x += bigBalls[i].speed.x;
- bigBalls[i].position.y += bigBalls[i].speed.y;
-
- // Meteor vs wall collision logic
- if (((bigBalls[i].position.x + bigBalls[i].radius) >= screenWidth) || ((bigBalls[i].position.x - bigBalls[i].radius) <= 0)) bigBalls[i].speed.x *= -1;
- if ((bigBalls[i].position.y - bigBalls[i].radius) <= 0) bigBalls[i].speed.y *= -1.5;
-
- if ((bigBalls[i].position.y + bigBalls[i].radius) >= screenHeight)
- {
- bigBalls[i].speed.y *= -1;
- bigBalls[i].position.y = screenHeight - bigBalls[i].radius;
- }
-
- bigBalls[i].speed.y += gravity;
- }
- }
-
- // Meteors logic (medium)
- for (int i = 0; i < MAX_BIG_BALLS*2; i++)
- {
- if (mediumBalls[i].active)
- {
- // Meteor movement logic
- mediumBalls[i].position.x += mediumBalls[i].speed.x;
- mediumBalls[i].position.y += mediumBalls[i].speed.y;
-
- // Meteor vs wall collision logic
- if (mediumBalls[i].position.x + mediumBalls[i].radius >= screenWidth || mediumBalls[i].position.x - mediumBalls[i].radius <= 0) mediumBalls[i].speed.x *= -1;
- if (mediumBalls[i].position.y - mediumBalls[i].radius <= 0) mediumBalls[i].speed.y *= -1;
- if (mediumBalls[i].position.y + mediumBalls[i].radius >= screenHeight)
- {
- mediumBalls[i].speed.y *= -1;
- mediumBalls[i].position.y = screenHeight - mediumBalls[i].radius;
- }
-
- mediumBalls[i].speed.y += gravity + 0.12f;
- }
- }
-
- // Meteors logic (small)
- for (int i = 0; i < MAX_BIG_BALLS*4; i++)
- {
- if (smallBalls[i].active)
- {
- // Meteor movement logic
- smallBalls[i].position.x += smallBalls[i].speed.x;
- smallBalls[i].position.y += smallBalls[i].speed.y;
-
- // Meteor vs wall collision logic
- if (smallBalls[i].position.x + smallBalls[i].radius >= screenWidth || smallBalls[i].position.x - smallBalls[i].radius <= 0) smallBalls[i].speed.x *= -1;
- if (smallBalls[i].position.y - smallBalls[i].radius <= 0) smallBalls[i].speed.y *= -1;
- if (smallBalls[i].position.y + smallBalls[i].radius >= screenHeight)
- {
- smallBalls[i].speed.y *= -1;
- smallBalls[i].position.y = screenHeight - smallBalls[i].radius;
- }
-
- smallBalls[i].speed.y += gravity + 0.25f;
- }
- }
-
- // Player-shot vs meteors logic
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if ((shoot[i].active))
- {
- for (int a = 0; a < MAX_BIG_BALLS; a++)
- {
- if (bigBalls[a].active && (bigBalls[a].position.x - bigBalls[a].radius <= linePosition.x && bigBalls[a].position.x + bigBalls[a].radius >= linePosition.x)
- && (bigBalls[a].position.y + bigBalls[a].radius >= shoot[i].position.y))
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- bigBalls[a].active = false;
- meteorsDestroyed++;
- score += bigBalls[a].points;
-
- for (int z = 0; z < 5; z++)
- {
- if (points[z].alpha == 0.0f)
- {
- points[z].position = bigBalls[a].position;
- points[z].value = bigBalls[a].points;
- points[z].alpha = 1.0f;
- z = 5;
- }
- }
-
- for (int j = 0; j < 2; j ++)
- {
- if ((countmediumBallss%2) == 0)
- {
- mediumBalls[countmediumBallss].position = (Vector2){bigBalls[a].position.x, bigBalls[a].position.y};
- mediumBalls[countmediumBallss].speed = (Vector2){ -1*BALLS_SPEED, BALLS_SPEED };
- }
- else
- {
- mediumBalls[countmediumBallss].position = (Vector2){bigBalls[a].position.x, bigBalls[a].position.y};
- mediumBalls[countmediumBallss].speed = (Vector2){ BALLS_SPEED, BALLS_SPEED };
- }
-
- mediumBalls[countmediumBallss].active = true;
- countmediumBallss ++;
- }
-
- a = MAX_BIG_BALLS;
- }
- }
- }
-
- if ((shoot[i].active))
- {
- for (int b = 0; b < MAX_BIG_BALLS*2; b++)
- {
- if (mediumBalls[b].active && (mediumBalls[b].position.x - mediumBalls[b].radius <= linePosition.x && mediumBalls[b].position.x + mediumBalls[b].radius >= linePosition.x)
- && (mediumBalls[b].position.y + mediumBalls[b].radius >= shoot[i].position.y))
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- mediumBalls[b].active = false;
- meteorsDestroyed++;
- score += mediumBalls[b].points;
-
- for (int z = 0; z < 5; z++)
- {
- if (points[z].alpha == 0.0f)
- {
- points[z].position = mediumBalls[b].position;
- points[z].value = mediumBalls[b].points;
- points[z].alpha = 1.0f;
- z = 5;
- }
- }
-
- for (int j = 0; j < 2; j ++)
- {
- if (countsmallBallss%2 == 0)
- {
- smallBalls[countsmallBallss].position = (Vector2){mediumBalls[b].position.x, mediumBalls[b].position.y};
- smallBalls[countsmallBallss].speed = (Vector2){ BALLS_SPEED*-1, BALLS_SPEED*-1};
- }
- else
- {
- smallBalls[countsmallBallss].position = (Vector2){mediumBalls[b].position.x, mediumBalls[b].position.y};
- smallBalls[countsmallBallss].speed = (Vector2){ BALLS_SPEED, BALLS_SPEED*-1};
- }
-
- smallBalls[countsmallBallss].active = true;
- countsmallBallss ++;
- }
-
- b = MAX_BIG_BALLS*2;
- }
- }
- }
-
- if ((shoot[i].active))
- {
- for (int c = 0; c < MAX_BIG_BALLS*4; c++)
- {
- if (smallBalls[c].active && (smallBalls[c].position.x - smallBalls[c].radius <= linePosition.x && smallBalls[c].position.x + smallBalls[c].radius >= linePosition.x)
- && (smallBalls[c].position.y + smallBalls[c].radius >= shoot[i].position.y))
- {
- shoot[i].active = false;
- shoot[i].lifeSpawn = 0;
- smallBalls[c].active = false;
- meteorsDestroyed++;
- score += smallBalls[c].points;
-
- for (int z = 0; z < 5; z++)
- {
- if (points[z].alpha == 0.0f)
- {
- points[z].position = smallBalls[c].position;
- points[z].value = smallBalls[c].points;
- points[z].alpha = 1.0f;
- z = 5;
- }
- }
-
- c = MAX_BIG_BALLS*4;
- }
- }
- }
- }
-
- if (meteorsDestroyed == (MAX_BIG_BALLS + MAX_BIG_BALLS*2 + MAX_BIG_BALLS*4)) victory = true;
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-
- // Points move-up and fade logic
- for (int z = 0; z < 5; z++)
- {
- if (points[z].alpha > 0.0f)
- {
- points[z].position.y -= 2;
- points[z].alpha -= 0.02f;
- }
-
- if (points[z].alpha < 0.0f) points[z].alpha = 0.0f;
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw player
- Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) };
- Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
- Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
- DrawTriangle(v1, v2, v3, MAROON);
-
- // Draw meteors (big)
- for (int i = 0;i < MAX_BIG_BALLS; i++)
- {
- if (bigBalls[i].active) DrawCircleV(bigBalls[i].position, bigBalls[i].radius, DARKGRAY);
- else DrawCircleV(bigBalls[i].position, bigBalls[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- // Draw meteors (medium)
- for (int i = 0;i < MAX_BIG_BALLS*2; i++)
- {
- if (mediumBalls[i].active) DrawCircleV(mediumBalls[i].position, mediumBalls[i].radius, GRAY);
- else DrawCircleV(mediumBalls[i].position, mediumBalls[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- // Draw meteors (small)
- for (int i = 0;i < MAX_BIG_BALLS*4; i++)
- {
- if (smallBalls[i].active) DrawCircleV(smallBalls[i].position, smallBalls[i].radius, GRAY);
- else DrawCircleV(smallBalls[i].position, smallBalls[i].radius, Fade(LIGHTGRAY, 0.3f));
- }
-
- // Draw shoot
- for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
- {
- if (shoot[i].active) DrawLine(linePosition.x, linePosition.y, shoot[i].position.x, shoot[i].position.y, RED);
- }
-
- // Draw score points
- for (int z = 0; z < 5; z++)
- {
- if (points[z].alpha > 0.0f)
- {
- DrawText(FormatText("+%02i", points[z].value), points[z].position.x, points[z].position.y, 20, Fade(BLUE, points[z].alpha));
- }
- }
-
- // Draw score (UI)
- DrawText(FormatText("SCORE: %i", score), 10, 10, 20, LIGHTGRAY);
-
- if (victory)
- {
- DrawText("YOU WIN!", screenWidth/2 - MeasureText("YOU WIN!", 60)/2, 100, 60, LIGHTGRAY);
- DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, LIGHTGRAY);
- }
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, LIGHTGRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, LIGHTGRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-} \ No newline at end of file
diff --git a/games/samples/snake.c b/games/samples/snake.c
deleted file mode 100644
index ac2f6132..00000000
--- a/games/samples/snake.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: snake
-*
-* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define SNAKE_LENGTH 256
-#define SQUARE_SIZE 31
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef struct Snake {
- Vector2 position;
- Vector2 size;
- Vector2 speed;
- Color color;
-} Snake;
-
-typedef struct Food {
- Vector2 position;
- Vector2 size;
- bool active;
- Color color;
-} Food;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-
-static Food fruit;
-static Snake snake[SNAKE_LENGTH];
-static Vector2 snakePosition[SNAKE_LENGTH];
-static bool allowMove;
-static Vector2 offset;
-static int counterTail;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: snake");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- framesCounter = 0;
- gameOver = false;
- pause = false;
-
- counterTail = 1;
- allowMove = false;
-
- offset.x = screenWidth%SQUARE_SIZE;
- offset.y = screenHeight%SQUARE_SIZE;
-
- for (int i = 0; i < SNAKE_LENGTH; i++)
- {
- 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 };
-
- if (i == 0) snake[i].color = DARKBLUE;
- else snake[i].color = BLUE;
- }
-
- for (int i = 0; i < SNAKE_LENGTH; i++)
- {
- snakePosition[i] = (Vector2){ 0.0f, 0.0f };
- }
-
- fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE };
- fruit.color = SKYBLUE;
- fruit.active = false;
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- // control
- if (IsKeyPressed(KEY_RIGHT) && (snake[0].speed.x == 0) && allowMove)
- {
- snake[0].speed = (Vector2){ SQUARE_SIZE, 0 };
- allowMove = false;
- }
- if (IsKeyPressed(KEY_LEFT) && (snake[0].speed.x == 0) && allowMove)
- {
- snake[0].speed = (Vector2){ -SQUARE_SIZE, 0 };
- allowMove = false;
- }
- if (IsKeyPressed(KEY_UP) && (snake[0].speed.y == 0) && allowMove)
- {
- snake[0].speed = (Vector2){ 0, -SQUARE_SIZE };
- allowMove = false;
- }
- if (IsKeyPressed(KEY_DOWN) && (snake[0].speed.y == 0) && allowMove)
- {
- snake[0].speed = (Vector2){ 0, SQUARE_SIZE };
- allowMove = false;
- }
-
- // movement
- for (int i = 0; i < counterTail; i++) snakePosition[i] = snake[i].position;
-
- if ((framesCounter%5) == 0)
- {
- for (int i = 0; i < counterTail; i++)
- {
- if (i == 0)
- {
- snake[0].position.x += snake[0].speed.x;
- snake[0].position.y += snake[0].speed.y;
- allowMove = true;
- }
- else snake[i].position = snakePosition[i-1];
- }
- }
-
- // 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))
- {
- gameOver = true;
- }
-
- // 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;
- }
-
- // TODO: review logic: fruit.position calculation
- if (!fruit.active)
- {
- fruit.active = true;
- 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++)
- {
- while ((fruit.position.x == snake[i].position.x) && (fruit.position.y == snake[i].position.y))
- {
- fruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE };
- i = 0;
- }
- }
- }
-
- // collision
- if (CheckCollisionRecs((Rectangle){(int)snake[0].position.x, (int)snake[0].position.y, (int)snake[0].size.x, (int)snake[0].size.y},
- (Rectangle){(int)fruit.position.x, (int)fruit.position.y, (int)fruit.size.x, (int)fruit.size.y}))
- {
- snake[counterTail].position = snakePosition[counterTail - 1];
- counterTail += 1;
- fruit.active = false;
- }
-
- framesCounter++;
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw grid lines
- for (int i = 0; i < screenWidth/SQUARE_SIZE + 1; i++)
- {
- DrawLineV((Vector2){SQUARE_SIZE*i + offset.x/2, offset.y/2}, (Vector2){SQUARE_SIZE*i + offset.x/2, screenHeight - offset.y/2}, LIGHTGRAY);
- }
-
- for (int i = 0; i < screenHeight/SQUARE_SIZE + 1; i++)
- {
- DrawLineV((Vector2){offset.x/2, SQUARE_SIZE*i + offset.y/2}, (Vector2){screenWidth - offset.x/2, SQUARE_SIZE*i + offset.y/2}, LIGHTGRAY);
- }
-
- // Draw snake
- for (int i = 0; i < counterTail; i++) DrawRectangleV(snake[i].position, snake[i].size, snake[i].color);
-
- // Draw fruit to pick
- DrawRectangleV(fruit.position, fruit.size, fruit.color);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-} \ No newline at end of file
diff --git a/games/samples/space_invaders.c b/games/samples/space_invaders.c
deleted file mode 100644
index c2dd0c61..00000000
--- a/games/samples/space_invaders.c
+++ /dev/null
@@ -1,406 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: space invaders
-*
-* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define NUM_SHOOTS 50
-#define NUM_MAX_ENEMIES 50
-#define FIRST_WAVE 10
-#define SECOND_WAVE 20
-#define THIRD_WAVE 50
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef enum { FIRST = 0, SECOND, THIRD } EnemyWave;
-
-typedef struct Player{
- Rectangle rec;
- Vector2 speed;
- Color color;
-} Player;
-
-typedef struct Enemy{
- Rectangle rec;
- Vector2 speed;
- bool active;
- Color color;
-} Enemy;
-
-typedef struct Shoot{
- Rectangle rec;
- Vector2 speed;
- bool active;
- Color color;
-} Shoot;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static int framesCounter;
-static bool gameOver;
-static bool pause;
-static int score;
-static bool victory;
-
-static Player player;
-static Enemy enemy[NUM_MAX_ENEMIES];
-static Shoot shoot[NUM_SHOOTS];
-static EnemyWave wave;
-
-static int shootRate;
-static float alpha;
-
-static int activeEnemies;
-static int enemiesKill;
-static bool smooth;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: space invaders");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//------------------------------------------------------------------------------------
-// Module Functions Definitions (local)
-//------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- // Initialize game variables
- shootRate = 0;
- pause = false;
- gameOver = false;
- victory = false;
- smooth = false;
- wave = FIRST;
- activeEnemies = FIRST_WAVE;
- enemiesKill = 0;
- score = 0;
- alpha = 0;
-
- // Initialize player
- player.rec.x = 20;
- player.rec.y = 50;
- player.rec.width = 20;
- player.rec.height = 20;
- player.speed.x = 5;
- player.speed.y = 5;
- player.color = BLACK;
-
- // Initialize enemies
- for (int i = 0; i < NUM_MAX_ENEMIES; i++)
- {
- enemy[i].rec.width = 10;
- enemy[i].rec.height = 10;
- enemy[i].rec.x = GetRandomValue(screenWidth, screenWidth + 1000);
- enemy[i].rec.y = GetRandomValue(0, screenHeight - enemy[i].rec.height);
- enemy[i].speed.x = 5;
- enemy[i].speed.y = 5;
- enemy[i].active = true;
- enemy[i].color = GRAY;
- }
-
- // Initialize shoots
- for (int i = 0; i < NUM_SHOOTS; i++)
- {
- shoot[i].rec.x = player.rec.x;
- shoot[i].rec.y = player.rec.y + player.rec.height/4;
- shoot[i].rec.width = 10;
- shoot[i].rec.height = 5;
- shoot[i].speed.x = 7;
- shoot[i].speed.y = 0;
- shoot[i].active = false;
- shoot[i].color = MAROON;
- }
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- switch (wave)
- {
- case FIRST:
- {
- if (!smooth)
- {
- alpha += 0.02f;
-
- if (alpha >= 1.0f) smooth = true;
- }
-
- if (smooth) alpha -= 0.02f;
-
- if (enemiesKill == activeEnemies)
- {
- enemiesKill = 0;
-
- for (int i = 0; i < activeEnemies; i++)
- {
- if (!enemy[i].active) enemy[i].active = true;
- }
-
- activeEnemies = SECOND_WAVE;
- wave = SECOND;
- smooth = false;
- alpha = 0.0f;
- }
- } break;
- case SECOND:
- {
- if (!smooth)
- {
- alpha += 0.02f;
-
- if (alpha >= 1.0f) smooth = true;
- }
-
- if (smooth) alpha -= 0.02f;
-
- if (enemiesKill == activeEnemies)
- {
- enemiesKill = 0;
-
- for (int i = 0; i < activeEnemies; i++)
- {
- if (!enemy[i].active) enemy[i].active = true;
- }
-
- activeEnemies = THIRD_WAVE;
- wave = THIRD;
- smooth = false;
- alpha = 0.0f;
- }
- } break;
- case THIRD:
- {
- if (!smooth)
- {
- alpha += 0.02f;
-
- if (alpha >= 1.0f) smooth = true;
- }
-
- if (smooth) alpha -= 0.02f;
-
- if (enemiesKill == activeEnemies) victory = true;
-
- } break;
- default: break;
- }
-
- // Player movement
- if (IsKeyDown(KEY_RIGHT)) player.rec.x += player.speed.x;
- if (IsKeyDown(KEY_LEFT)) player.rec.x -= player.speed.x;
- if (IsKeyDown(KEY_UP)) player.rec.y -= player.speed.y;
- if (IsKeyDown(KEY_DOWN)) player.rec.y += player.speed.y;
-
- // Player collision with enemy
- for (int i = 0; i < activeEnemies; i++)
- {
- if (CheckCollisionRecs(player.rec, enemy[i].rec)) gameOver = true;
- }
-
- // Enemy behaviour
- for (int i = 0; i < activeEnemies; i++)
- {
- if (enemy[i].active)
- {
- enemy[i].rec.x -= enemy[i].speed.x;
-
- if (enemy[i].rec.x < 0)
- {
- enemy[i].rec.x = GetRandomValue(screenWidth, screenWidth + 1000);
- enemy[i].rec.y = GetRandomValue(0, screenHeight - enemy[i].rec.height);
- }
- }
- }
-
- // Wall behaviour
- if (player.rec.x <= 0) player.rec.x = 0;
- if (player.rec.x + player.rec.width >= screenWidth) player.rec.x = screenWidth - player.rec.width;
- if (player.rec.y <= 0) player.rec.y = 0;
- if (player.rec.y + player.rec.height >= screenHeight) player.rec.y = screenHeight - player.rec.height;
-
- //Shoot initialization
- if (IsKeyDown(KEY_SPACE))
- {
- shootRate += 5;
-
- for (int i = 0; i < NUM_SHOOTS; i++)
- {
- if (!shoot[i].active && shootRate%20 == 0)
- {
- shoot[i].rec.x = player.rec.x;
- shoot[i].rec.y = player.rec.y + player.rec.height/4;
- shoot[i].active = true;
- break;
- }
- }
- }
-
- // Shoot logic
- for (int i = 0; i < NUM_SHOOTS; i++)
- {
- if (shoot[i].active)
- {
- // Movement
- shoot[i].rec.x += shoot[i].speed.x;
-
- // Collision with enemy
- for (int j = 0; j < activeEnemies; j++)
- {
- if (enemy[j].active)
- {
- if (CheckCollisionRecs(shoot[i].rec, enemy[j].rec))
- {
- shoot[i].active = false;
- enemy[j].rec.x = GetRandomValue(screenWidth, screenWidth + 1000);
- enemy[j].rec.y = GetRandomValue(0, screenHeight - enemy[j].rec.height);
- shootRate = 0;
- enemiesKill++;
- score += 100;
- }
-
- if (shoot[i].rec.x + shoot[i].rec.width >= screenWidth)
- {
- shoot[i].active = false;
- shootRate = 0;
- }
- }
- }
- }
- }
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- DrawRectangleRec(player.rec, player.color);
-
- if (wave == FIRST) DrawText("FIRST WAVE", screenWidth/2 - MeasureText("FIRST WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha));
- else if (wave == SECOND) DrawText("SECOND WAVE", screenWidth/2 - MeasureText("SECOND WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha));
- else if (wave == THIRD) DrawText("THIRD WAVE", screenWidth/2 - MeasureText("THIRD WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha));
-
- for (int i = 0; i < activeEnemies; i++)
- {
- if (enemy[i].active) DrawRectangleRec(enemy[i].rec, enemy[i].color);
- }
-
- for (int i = 0; i < NUM_SHOOTS; i++)
- {
- if (shoot[i].active) DrawRectangleRec(shoot[i].rec, shoot[i].color);
- }
-
- DrawText(FormatText("%04i", score), 20, 20, 40, GRAY);
-
- if (victory) DrawText("YOU WIN", screenWidth/2 - MeasureText("YOU WIN", 40)/2, screenHeight/2 - 40, 40, BLACK);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-} \ No newline at end of file
diff --git a/games/samples/tetris.c b/games/samples/tetris.c
deleted file mode 100644
index 62400201..00000000
--- a/games/samples/tetris.c
+++ /dev/null
@@ -1,836 +0,0 @@
-/*******************************************************************************************
-*
-* raylib - sample game: tetris
-*
-* Sample game Marc Palau and Ramon Santamaria
-*
-* This game has been created using raylib v1.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2015 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <math.h>
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Some Defines
-//----------------------------------------------------------------------------------
-#define SQUARE_SIZE 20
-
-#define GRID_HORIZONTAL_SIZE 12
-#define GRID_VERTICAL_SIZE 20
-
-#define LATERAL_SPEED 10
-#define TURNING_SPEED 12
-#define FAST_FALL_AWAIT_COUNTER 30
-
-#define FADING_TIME 33
-
-//----------------------------------------------------------------------------------
-// Types and Structures Definition
-//----------------------------------------------------------------------------------
-typedef enum GridSquare { EMPTY, MOVING, FULL, BLOCK, FADING } GridSquare;
-
-//------------------------------------------------------------------------------------
-// Global Variables Declaration
-//------------------------------------------------------------------------------------
-static int screenWidth = 800;
-static int screenHeight = 450;
-
-static bool gameOver = false;
-static bool pause = false;
-
-// Matrices
-static GridSquare grid [GRID_HORIZONTAL_SIZE][GRID_VERTICAL_SIZE];
-static GridSquare piece [4][4];
-static GridSquare incomingPiece [4][4];
-
-// Theese variables keep track of the active piece position
-static int piecePositionX = 0;
-static int piecePositionY = 0;
-
-// Game parameters
-static Color fadingColor;
-//static int fallingSpeed; // In frames
-
-static bool beginPlay = true; // This var is only true at the begining of the game, used for the first matrix creations
-static bool pieceActive = false;
-static bool detection = false;
-static bool lineToDelete = false;
-
-// Statistics
-static int level = 1;
-static int lines = 0;
-
-// Counters
-static int gravityMovementCounter = 0;
-static int lateralMovementCounter = 0;
-static int turnMovementCounter = 0;
-static int fastFallMovementCounter = 0;
-
-static int fadeLineCounter = 0;
-
-// Based on level
-static int gravitySpeed = 30;
-
-//------------------------------------------------------------------------------------
-// Module Functions Declaration (local)
-//------------------------------------------------------------------------------------
-static void InitGame(void); // Initialize game
-static void UpdateGame(void); // Update game (one frame)
-static void DrawGame(void); // Draw game (one frame)
-static void UnloadGame(void); // Unload game
-static void UpdateDrawFrame(void); // Update and Draw (one frame)
-
-// Additional module functions
-static bool Createpiece();
-static void GetRandompiece();
-static void ResolveFallingMovement();
-static bool ResolveLateralMovement();
-static bool ResolveTurnMovement();
-static void CheckDetection();
-static void CheckCompletition();
-static void DeleteCompleteLines();
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "sample game: tetris");
-
- InitGame();
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
-#else
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- UpdateGame();
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- DrawGame();
- //----------------------------------------------------------------------------------
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadGame(); // Unload loaded data (textures, sounds, models...)
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//--------------------------------------------------------------------------------------
-// Game Module Functions Definition
-//--------------------------------------------------------------------------------------
-
-// Initialize game variables
-void InitGame(void)
-{
- // Initialize game statistics
- level = 1;
- lines = 0;
-
- fadingColor = GRAY;
-
- piecePositionX = 0;
- piecePositionY = 0;
-
- pause = false;
-
- beginPlay = true;
- pieceActive = false;
- detection = false;
- lineToDelete = false;
-
- // Counters
- gravityMovementCounter = 0;
- lateralMovementCounter = 0;
- turnMovementCounter = 0;
- fastFallMovementCounter = 0;
-
- fadeLineCounter = 0;
- gravitySpeed = 30;
-
- // Initialize grid matrices
- for (int i = 0; i < GRID_HORIZONTAL_SIZE; i++)
- {
- for (int j = 0; j < GRID_VERTICAL_SIZE; j++)
- {
- if ((j == GRID_VERTICAL_SIZE - 1) || (i == 0) || (i == GRID_HORIZONTAL_SIZE - 1)) grid[i][j] = BLOCK;
- else grid[i][j] = EMPTY;
- }
- }
-
- // Initialize incoming piece matrices
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j< 4; j++)
- {
- incomingPiece[i][j] = EMPTY;
- }
- }
-}
-
-// Update game (one frame)
-void UpdateGame(void)
-{
- if (!gameOver)
- {
- if (IsKeyPressed('P')) pause = !pause;
-
- if (!pause)
- {
- if (!lineToDelete)
- {
- if (!pieceActive)
- {
- // Get another piece
- pieceActive = Createpiece();
-
- // We leave a little time before starting the fast falling down
- fastFallMovementCounter = 0;
- }
- else // Piece falling
- {
- // Counters update
- fastFallMovementCounter++;
- gravityMovementCounter++;
- lateralMovementCounter++;
- turnMovementCounter++;
-
- // We make sure to move if we've pressed the key this frame
- if (IsKeyPressed(KEY_LEFT) || IsKeyPressed(KEY_RIGHT)) lateralMovementCounter = LATERAL_SPEED;
- if (IsKeyPressed(KEY_UP)) turnMovementCounter = TURNING_SPEED;
-
- // Fall down
- if (IsKeyDown(KEY_DOWN) && (fastFallMovementCounter >= FAST_FALL_AWAIT_COUNTER))
- {
- // We make sure the piece is going to fall this frame
- gravityMovementCounter += gravitySpeed;
- }
-
- if (gravityMovementCounter >= gravitySpeed)
- {
- // Basic falling movement
- CheckDetection(&detection);
-
- // Check if the piece has collided with another piece or with the boundings
- ResolveFallingMovement(&detection, &pieceActive);
-
- // Check if we fullfilled a line and if so, erase the line and pull down the the lines above
- CheckCompletition(&lineToDelete);
-
- gravityMovementCounter = 0;
- }
-
- // Move laterally at player's will
- if (lateralMovementCounter >= LATERAL_SPEED)
- {
- // Update the lateral movement and if success, reset the lateral counter
- if (!ResolveLateralMovement()) lateralMovementCounter = 0;
- }
-
- // Turn the piece at player's will
- if (turnMovementCounter >= TURNING_SPEED)
- {
- // Update the turning movement and reset the turning counter
- if (ResolveTurnMovement()) turnMovementCounter = 0;
- }
- }
-
- // Game over logic
- for (int j = 0; j < 2; j++)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- if (grid[i][j] == FULL)
- {
- gameOver = true;
- }
- }
- }
- }
- else
- {
- // Animation when deleting lines
- fadeLineCounter++;
-
- if (fadeLineCounter%8 < 4) fadingColor = MAROON;
- else fadingColor = GRAY;
-
- if (fadeLineCounter >= FADING_TIME)
- {
- DeleteCompleteLines();
- fadeLineCounter = 0;
- lineToDelete = false;
-
- lines++;
- }
- }
- }
- }
- else
- {
- if (IsKeyPressed(KEY_ENTER))
- {
- InitGame();
- gameOver = false;
- }
- }
-}
-
-// Draw game (one frame)
-void DrawGame(void)
-{
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- if (!gameOver)
- {
- // Draw gameplay area
- Vector2 offset;
- offset.x = screenWidth/2 - (GRID_HORIZONTAL_SIZE*SQUARE_SIZE/2) - 50;
- offset.y = screenHeight/2 - ((GRID_VERTICAL_SIZE - 1)*SQUARE_SIZE/2) + SQUARE_SIZE*2;
-
- offset.y -= 50; // NOTE: Harcoded position!
-
- int controller = offset.x;
-
- for (int j = 0; j < GRID_VERTICAL_SIZE; j++)
- {
- for (int i = 0; i < GRID_HORIZONTAL_SIZE; i++)
- {
- // Draw each square of the grid
- if (grid[i][j] == EMPTY)
- {
- DrawLine(offset.x, offset.y, offset.x + SQUARE_SIZE, offset.y, LIGHTGRAY );
- DrawLine(offset.x, offset.y, offset.x, offset.y + SQUARE_SIZE, LIGHTGRAY );
- DrawLine(offset.x + SQUARE_SIZE, offset.y, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY );
- DrawLine(offset.x, offset.y + SQUARE_SIZE, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY );
- offset.x += SQUARE_SIZE;
- }
- else if (grid[i][j] == FULL)
- {
- DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, GRAY);
- offset.x += SQUARE_SIZE;
- }
- else if (grid[i][j] == MOVING)
- {
- DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, DARKGRAY);
- offset.x += SQUARE_SIZE;
- }
- else if (grid[i][j] == BLOCK)
- {
- DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, LIGHTGRAY);
- offset.x += SQUARE_SIZE;
- }
- else if (grid[i][j] == FADING)
- {
- DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, fadingColor);
- offset.x += SQUARE_SIZE;
- }
- }
-
- offset.x = controller;
- offset.y += SQUARE_SIZE;
- }
-
- // Draw incoming piece (hardcoded)
- offset.x = 500;
- offset.y = 45;
-
- int controler = offset.x;
-
- for (int j = 0; j < 4; j++)
- {
- for (int i = 0; i < 4; i++)
- {
- if (incomingPiece[i][j] == EMPTY)
- {
- DrawLine(offset.x, offset.y, offset.x + SQUARE_SIZE, offset.y, LIGHTGRAY );
- DrawLine(offset.x, offset.y, offset.x, offset.y + SQUARE_SIZE, LIGHTGRAY );
- DrawLine(offset.x + SQUARE_SIZE, offset.y, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY );
- DrawLine(offset.x, offset.y + SQUARE_SIZE, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY );
- offset.x += SQUARE_SIZE;
- }
- else if (incomingPiece[i][j] == MOVING)
- {
- DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, GRAY);
- offset.x += SQUARE_SIZE;
- }
- }
-
- offset.x = controler;
- offset.y += SQUARE_SIZE;
- }
-
- DrawText("INCOMING:", offset.x, offset.y - 100, 10, GRAY);
- DrawText(FormatText("LINES: %04i", lines), offset.x, offset.y + 20, 10, GRAY);
-
- if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
- }
- else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
-
- EndDrawing();
-}
-
-// Unload game variables
-void UnloadGame(void)
-{
- // TODO: Unload all dynamic loaded data (textures, sounds, models...)
-}
-
-// Update and Draw (one frame)
-void UpdateDrawFrame(void)
-{
- UpdateGame();
- DrawGame();
-}
-
-//--------------------------------------------------------------------------------------
-// Additional module functions
-//--------------------------------------------------------------------------------------
-static bool Createpiece()
-{
- piecePositionX = (int)((GRID_HORIZONTAL_SIZE - 4)/2);
- piecePositionY = 0;
-
- // If the game is starting and you are going to create the first piece, we create an extra one
- if (beginPlay)
- {
- GetRandompiece();
- beginPlay = false;
- }
-
- // We assign the incoming piece to the actual piece
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j< 4; j++)
- {
- piece[i][j] = incomingPiece[i][j];
- }
- }
-
- // We assign a random piece to the incoming one
- GetRandompiece();
-
- // Assign the piece to the grid
- for (int i = piecePositionX; i < piecePositionX + 4; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- if (piece[i - (int)piecePositionX][j] == MOVING) grid[i][j] = MOVING;
- }
- }
-
- return true;
-}
-
-static void GetRandompiece()
-{
- srand(time(NULL));
- int random = rand() % 7;
-
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- incomingPiece[i][j] = EMPTY;
- }
- }
-
- switch(random)
- {
- case 0: { incomingPiece[1][1] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[1][2] = MOVING; incomingPiece[2][2] = MOVING; } break; //Cube
- case 1: { incomingPiece[1][0] = MOVING; incomingPiece[1][1] = MOVING; incomingPiece[1][2] = MOVING; incomingPiece[2][2] = MOVING; } break; //L
- case 2: { incomingPiece[1][2] = MOVING; incomingPiece[2][0] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[2][2] = MOVING; } break; //L inversa
- case 3: { incomingPiece[0][1] = MOVING; incomingPiece[1][1] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[3][1] = MOVING; } break; //Recta
- case 4: { incomingPiece[1][0] = MOVING; incomingPiece[1][1] = MOVING; incomingPiece[1][2] = MOVING; incomingPiece[2][1] = MOVING; } break; //Creu tallada
- case 5: { incomingPiece[1][1] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[2][2] = MOVING; incomingPiece[3][2] = MOVING; } break; //S
- case 6: { incomingPiece[1][2] = MOVING; incomingPiece[2][2] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[3][1] = MOVING; } break; //S inversa
- }
-}
-
-static void ResolveFallingMovement(bool *detection, bool *pieceActive)
-{
- // If we finished moving this piece, we stop it
- if (*detection)
- {
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- if (grid[i][j] == MOVING)
- {
- grid[i][j] = FULL;
- *detection = false;
- *pieceActive = false;
- }
- }
- }
- }
- // We move down the piece
- else
- {
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- if (grid[i][j] == MOVING)
- {
- grid[i][j+1] = MOVING;
- grid[i][j] = EMPTY;
- }
- }
- }
- piecePositionY++;
- }
-}
-
-static bool ResolveLateralMovement()
-{
- bool collision = false;
-
- // Move left
- if (IsKeyDown(KEY_LEFT))
- {
- // Check if is possible to move to left
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- if (grid[i][j] == MOVING)
- {
- // Check if we are touching the left wall or we have a full square at the left
- if ((i-1 == 0) || (grid[i-1][j] == FULL)) collision = true;
- }
- }
- }
- // If able, move left
- if (!collision)
- {
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) // We check the matrix from left to right
- {
- // Move everything to the left
- if (grid[i][j] == MOVING)
- {
- grid[i-1][j] = MOVING;
- grid[i][j] = EMPTY;
- }
- }
- }
-
- piecePositionX--;
- }
- }
-
- // Move right
- else if (IsKeyDown(KEY_RIGHT))
- {
- // Check if is possible to move to right
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- if (grid[i][j] == MOVING)
- {
- // Check if we are touching the right wall or we have a full square at the right
- if ((i+1 == GRID_HORIZONTAL_SIZE - 1) || (grid[i+1][j] == FULL))
- {
- collision = true;
-
- }
- }
- }
- }
- // If able move right
- if (!collision)
- {
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = GRID_HORIZONTAL_SIZE - 1; i >= 1; i--) // We check the matrix from right to left
- {
- // Move everything to the right
- if (grid[i][j] == MOVING)
- {
- grid[i+1][j] = MOVING;
- grid[i][j] = EMPTY;
- }
- }
- }
-
- piecePositionX++;
- }
- }
-
- return collision;
-}
-
-static bool ResolveTurnMovement()
-{
- // Input for turning the piece
- if (IsKeyDown(KEY_UP))
- {
- int aux;
- bool checker = false;
-
- // Check all turning possibilities
- if ((grid[piecePositionX + 3][piecePositionY] == MOVING) &&
- (grid[piecePositionX][piecePositionY] != EMPTY) &&
- (grid[piecePositionX][piecePositionY] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX + 3][piecePositionY + 3] == MOVING) &&
- (grid[piecePositionX + 3][piecePositionY] != EMPTY) &&
- (grid[piecePositionX + 3][piecePositionY] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX][piecePositionY + 3] == MOVING) &&
- (grid[piecePositionX + 3][piecePositionY + 3] != EMPTY) &&
- (grid[piecePositionX + 3][piecePositionY + 3] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX][piecePositionY] == MOVING) &&
- (grid[piecePositionX][piecePositionY + 3] != EMPTY) &&
- (grid[piecePositionX][piecePositionY + 3] != MOVING))
- {
- checker = true;
- }
-
-
- if ((grid[piecePositionX + 1][piecePositionY] == MOVING) &&
- (grid[piecePositionX][piecePositionY + 2] != EMPTY) &&
- (grid[piecePositionX][piecePositionY + 2] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX + 3][piecePositionY + 1] == MOVING) &&
- (grid[piecePositionX + 1][piecePositionY] != EMPTY) &&
- (grid[piecePositionX + 1][piecePositionY] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX + 2][piecePositionY + 3] == MOVING) &&
- (grid[piecePositionX + 3][piecePositionY + 1] != EMPTY) &&
- (grid[piecePositionX + 3][piecePositionY + 1] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX][piecePositionY + 2] == MOVING) &&
- (grid[piecePositionX + 2][piecePositionY + 3] != EMPTY) &&
- (grid[piecePositionX + 2][piecePositionY + 3] != MOVING))
- {
- checker = true;
- }
-
-
- if ((grid[piecePositionX + 2][piecePositionY] == MOVING) &&
- (grid[piecePositionX][piecePositionY + 1] != EMPTY) &&
- (grid[piecePositionX][piecePositionY + 1] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX + 3][piecePositionY + 2] == MOVING) &&
- (grid[piecePositionX + 2][piecePositionY] != EMPTY) &&
- (grid[piecePositionX + 2][piecePositionY] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX + 1][piecePositionY + 3] == MOVING) &&
- (grid[piecePositionX + 3][piecePositionY + 2] != EMPTY) &&
- (grid[piecePositionX + 3][piecePositionY + 2] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX][piecePositionY + 1] == MOVING) &&
- (grid[piecePositionX + 1][piecePositionY + 3] != EMPTY) &&
- (grid[piecePositionX + 1][piecePositionY + 3] != MOVING))
- {
- checker = true;
- }
-
- if ((grid[piecePositionX + 1][piecePositionY + 1] == MOVING) &&
- (grid[piecePositionX + 1][piecePositionY + 2] != EMPTY) &&
- (grid[piecePositionX + 1][piecePositionY + 2] != MOVING))
- {
- checker = true;
- }
-
- if ((grid[piecePositionX + 2][piecePositionY + 1] == MOVING) &&
- (grid[piecePositionX + 1][piecePositionY + 1] != EMPTY) &&
- (grid[piecePositionX + 1][piecePositionY + 1] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX + 2][piecePositionY + 2] == MOVING) &&
- (grid[piecePositionX + 2][piecePositionY + 1] != EMPTY) &&
- (grid[piecePositionX + 2][piecePositionY + 1] != MOVING))
- {
- checker = true;
- }
- if ((grid[piecePositionX + 1][piecePositionY + 2] == MOVING) &&
- (grid[piecePositionX + 2][piecePositionY + 2] != EMPTY) &&
- (grid[piecePositionX + 2][piecePositionY + 2] != MOVING))
- {
- checker = true;
- }
-
- if (!checker)
- {
- aux = piece[0][0];
- piece[0][0] = piece[3][0];
- piece[3][0] = piece[3][3];
- piece[3][3] = piece[0][3];
- piece[0][3] = aux;
-
- aux = piece[1][0];
- piece[1][0] = piece[3][1];
- piece[3][1] = piece[2][3];
- piece[2][3] = piece[0][2];
- piece[0][2] = aux;
-
- aux = piece[2][0];
- piece[2][0] = piece[3][2];
- piece[3][2] = piece[1][3];
- piece[1][3] = piece[0][1];
- piece[0][1] = aux;
-
- aux = piece[1][1];
- piece[1][1] = piece[2][1];
- piece[2][1] = piece[2][2];
- piece[2][2] = piece[1][2];
- piece[1][2] = aux;
- }
-
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- if (grid[i][j] == MOVING)
- {
- grid[i][j] = EMPTY;
- }
- }
- }
-
- for (int i = piecePositionX; i < piecePositionX + 4; i++)
- {
- for (int j = piecePositionY; j < piecePositionY + 4; j++)
- {
- if (piece[i - piecePositionX][j - piecePositionY] == MOVING)
- {
- grid[i][j] = MOVING;
- }
- }
- }
- return true;
- }
-
- return false;
-}
-
-static void CheckDetection(bool *detection)
-{
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- if ((grid[i][j] == MOVING) && ((grid[i][j+1] == FULL) || (grid[i][j+1] == BLOCK))) *detection = true;
- }
- }
-}
-
-static void CheckCompletition(bool *lineToDelete)
-{
- int calculator;
-
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- calculator = 0;
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- // Count each square of the line
- if (grid[i][j] == FULL)
- {
- calculator++;
- }
-
- // Check if we completed the whole line
- if (calculator == GRID_HORIZONTAL_SIZE - 2)
- {
- *lineToDelete = true;
- calculator = 0;
- // points++;
-
- // Mark the completed line
- for (int z = 1; z < GRID_HORIZONTAL_SIZE - 1; z++)
- {
- grid[z][j] = FADING;
- }
- }
- }
- }
-}
-
-static void DeleteCompleteLines()
-{
- // erase the completed line
- for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
- {
- while (grid[1][j] == FADING)
- {
- for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
- {
- grid[i][j] = EMPTY;
- }
- for (int j2 = j-1; j2 >= 0; j2--)
- {
- for (int i2 = 1; i2 < GRID_HORIZONTAL_SIZE - 1; i2++)
- {
- if (grid[i2][j2] == FULL)
- {
- grid[i2][j2+1] = FULL;
- grid[i2][j2] = EMPTY;
- }
- else if (grid[i2][j2] == FADING)
- {
- grid[i2][j2+1] = FADING;
- grid[i2][j2] = EMPTY;
- }
- }
- }
- }
- }
-} \ No newline at end of file