added health pickups and multiple source files
This commit is contained in:
parent
fb39864584
commit
2e3d37385b
13 changed files with 461 additions and 283 deletions
6
Makefile
6
Makefile
|
@ -1,8 +1,8 @@
|
||||||
clang :
|
clang :
|
||||||
clang src/Main.c -std=c99 -Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o Avoid
|
clang src/Main.c src/Title.c src/Credits.c src/Gameover.c src/Gameplay.c -std=c99 -Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o Avoid
|
||||||
|
|
||||||
tcc :
|
tcc :
|
||||||
tcc src/Main.c -std=c99 -Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o Avoid
|
tcc src/Main.c src/Title.c src/Credits.c src/Gameover.c src/Gameplay.c -std=c99 -Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o Avoid
|
||||||
|
|
||||||
gcc :
|
gcc :
|
||||||
gcc src/Main.c -std=c99 -Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o Avoid
|
gcc src/Main.c src/Title.c src/Credits.c src/Gameover.c src/Gameplay.c -std=c99 -Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o Avoid
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
{"modelVersion":2,"piskel":{"name":"Health","description":"","fps":12,"height":40,"width":40,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":1,\"chunks\":[{\"layout\":[[0]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAbUlEQVRYhe3WMQ7AIAhAUY/g8XtUNjvZuGAgjSjx/8QNwhsthYiIKLI2ed55becC4FPr9yzAcd6wcxlQOarOhQFFpIlIHuB4WIMBtAIAroJGwNIAXdAdsDTAKfQEWO94YG/5d+pvxwOJiIjI1wsK5HWucm45QwAAAABJRU5ErkJggg==\"}]}"],"hiddenFrames":[""]}}
|
|
1
asset-src/gfx/heart.piskel
Normal file
1
asset-src/gfx/heart.piskel
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"modelVersion":2,"piskel":{"name":"Health","description":"","fps":12,"height":32,"width":32,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":1,\"chunks\":[{\"layout\":[[0]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAZ0lEQVRYhe3OQQ4AIQgDQJ/g830qNz3rbhZEyDamTXqkTCkMwzDPdKXpOxiAVutrDQOn9+CAjyHvnQ4QETzAOqg9vhewWxcgsgQQYAGkQHYewwBCICePYQAuSORjGMAEMTQtvwPuygADDK9XgRU+4gAAAABJRU5ErkJggg==\"}]}"],"hiddenFrames":[""]}}
|
Binary file not shown.
Before Width: | Height: | Size: 168 B After Width: | Height: | Size: 174 B |
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
emcc -o html5/index.html src/Main.c -Os -Wall /usr/local/lib/libraylib.a -I. -I/usr/local/include/raylib.h -L. -L/usr/local/lib/libraylib.a -s USE_GLFW=3 -DPLATFORM_WEB --preload-file ./assets --shell-file html5/shell.html
|
emcc -o html5/index.html src/Main.c src/Title.c src/Credits.c src/Gameover.c src/Gameplay.c -Os -Wall /usr/local/lib/libraylib.a -I. -I/usr/local/include/raylib.h -L. -L/usr/local/lib/libraylib.a -s USE_GLFW=3 -DPLATFORM_WEB --preload-file ./assets --shell-file html5/shell.html
|
||||||
|
|
32
src/Credits.c
Normal file
32
src/Credits.c
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Credits.c
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../include/raylib.h"
|
||||||
|
|
||||||
|
#include "Screens.h"
|
||||||
|
#include "Controls.h"
|
||||||
|
|
||||||
|
void UpdateCreditsScreen(void)
|
||||||
|
{
|
||||||
|
if (INPUT_OPTION_PRESSED) currentScreen = TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawCreditsScreen(void)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GREEN);
|
||||||
|
|
||||||
|
DrawText("Avoid", 330, 20, 50, MAGENTA);
|
||||||
|
|
||||||
|
DrawText("Programming and Art by Return0ne", 10, 210, 20, BLUE);
|
||||||
|
|
||||||
|
DrawText("Powered by raylib 4.0", 10, 240, 20, BLUE);
|
||||||
|
|
||||||
|
DrawText("A Canneddonuts project 2022", 10, 270, 40, RED);
|
||||||
|
|
||||||
|
DrawText("Press 'ENTER' ", 10, 350, 20, WHITE);
|
||||||
|
}
|
44
src/Gameover.c
Normal file
44
src/Gameover.c
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Gameover.c
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../include/raylib.h"
|
||||||
|
|
||||||
|
#include "Screens.h"
|
||||||
|
#include "Controls.h"
|
||||||
|
|
||||||
|
int gameoverSelected = 0;
|
||||||
|
|
||||||
|
void InitGameoverScreen(void)
|
||||||
|
{
|
||||||
|
gameoverSelected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateGameoverScreen(void)
|
||||||
|
{
|
||||||
|
if (INPUT_UP_PRESSED) gameoverSelected++;
|
||||||
|
if (INPUT_DOWN_PRESSED) gameoverSelected--;
|
||||||
|
if (gameoverSelected > 0) gameoverSelected--;
|
||||||
|
if (gameoverSelected < -1) gameoverSelected++;
|
||||||
|
|
||||||
|
if ((gameoverSelected == 0) && (INPUT_OPTION_PRESSED))
|
||||||
|
currentScreen = GAMEPLAY;
|
||||||
|
|
||||||
|
if ((gameoverSelected == -1) && (INPUT_OPTION_PRESSED))
|
||||||
|
currentScreen = TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawGameoverScreen(void)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE);
|
||||||
|
DrawText("GAMEOVER", 250, 20, 50, RED);
|
||||||
|
if (gameoverSelected == 0) DrawText("RETRY", 350, 200, 20, WHITE);
|
||||||
|
else DrawText("RETRY", 350, 200, 20, RED);
|
||||||
|
|
||||||
|
if (gameoverSelected == -1) DrawText("TITLE", 352, 230, 20, WHITE);
|
||||||
|
else DrawText("TITLE", 352, 230, 20, RED);
|
||||||
|
}
|
219
src/Gameplay.c
Normal file
219
src/Gameplay.c
Normal file
|
@ -0,0 +1,219 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Gameplay.c
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../include/raylib.h"
|
||||||
|
|
||||||
|
#include "Screens.h"
|
||||||
|
#include "Controls.h"
|
||||||
|
#include "Gameplay.h"
|
||||||
|
#include "Score.h"
|
||||||
|
|
||||||
|
int score = 0, bestscore = 0;
|
||||||
|
|
||||||
|
void InitGameplayScreen(void)
|
||||||
|
{
|
||||||
|
fxbounce = LoadSound("assets/sfx/boing.wav");
|
||||||
|
|
||||||
|
SetMasterVolume(0.2);
|
||||||
|
|
||||||
|
player.sprite = LoadTexture("assets/gfx/player.png");
|
||||||
|
player.currentframe = 0;
|
||||||
|
player.speed = 300.0f;
|
||||||
|
player.hp = 30;
|
||||||
|
player.frameRec = (Rectangle) {
|
||||||
|
player.hitbox.x,
|
||||||
|
player.hitbox.y,
|
||||||
|
(float) player.sprite.width/3,
|
||||||
|
(float) player.sprite.height
|
||||||
|
};
|
||||||
|
player.hitbox = (Rectangle) {
|
||||||
|
GetScreenWidth()/2.0f - 30,
|
||||||
|
GetScreenHeight()/2.0f - 30,
|
||||||
|
(float) player.sprite.width/3,
|
||||||
|
(float) player.sprite.height
|
||||||
|
};
|
||||||
|
|
||||||
|
heart.sprite = LoadTexture("assets/gfx/health.png");
|
||||||
|
heart.hitbox = (Rectangle) {
|
||||||
|
GetRandomValue(0, GetScreenWidth() - heart.sprite.width),
|
||||||
|
GetRandomValue(0, GetScreenHeight() - heart.sprite.height),
|
||||||
|
(float) heart.sprite.width,
|
||||||
|
(float) heart.sprite.height
|
||||||
|
};
|
||||||
|
heart.active = false;
|
||||||
|
|
||||||
|
ball.position = (Vector2){ 50, 50 };
|
||||||
|
ball.speed = (Vector2){ 400.0f, 300.0f };
|
||||||
|
ball.radius = 20;
|
||||||
|
ball.growth = 2;
|
||||||
|
ball.color = MAROON;
|
||||||
|
ball.active = true;
|
||||||
|
|
||||||
|
pause = 0;
|
||||||
|
mute = 0;
|
||||||
|
DebugMode = 0;
|
||||||
|
pauseTimer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetGameplayScreen(void)
|
||||||
|
{
|
||||||
|
// code to reset all variables without reloading assets
|
||||||
|
player.currentframe = 0;
|
||||||
|
player.speed = 300.0f;
|
||||||
|
player.hp = 30;
|
||||||
|
player.hitbox = (Rectangle) {
|
||||||
|
GetScreenWidth()/2.0f - 30,
|
||||||
|
GetScreenHeight()/2.0f - 30,
|
||||||
|
(float) player.sprite.width/3,
|
||||||
|
(float) player.sprite.height
|
||||||
|
};
|
||||||
|
|
||||||
|
heart.hitbox = (Rectangle) {
|
||||||
|
GetRandomValue(0, GetScreenWidth() - heart.sprite.width),
|
||||||
|
GetRandomValue(0, GetScreenHeight() - heart.sprite.height),
|
||||||
|
(float) heart.sprite.width,
|
||||||
|
(float) heart.sprite.height
|
||||||
|
};
|
||||||
|
heart.active = false;
|
||||||
|
|
||||||
|
ball.position = (Vector2){ 50, 50 };
|
||||||
|
ball.radius = 20;
|
||||||
|
ball.active = true;
|
||||||
|
|
||||||
|
DebugMode = 0;
|
||||||
|
|
||||||
|
pauseTimer = 0;
|
||||||
|
score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateGameplayScreen(void)
|
||||||
|
{
|
||||||
|
if (IsKeyPressed(KEY_M)) mute = !mute;
|
||||||
|
|
||||||
|
if (INPUT_OPTION_PRESSED) pause = !pause;
|
||||||
|
|
||||||
|
if (!pause) {
|
||||||
|
// Controls
|
||||||
|
if (INPUT_LEFT_DOWN) player.hitbox.x -= GetFrameTime() * player.speed;
|
||||||
|
if (INPUT_RIGHT_DOWN) player.hitbox.x += GetFrameTime() * player.speed;
|
||||||
|
if (INPUT_UP_DOWN) player.hitbox.y -= GetFrameTime() * player.speed;
|
||||||
|
if (INPUT_DOWN_DOWN) player.hitbox.y += GetFrameTime() * player.speed;
|
||||||
|
if (INPUT_DASH_DOWN) {
|
||||||
|
player.speed = 600.0f;
|
||||||
|
if (player.currentframe != 1) player.currentframe = 2;
|
||||||
|
} else player.speed = 300.0f;
|
||||||
|
|
||||||
|
|
||||||
|
player.sprite_pos = (Vector2){ player.hitbox.x, player.hitbox.y };
|
||||||
|
player.frameRec.x = (float)player.currentframe*(float)player.sprite.width/3;
|
||||||
|
|
||||||
|
heart.sprite_pos = (Vector2){ heart.hitbox.x, heart.hitbox.y };
|
||||||
|
|
||||||
|
if (score == 1000) heart.active = true;
|
||||||
|
if (score == 2000) heart.active = true;
|
||||||
|
if (score == 3000) heart.active = true;
|
||||||
|
if (score == 4000) heart.active = true;
|
||||||
|
if (score == 5000) heart.active = true;
|
||||||
|
if (score == 6000) heart.active = true;
|
||||||
|
if (score == 7000) heart.active = true;
|
||||||
|
if (score == 8000) heart.active = true;
|
||||||
|
if (score == 9000) heart.active = true;
|
||||||
|
if (score == 10000) heart.active = true;
|
||||||
|
|
||||||
|
// Player to da wallz collies
|
||||||
|
if ((player.hitbox.x + player.hitbox.width) >= GetScreenWidth()) player.hitbox.x = GetScreenWidth() - player.hitbox.width;
|
||||||
|
else if (player.hitbox.x <= 0) player.hitbox.x = 0;
|
||||||
|
|
||||||
|
if ((player.hitbox.y + player.hitbox.height) >= GetScreenHeight()) player.hitbox.y = GetScreenHeight() - player.hitbox.height;
|
||||||
|
else if (player.hitbox.y <= 0) player.hitbox.y = 0;
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_B)) ball.active = !ball.active;
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_D)) DebugMode = !DebugMode;
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_R)) {
|
||||||
|
gameReset();
|
||||||
|
currentScreen = TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.hp <= 0) {
|
||||||
|
gameReset();
|
||||||
|
currentScreen = GAMEOVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heart.active) {
|
||||||
|
if (CheckCollisionRecs(player.hitbox, heart.hitbox)) {
|
||||||
|
player.hp = 30;
|
||||||
|
heart.hitbox.x = GetRandomValue(0, GetScreenWidth() - heart.sprite.width);
|
||||||
|
heart.hitbox.y = GetRandomValue(0, GetScreenHeight() - heart.sprite.height);
|
||||||
|
heart.active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ball.active) {
|
||||||
|
score++;
|
||||||
|
// movement of the ball
|
||||||
|
ball.position.x += GetFrameTime() * ball.speed.x;
|
||||||
|
ball.position.y += GetFrameTime() * ball.speed.y;
|
||||||
|
|
||||||
|
if (score >= bestscore) bestscore = score;
|
||||||
|
|
||||||
|
// Ballz to da wallz collies
|
||||||
|
if ((ball.position.x >= (GetScreenWidth() - ball.radius)) || (ball.position.x <= ball.radius)) {
|
||||||
|
ball.speed.x *= -1.0f;
|
||||||
|
if (!mute) PlaySoundMulti(fxbounce);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ball.position.y >= (GetScreenHeight() - ball.radius)) || (ball.position.y <= ball.radius)) {
|
||||||
|
ball.speed.y *= -1.0f;
|
||||||
|
if (!mute) PlaySoundMulti(fxbounce);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CheckCollisionCircleRec(ball.position, ball.radius, player.hitbox)) {
|
||||||
|
player.hp -= GetFrameTime() * 3.0f;
|
||||||
|
player.currentframe = 1;
|
||||||
|
} else player.currentframe = 0;
|
||||||
|
|
||||||
|
if (ball.radius <= 100) ball.radius += GetFrameTime() * ball.growth;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else pauseTimer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawGameplayScreen(void)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
||||||
|
DrawFPS(10, 430);
|
||||||
|
DrawText(TextFormat("HP: %i", player.hp), 10, 10, 20, RED);
|
||||||
|
DrawText(TextFormat("SCORE: %i", score), 10, 30, 20, BLUE);
|
||||||
|
if (DebugMode) {
|
||||||
|
DrawText(TextFormat("BALL SIZE: %f", ball.radius), 10, 50, 20, GREEN);
|
||||||
|
DrawText(TextFormat("BALL POS X: %f, BALL POS Y: %f", ball.position.x, ball.position.y), 10, 70, 20, GREEN);
|
||||||
|
DrawText(TextFormat("BALL SPEED X: %f, BALL SPEED Y: %f", ball.speed.x, ball.speed.y), 10, 90, 20, GREEN);
|
||||||
|
DrawRectangleRec(player.hitbox, BLUE);
|
||||||
|
DrawRectangleRec(heart.hitbox, GREEN);
|
||||||
|
}
|
||||||
|
if (ball.active) DrawCircleV(ball.position, (float)ball.radius, ball.color);
|
||||||
|
if (heart.active) DrawTexture(heart.sprite, heart.sprite_pos.x, heart.sprite_pos.y, RAYWHITE);
|
||||||
|
DrawTextureRec(player.sprite, player.frameRec, player.sprite_pos, WHITE);
|
||||||
|
if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, PURPLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnloadGameplayScreen()
|
||||||
|
{
|
||||||
|
UnloadSound(fxbounce);
|
||||||
|
UnloadTexture(player.sprite);
|
||||||
|
UnloadTexture(heart.sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gameReset(void)
|
||||||
|
{
|
||||||
|
ResetGameplayScreen();
|
||||||
|
InitGameoverScreen();
|
||||||
|
}
|
47
src/Gameplay.h
Normal file
47
src/Gameplay.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Gameplay.h
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GAMEPLAY_HEADER
|
||||||
|
#define GAMEPLAY_HEADER
|
||||||
|
|
||||||
|
typedef struct Ball {
|
||||||
|
Vector2 position;
|
||||||
|
Vector2 speed;
|
||||||
|
float radius;
|
||||||
|
float growth;
|
||||||
|
Color color;
|
||||||
|
bool active;
|
||||||
|
} Ball;
|
||||||
|
|
||||||
|
typedef struct Player {
|
||||||
|
Texture2D sprite;
|
||||||
|
float speed;
|
||||||
|
int hp;
|
||||||
|
int currentframe;
|
||||||
|
Vector2 sprite_pos;
|
||||||
|
Rectangle frameRec;
|
||||||
|
Rectangle hitbox;
|
||||||
|
} Player;
|
||||||
|
|
||||||
|
typedef struct Item {
|
||||||
|
Texture2D sprite;
|
||||||
|
Vector2 sprite_pos;
|
||||||
|
Rectangle hitbox;
|
||||||
|
bool active;
|
||||||
|
} Item;
|
||||||
|
|
||||||
|
int pauseTimer;
|
||||||
|
Sound fxbounce = { 0 };
|
||||||
|
Player player = { 0 };
|
||||||
|
Ball ball = { 0 };
|
||||||
|
Item heart = { 0 };
|
||||||
|
bool pause;
|
||||||
|
bool mute;
|
||||||
|
bool DebugMode;
|
||||||
|
|
||||||
|
#endif
|
290
src/Main.c
290
src/Main.c
|
@ -8,8 +8,10 @@
|
||||||
|
|
||||||
#include "../include/raylib.h"
|
#include "../include/raylib.h"
|
||||||
|
|
||||||
|
#include "Screens.h"
|
||||||
#include "Controls.h"
|
#include "Controls.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
#include <emscripten/emscripten.h>
|
#include <emscripten/emscripten.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,54 +20,13 @@
|
||||||
static const int screenWidth = 800;
|
static const int screenWidth = 800;
|
||||||
static const int screenHeight = 450;
|
static const int screenHeight = 450;
|
||||||
|
|
||||||
// Gamescreens
|
GameScreen currentScreen = 0;
|
||||||
typedef enum GameScreen { TITLE = 0, GAMEPLAY, GAMEOVER, CREDITS } GameScreen;
|
|
||||||
|
|
||||||
// structs
|
|
||||||
typedef struct Ball {
|
|
||||||
Vector2 position;
|
|
||||||
Vector2 speed;
|
|
||||||
float radius;
|
|
||||||
float growth;
|
|
||||||
Color color;
|
|
||||||
bool active;
|
|
||||||
} Ball;
|
|
||||||
|
|
||||||
typedef struct Player {
|
|
||||||
Texture2D sprite;
|
|
||||||
float speed;
|
|
||||||
int hp;
|
|
||||||
int currentframe;
|
|
||||||
Vector2 sprite_pos;
|
|
||||||
Rectangle frameRec;
|
|
||||||
Rectangle hitbox;
|
|
||||||
} Player;
|
|
||||||
/*
|
|
||||||
typedef struct Item {
|
|
||||||
Texture2D sprite;
|
|
||||||
Vector2 sprite_pos;
|
|
||||||
Rectangle hitbox;
|
|
||||||
bool active;
|
|
||||||
} Item;
|
|
||||||
*/
|
|
||||||
// Game variables
|
|
||||||
static int pauseTimer;
|
|
||||||
static int score, bestscore;
|
|
||||||
static int titleSelected = 0, gameoverSelected = 0;
|
|
||||||
static GameScreen currentScreen = { 0 };
|
|
||||||
static Sound fxbounce = { 0 };
|
|
||||||
static Player player = { 0 };
|
|
||||||
static Ball ball = { 0 };
|
|
||||||
// static Item heart = { 0 };
|
|
||||||
static bool pause;
|
|
||||||
static bool mute;
|
|
||||||
static bool DebugMode;
|
|
||||||
|
|
||||||
// Game functions
|
// Game functions
|
||||||
static void gameSetup(void);
|
static void gameSetup(void);
|
||||||
static void updateGame(void);
|
static void updateGame(void);
|
||||||
static void drawGame(void);
|
static void drawGame(void);
|
||||||
static void gameReset(void);
|
|
||||||
static void gameLoop(void);
|
static void gameLoop(void);
|
||||||
static void unloadGame(void);
|
static void unloadGame(void);
|
||||||
|
|
||||||
|
@ -99,48 +60,7 @@ void gameSetup(void)
|
||||||
// asset loading & setting of variable values
|
// asset loading & setting of variable values
|
||||||
currentScreen = TITLE;
|
currentScreen = TITLE;
|
||||||
|
|
||||||
fxbounce = LoadSound("assets/sfx/boing.wav");
|
InitGameplayScreen();
|
||||||
|
|
||||||
SetMasterVolume(0.2);
|
|
||||||
|
|
||||||
player.sprite = LoadTexture("assets/gfx/player.png");
|
|
||||||
player.currentframe = 0;
|
|
||||||
player.speed = 300.0f;
|
|
||||||
player.hp = 30;
|
|
||||||
player.frameRec = (Rectangle) {
|
|
||||||
player.hitbox.x,
|
|
||||||
player.hitbox.y,
|
|
||||||
(float) player.sprite.width/3,
|
|
||||||
(float) player.sprite.height
|
|
||||||
};
|
|
||||||
player.hitbox = (Rectangle) {
|
|
||||||
GetScreenWidth()/2.0f - 30,
|
|
||||||
GetScreenHeight()/2.0f - 30,
|
|
||||||
(float) player.sprite.width/3,
|
|
||||||
(float) player.sprite.height
|
|
||||||
};
|
|
||||||
/*
|
|
||||||
heart.sprite = LoadTexture("assets/gfx/health.png");
|
|
||||||
heart.hitbox = (Rectangle) {
|
|
||||||
GetRandomValue(0, screenWidth - heart.sprite.width),
|
|
||||||
GetRandomValue(0, screenHeight - heart.sprite.height),
|
|
||||||
(float) heart.sprite.width/3,
|
|
||||||
(float) heart.sprite.height
|
|
||||||
};
|
|
||||||
heart.active = true;
|
|
||||||
*/
|
|
||||||
ball.position = (Vector2){ 50, 50 };
|
|
||||||
ball.speed = (Vector2){ 400.0f, 300.0f };
|
|
||||||
ball.radius = 20;
|
|
||||||
ball.growth = 2;
|
|
||||||
ball.color = MAROON;
|
|
||||||
ball.active = true;
|
|
||||||
|
|
||||||
pause = 0;
|
|
||||||
mute = 0;
|
|
||||||
DebugMode = 0;
|
|
||||||
pauseTimer = 0;
|
|
||||||
score = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateGame(void)
|
void updateGame(void)
|
||||||
|
@ -149,106 +69,10 @@ void updateGame(void)
|
||||||
if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
|
if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
|
||||||
|
|
||||||
switch(currentScreen) {
|
switch(currentScreen) {
|
||||||
case TITLE:
|
case TITLE: UpdateTitleScreen(); break;
|
||||||
if (INPUT_UP_PRESSED) titleSelected++;
|
case GAMEPLAY: UpdateGameplayScreen(); break;
|
||||||
if (INPUT_DOWN_PRESSED) titleSelected--;
|
case GAMEOVER: UpdateGameoverScreen(); break;
|
||||||
if (titleSelected > 0) titleSelected--;
|
case CREDITS: UpdateCreditsScreen(); break;
|
||||||
if (titleSelected < -2) titleSelected++;
|
|
||||||
|
|
||||||
if ((titleSelected == 0) && (INPUT_OPTION_PRESSED)) currentScreen = GAMEPLAY;
|
|
||||||
if ((titleSelected == -1) && (INPUT_OPTION_PRESSED)) currentScreen = CREDITS;
|
|
||||||
if ((titleSelected == -2) && (INPUT_OPTION_PRESSED)) OpenURL("https://canneddonuts.itch.io/");
|
|
||||||
break;
|
|
||||||
case GAMEPLAY:
|
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_M)) mute = !mute;
|
|
||||||
|
|
||||||
if (INPUT_OPTION_PRESSED) pause = !pause;
|
|
||||||
|
|
||||||
if (!pause) {
|
|
||||||
// Controls
|
|
||||||
if (INPUT_LEFT_DOWN) player.hitbox.x -= GetFrameTime() * player.speed;
|
|
||||||
if (INPUT_RIGHT_DOWN) player.hitbox.x += GetFrameTime() * player.speed;
|
|
||||||
if (INPUT_UP_DOWN) player.hitbox.y -= GetFrameTime() * player.speed;
|
|
||||||
if (INPUT_DOWN_DOWN) player.hitbox.y += GetFrameTime() * player.speed;
|
|
||||||
if (INPUT_DASH_DOWN) {
|
|
||||||
player.speed = 600.0f;
|
|
||||||
if (player.currentframe != 1) player.currentframe = 2;
|
|
||||||
} else player.speed = 300.0f;
|
|
||||||
|
|
||||||
|
|
||||||
player.sprite_pos = (Vector2){ player.hitbox.x, player.hitbox.y };
|
|
||||||
player.frameRec.x = (float)player.currentframe*(float)player.sprite.width/3;
|
|
||||||
|
|
||||||
// heart.sprite_pos = (Vector2){ heart.hitbox.x, heart.hitbox.y };
|
|
||||||
|
|
||||||
// Player to da wallz collies
|
|
||||||
if ((player.hitbox.x + player.hitbox.width) >= GetScreenWidth()) player.hitbox.x = GetScreenWidth() - player.hitbox.width;
|
|
||||||
else if (player.hitbox.x <= 0) player.hitbox.x = 0;
|
|
||||||
|
|
||||||
if ((player.hitbox.y + player.hitbox.height) >= GetScreenHeight()) player.hitbox.y = GetScreenHeight() - player.hitbox.height;
|
|
||||||
else if (player.hitbox.y <= 0) player.hitbox.y = 0;
|
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_B)) ball.active = !ball.active;
|
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_D)) DebugMode = !DebugMode;
|
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_R)) {
|
|
||||||
gameReset();
|
|
||||||
currentScreen = TITLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.hp <= 0) {
|
|
||||||
gameReset();
|
|
||||||
currentScreen = GAMEOVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (ball.active) {
|
|
||||||
score++;
|
|
||||||
// movement of the ball
|
|
||||||
ball.position.x += GetFrameTime() * ball.speed.x;
|
|
||||||
ball.position.y += GetFrameTime() * ball.speed.y;
|
|
||||||
|
|
||||||
if (score >= bestscore) bestscore = score;
|
|
||||||
|
|
||||||
// Ballz to da wallz collies
|
|
||||||
if ((ball.position.x >= (GetScreenWidth() - ball.radius)) || (ball.position.x <= ball.radius)) {
|
|
||||||
ball.speed.x *= -1.0f;
|
|
||||||
if (!mute) PlaySoundMulti(fxbounce);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ball.position.y >= (GetScreenHeight() - ball.radius)) || (ball.position.y <= ball.radius)) {
|
|
||||||
ball.speed.y *= -1.0f;
|
|
||||||
if (!mute) PlaySoundMulti(fxbounce);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckCollisionCircleRec(ball.position, ball.radius, player.hitbox)) {
|
|
||||||
player.hp -= GetFrameTime() * 3.0f;
|
|
||||||
player.currentframe = 1;
|
|
||||||
} else player.currentframe = 0;
|
|
||||||
|
|
||||||
if (ball.radius <= 100) ball.radius += GetFrameTime() * ball.growth;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else pauseTimer++;
|
|
||||||
|
|
||||||
break;
|
|
||||||
case GAMEOVER:
|
|
||||||
if (INPUT_UP_PRESSED) gameoverSelected++;
|
|
||||||
if (INPUT_DOWN_PRESSED) gameoverSelected--;
|
|
||||||
if (gameoverSelected > 0) gameoverSelected--;
|
|
||||||
if (gameoverSelected < -1) gameoverSelected++;
|
|
||||||
|
|
||||||
if ((gameoverSelected == 0) && (INPUT_OPTION_PRESSED))
|
|
||||||
currentScreen = GAMEPLAY;
|
|
||||||
|
|
||||||
if ((gameoverSelected == -1) && (INPUT_OPTION_PRESSED))
|
|
||||||
currentScreen = TITLE;
|
|
||||||
break;
|
|
||||||
case CREDITS:
|
|
||||||
if (INPUT_OPTION_PRESSED) currentScreen = TITLE;
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,102 +85,16 @@ void drawGame(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
switch(currentScreen) {
|
switch(currentScreen) {
|
||||||
case TITLE:
|
case TITLE: DrawTitleScreen(); break;
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, ORANGE);
|
case GAMEPLAY: DrawGameplayScreen(); break;
|
||||||
DrawText("Controls", 10, 10, 30, PURPLE);
|
case GAMEOVER: DrawGameoverScreen(); break;
|
||||||
DrawText(TextFormat("BEST: %i", bestscore), 600, 0, 30, WHITE);
|
case CREDITS: DrawCreditsScreen(); break;
|
||||||
DrawText("Press the arrow keys or 'DPAD' to move and 'X' to dash", 10, 40, 10, RED);
|
|
||||||
DrawText("Press 'ENTER' or 'START' to pause", 10, 60, 10, RED);
|
|
||||||
DrawText("Press 'M' to mute", 10, 80, 10, RED);
|
|
||||||
DrawText("Press 'Left-ALT' + 'F' for full screen", 10, 100, 10, RED);
|
|
||||||
DrawText("Press 'R' to restart", 10, 120, 10, RED);
|
|
||||||
DrawText("Press 'ENTER' or 'START' to select an option", 10, 140, 10, RED);
|
|
||||||
DrawText("Avoid", 330, 20, 50, BLUE);
|
|
||||||
if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE);
|
|
||||||
else DrawText("PLAY", 360, 220, 20, BLUE);
|
|
||||||
|
|
||||||
if (titleSelected == -1) DrawText("CREDITS", 340, 240, 20, WHITE);
|
|
||||||
else DrawText("CREDITS", 340, 240, 20, BLUE);
|
|
||||||
|
|
||||||
if (titleSelected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE);
|
|
||||||
else DrawText("MORE GAMES", 320, 260, 20, BLUE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GAMEPLAY:
|
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, BLACK);
|
|
||||||
DrawFPS(10, 430);
|
|
||||||
DrawText(TextFormat("HP: %i", player.hp), 10, 10, 20, RED);
|
|
||||||
DrawText(TextFormat("SCORE: %i", score), 10, 30, 20, BLUE);
|
|
||||||
if (DebugMode) {
|
|
||||||
DrawText(TextFormat("BALL SIZE: %f", ball.radius), 10, 50, 20, GREEN);
|
|
||||||
DrawText(TextFormat("BALL POS X: %f, BALL POS Y: %f", ball.position.x, ball.position.y), 10, 70, 20, GREEN);
|
|
||||||
DrawText(TextFormat("BALL SPEED X: %f, BALL SPEED Y: %f", ball.speed.x, ball.speed.y), 10, 90, 20, GREEN);
|
|
||||||
DrawRectangleRec(player.hitbox, BLUE);
|
|
||||||
}
|
|
||||||
if (ball.active) DrawCircleV(ball.position, (float)ball.radius, ball.color);
|
|
||||||
// if (heart.active) DrawTexture(heart.sprite, heart.sprite_pos.x, heart.sprite_pos.y, RAYWHITE);
|
|
||||||
DrawTextureRec(player.sprite, player.frameRec, player.sprite_pos, WHITE);
|
|
||||||
if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, PURPLE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GAMEOVER:
|
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
|
|
||||||
DrawText("GAMEOVER", 250, 20, 50, RED);
|
|
||||||
if (gameoverSelected == 0) DrawText("RETRY", 350, 200, 20, WHITE);
|
|
||||||
else DrawText("RETRY", 350, 200, 20, RED);
|
|
||||||
|
|
||||||
if (gameoverSelected == -1) DrawText("TITLE", 352, 230, 20, WHITE);
|
|
||||||
else DrawText("TITLE", 352, 230, 20, RED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CREDITS:
|
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
|
|
||||||
DrawText("Avoid", 330, 20, 50, MAGENTA);
|
|
||||||
DrawText("Programming and Art by Return0ne", 10, 210, 20, BLUE);
|
|
||||||
DrawText("Powered by raylib 4.0", 10, 240, 20, BLUE);
|
|
||||||
DrawText("A Canneddonuts project 2022", 10, 270, 40, RED);
|
|
||||||
DrawText("Press 'ENTER' ", 10, 350, 20, WHITE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gameReset(void)
|
|
||||||
{
|
|
||||||
// code to reset all variables without reloading assets
|
|
||||||
player.currentframe = 0;
|
|
||||||
player.speed = 300.0f;
|
|
||||||
player.hp = 30;
|
|
||||||
player.hitbox = (Rectangle) {
|
|
||||||
GetScreenWidth()/2.0f - 30,
|
|
||||||
GetScreenHeight()/2.0f - 30,
|
|
||||||
(float) player.sprite.width/3,
|
|
||||||
(float) player.sprite.height
|
|
||||||
};
|
|
||||||
/*
|
|
||||||
heart.hitbox = (Rectangle) {
|
|
||||||
GetRandomValue(0, screenWidth - heart.sprite.width),
|
|
||||||
GetRandomValue(0, screenHeight - heart.sprite.height),
|
|
||||||
(float) heart.sprite.width/3,
|
|
||||||
(float) heart.sprite.height
|
|
||||||
};
|
|
||||||
heart.active = true;
|
|
||||||
*/
|
|
||||||
ball.position = (Vector2){ 50, 50 };
|
|
||||||
ball.radius = 20;
|
|
||||||
ball.active = true;
|
|
||||||
|
|
||||||
DebugMode = 0;
|
|
||||||
|
|
||||||
pauseTimer = 0;
|
|
||||||
score = 0;
|
|
||||||
|
|
||||||
gameoverSelected = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gameLoop(void)
|
void gameLoop(void)
|
||||||
{
|
{
|
||||||
updateGame();
|
updateGame();
|
||||||
|
@ -365,7 +103,5 @@ void gameLoop(void)
|
||||||
|
|
||||||
void unloadGame(void)
|
void unloadGame(void)
|
||||||
{
|
{
|
||||||
UnloadSound(fxbounce);
|
UnloadGameplayScreen();
|
||||||
UnloadTexture(player.sprite);
|
|
||||||
//UnloadTexture(heart.sprite);
|
|
||||||
}
|
}
|
||||||
|
|
15
src/Score.h
Normal file
15
src/Score.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Score.h
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SCORE_HEADER
|
||||||
|
#define SCORE_HEADER
|
||||||
|
|
||||||
|
extern int bestscore;
|
||||||
|
extern int score;
|
||||||
|
|
||||||
|
#endif
|
36
src/Screens.h
Normal file
36
src/Screens.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Screens.h
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SCREENS_HEADER
|
||||||
|
#define SCREENS_HEADER
|
||||||
|
|
||||||
|
typedef enum GameScreen { TITLE = 0, GAMEPLAY, GAMEOVER, CREDITS } GameScreen;
|
||||||
|
|
||||||
|
extern GameScreen currentScreen;
|
||||||
|
|
||||||
|
void gameReset(void);
|
||||||
|
|
||||||
|
void UpdateTitleScreen(void);
|
||||||
|
void DrawTitleScreen(void);
|
||||||
|
|
||||||
|
|
||||||
|
void InitGameplayScreen(void);
|
||||||
|
void UpdateGameplayScreen(void);
|
||||||
|
void DrawGameplayScreen(void);
|
||||||
|
void UnloadGameplayScreen(void);
|
||||||
|
void ResetGameplayScreen(void);
|
||||||
|
|
||||||
|
void UpdateCreditsScreen(void);
|
||||||
|
void DrawCreditsScreen(void);
|
||||||
|
|
||||||
|
void InitGameoverScreen(void);
|
||||||
|
void UpdateGameoverScreen(void);
|
||||||
|
void DrawGameoverScreen(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
49
src/Title.c
Normal file
49
src/Title.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Title.h
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../include/raylib.h"
|
||||||
|
|
||||||
|
#include "Screens.h"
|
||||||
|
#include "Controls.h"
|
||||||
|
#include "Score.h"
|
||||||
|
|
||||||
|
int titleSelected = 0;
|
||||||
|
|
||||||
|
void UpdateTitleScreen(void)
|
||||||
|
{
|
||||||
|
if (INPUT_UP_PRESSED) titleSelected++;
|
||||||
|
if (INPUT_DOWN_PRESSED) titleSelected--;
|
||||||
|
if (titleSelected > 0) titleSelected--;
|
||||||
|
if (titleSelected < -2) titleSelected++;
|
||||||
|
|
||||||
|
if ((titleSelected == 0) && (INPUT_OPTION_PRESSED)) currentScreen = GAMEPLAY;
|
||||||
|
if ((titleSelected == -1) && (INPUT_OPTION_PRESSED)) currentScreen = CREDITS;
|
||||||
|
if ((titleSelected == -2) && (INPUT_OPTION_PRESSED)) OpenURL("https://canneddonuts.itch.io/");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawTitleScreen(void)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), ORANGE);
|
||||||
|
DrawText("Controls", 10, 10, 30, PURPLE);
|
||||||
|
DrawText(TextFormat("BEST: %i", bestscore), 600, 0, 30, WHITE);
|
||||||
|
DrawText("Press the arrow keys or 'DPAD' to move and 'X' to dash", 10, 40, 10, RED);
|
||||||
|
DrawText("Press 'ENTER' or 'START' to pause", 10, 60, 10, RED);
|
||||||
|
DrawText("Press 'M' to mute", 10, 80, 10, RED);
|
||||||
|
DrawText("Press 'Left-ALT' + 'F' for full screen", 10, 100, 10, RED);
|
||||||
|
DrawText("Press 'R' to restart", 10, 120, 10, RED);
|
||||||
|
DrawText("Press 'ENTER' or 'START' to select an option", 10, 140, 10, RED);
|
||||||
|
DrawText("Avoid", 330, 20, 50, BLUE);
|
||||||
|
if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE);
|
||||||
|
else DrawText("PLAY", 360, 220, 20, BLUE);
|
||||||
|
|
||||||
|
if (titleSelected == -1) DrawText("CREDITS", 340, 240, 20, WHITE);
|
||||||
|
else DrawText("CREDITS", 340, 240, 20, BLUE);
|
||||||
|
|
||||||
|
if (titleSelected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE);
|
||||||
|
else DrawText("MORE GAMES", 320, 260, 20, BLUE);
|
||||||
|
}
|
Loading…
Reference in a new issue