Compare commits

...

2 commits

Author SHA1 Message Date
e4b8831e8d added backgrounds 2022-06-16 22:17:26 -04:00
6672c7bb7d cleaner heart code and new date of build in the credits 2022-06-13 20:33:35 -04:00
12 changed files with 93 additions and 66 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,9 @@
GIMP Palette
Name: Avoid_bg
Columns: 0
#
248 248 248 Untitled
166 166 166 Untitled
30 142 20 Untitled
22 85 93 Untitled

BIN
assets/gfx/background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View file

@ -10,6 +10,7 @@
#include "Screens.h" #include "Screens.h"
#include "Controls.h" #include "Controls.h"
#include "Textures.h"
void UpdateCreditsScreen(void) void UpdateCreditsScreen(void)
{ {
@ -18,15 +19,11 @@ void UpdateCreditsScreen(void)
void DrawCreditsScreen(void) void DrawCreditsScreen(void)
{ {
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GREEN); DrawTexture(background, 0, 0, DARKGRAY);
DrawText("CREDITS", 290, 20, 50, BLUE);
DrawText("Avoid", 330, 20, 50, MAGENTA);
DrawText("Programming and Art by Return0ne", 10, 210, 20, BLUE); DrawText("Programming and Art by Return0ne", 10, 210, 20, BLUE);
DrawText("Powered by raylib 4.0", 10, 240, 20, BLUE); DrawText("Powered by raylib 4.0", 10, 240, 20, BLUE);
DrawText("A Canneddonuts project 2022", 10, 270, 40, BLUE);
DrawText("A Canneddonuts project 2022", 10, 270, 40, RED); DrawText(TextFormat("Build compiled on %s", __DATE__), 10, 310, 30, YELLOW);
DrawText("Press 'ENTER' ", 10, 350, 20, WHITE); DrawText("Press 'ENTER' ", 10, 350, 20, WHITE);
} }

View file

@ -34,7 +34,7 @@ void UpdateGameoverScreen(void)
void DrawGameoverScreen(void) void DrawGameoverScreen(void)
{ {
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
DrawText("GAMEOVER", 250, 20, 50, RED); DrawText("GAMEOVER", 250, 20, 50, RED);
if (gameoverSelected == 0) DrawText("RETRY", 350, 200, 20, WHITE); if (gameoverSelected == 0) DrawText("RETRY", 350, 200, 20, WHITE);
else DrawText("RETRY", 350, 200, 20, RED); else DrawText("RETRY", 350, 200, 20, RED);

View file

@ -12,6 +12,7 @@
#include "Controls.h" #include "Controls.h"
#include "Gameplay.h" #include "Gameplay.h"
#include "Score.h" #include "Score.h"
#include "Textures.h"
int score = 0, bestscore = 0; int score = 0, bestscore = 0;
@ -38,14 +39,14 @@ void InitGameplayScreen(void)
(float) player.sprite.height (float) player.sprite.height
}; };
heart.sprite = LoadTexture("assets/gfx/health.png"); heart.sprite = LoadTexture("assets/gfx/health.png");
heart.hitbox = (Rectangle) { heart.hitbox = (Rectangle) {
GetRandomValue(0, GetScreenWidth() - heart.sprite.width), GetRandomValue(0, GetScreenWidth() - heart.sprite.width),
GetRandomValue(0, GetScreenHeight() - heart.sprite.height), GetRandomValue(0, GetScreenHeight() - heart.sprite.height),
(float) heart.sprite.width, (float) heart.sprite.width,
(float) heart.sprite.height (float) heart.sprite.height
}; };
heart.active = false; heart.active = true;
ball.position = (Vector2){ 50, 50 }; ball.position = (Vector2){ 50, 50 };
ball.speed = (Vector2){ 400.0f, 300.0f }; ball.speed = (Vector2){ 400.0f, 300.0f };
@ -55,7 +56,7 @@ void InitGameplayScreen(void)
ball.active = true; ball.active = true;
pause = 0; pause = 0;
mute = 0; mute = true;
DebugMode = 0; DebugMode = 0;
pauseTimer = 0; pauseTimer = 0;
} }
@ -78,8 +79,8 @@ void ResetGameplayScreen(void)
GetRandomValue(0, GetScreenHeight() - heart.sprite.height), GetRandomValue(0, GetScreenHeight() - heart.sprite.height),
(float) heart.sprite.width, (float) heart.sprite.width,
(float) heart.sprite.height (float) heart.sprite.height
}; };
heart.active = false; heart.active = true;
ball.position = (Vector2){ 50, 50 }; ball.position = (Vector2){ 50, 50 };
ball.radius = 20; ball.radius = 20;
@ -93,20 +94,20 @@ void ResetGameplayScreen(void)
void UpdateGameplayScreen(void) void UpdateGameplayScreen(void)
{ {
if (IsKeyPressed(KEY_M)) mute = !mute; if (IsKeyPressed(KEY_M)) mute = !mute;
if (INPUT_OPTION_PRESSED) pause = !pause; if (INPUT_OPTION_PRESSED) pause = !pause;
if (!pause) { if (!pause) {
// Controls // Controls
if (INPUT_LEFT_DOWN) player.hitbox.x -= GetFrameTime() * player.speed; if (INPUT_LEFT_DOWN) player.hitbox.x -= GetFrameTime() * player.speed;
if (INPUT_RIGHT_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_UP_DOWN) player.hitbox.y -= GetFrameTime() * player.speed;
if (INPUT_DOWN_DOWN) player.hitbox.y += GetFrameTime() * player.speed; if (INPUT_DOWN_DOWN) player.hitbox.y += GetFrameTime() * player.speed;
if (INPUT_DASH_DOWN) { if (INPUT_DASH_DOWN) {
player.speed = 600.0f; player.speed = 600.0f;
if (player.currentframe != 1) player.currentframe = 2; if (player.currentframe != 1) player.currentframe = 2;
} else player.speed = 300.0f; } else player.speed = 300.0f;
player.sprite_pos = (Vector2){ player.hitbox.x, player.hitbox.y }; player.sprite_pos = (Vector2){ player.hitbox.x, player.hitbox.y };
@ -114,16 +115,7 @@ void UpdateGameplayScreen(void)
heart.sprite_pos = (Vector2){ heart.hitbox.x, heart.hitbox.y }; heart.sprite_pos = (Vector2){ heart.hitbox.x, heart.hitbox.y };
if (score == 1000) heart.active = true; if (score % 1000 == 0) 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 // Player to da wallz collies
if ((player.hitbox.x + player.hitbox.width) >= GetScreenWidth()) player.hitbox.x = GetScreenWidth() - player.hitbox.width; if ((player.hitbox.x + player.hitbox.width) >= GetScreenWidth()) player.hitbox.x = GetScreenWidth() - player.hitbox.width;
@ -157,12 +149,13 @@ void UpdateGameplayScreen(void)
if (ball.active) { if (ball.active) {
score++; score++;
if (score >= bestscore) bestscore = score;
// movement of the ball // movement of the ball
ball.position.x += GetFrameTime() * ball.speed.x; ball.position.x += GetFrameTime() * ball.speed.x;
ball.position.y += GetFrameTime() * ball.speed.y; ball.position.y += GetFrameTime() * ball.speed.y;
if (score >= bestscore) bestscore = score;
// Ballz to da wallz collies // Ballz to da wallz collies
if ((ball.position.x >= (GetScreenWidth() - ball.radius)) || (ball.position.x <= ball.radius)) { if ((ball.position.x >= (GetScreenWidth() - ball.radius)) || (ball.position.x <= ball.radius)) {
ball.speed.x *= -1.0f; ball.speed.x *= -1.0f;
@ -188,7 +181,7 @@ void UpdateGameplayScreen(void)
void DrawGameplayScreen(void) void DrawGameplayScreen(void)
{ {
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK); DrawTexture(background, 0, 0, RAYWHITE);
DrawFPS(10, 430); DrawFPS(10, 430);
DrawText(TextFormat("HP: %i", player.hp), 10, 10, 20, RED); DrawText(TextFormat("HP: %i", player.hp), 10, 10, 20, RED);
DrawText(TextFormat("SCORE: %i", score), 10, 30, 20, BLUE); DrawText(TextFormat("SCORE: %i", score), 10, 30, 20, BLUE);
@ -201,7 +194,7 @@ void DrawGameplayScreen(void)
} }
if (ball.active) DrawCircleV(ball.position, (float)ball.radius, ball.color); 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); if (heart.active) DrawTexture(heart.sprite, heart.sprite_pos.x, heart.sprite_pos.y, RAYWHITE);
DrawTextureRec(player.sprite, player.frameRec, player.sprite_pos, WHITE); DrawTextureRec(player.sprite, player.frameRec, player.sprite_pos, RAYWHITE);
if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, PURPLE); if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, PURPLE);
} }

View file

@ -9,16 +9,16 @@
#ifndef GAMEPLAY_HEADER #ifndef GAMEPLAY_HEADER
#define GAMEPLAY_HEADER #define GAMEPLAY_HEADER
typedef struct Ball { struct Ball {
Vector2 position; Vector2 position;
Vector2 speed; Vector2 speed;
float radius; float radius;
float growth; float growth;
Color color; Color color;
bool active; bool active;
} Ball; };
typedef struct Player { struct Player {
Texture2D sprite; Texture2D sprite;
float speed; float speed;
int hp; int hp;
@ -26,20 +26,20 @@ typedef struct Player {
Vector2 sprite_pos; Vector2 sprite_pos;
Rectangle frameRec; Rectangle frameRec;
Rectangle hitbox; Rectangle hitbox;
} Player; };
typedef struct Item { struct Item {
Texture2D sprite; Texture2D sprite;
Vector2 sprite_pos; Vector2 sprite_pos;
Rectangle hitbox; Rectangle hitbox;
bool active; bool active;
} Item; };
struct Player player = { 0 };
struct Ball ball = { 0 };
struct Item heart = { 0 };
int pauseTimer; int pauseTimer;
Sound fxbounce = { 0 }; Sound fxbounce = { 0 };
Player player = { 0 };
Ball ball = { 0 };
Item heart = { 0 };
bool pause; bool pause;
bool mute; bool mute;
bool DebugMode; bool DebugMode;

View file

@ -9,8 +9,6 @@
#include "../include/raylib.h" #include "../include/raylib.h"
#include "Screens.h" #include "Screens.h"
#include "Controls.h"
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
@ -21,7 +19,7 @@ static const int screenWidth = 800;
static const int screenHeight = 450; static const int screenHeight = 450;
GameScreen currentScreen = 0; GameScreen currentScreen = 0;
Texture2D background = { 0 };
// Game functions // Game functions
static void gameSetup(void); static void gameSetup(void);
@ -61,6 +59,7 @@ void gameSetup(void)
currentScreen = TITLE; currentScreen = TITLE;
InitGameplayScreen(); InitGameplayScreen();
InitTitleScreen();
} }
void updateGame(void) void updateGame(void)
@ -68,7 +67,7 @@ void updateGame(void)
// code that runs as long as the program is running // code that runs as long as the program is running
if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen(); if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
switch(currentScreen) { switch (currentScreen) {
case TITLE: UpdateTitleScreen(); break; case TITLE: UpdateTitleScreen(); break;
case GAMEPLAY: UpdateGameplayScreen(); break; case GAMEPLAY: UpdateGameplayScreen(); break;
case GAMEOVER: UpdateGameoverScreen(); break; case GAMEOVER: UpdateGameoverScreen(); break;
@ -84,7 +83,7 @@ void drawGame(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
switch(currentScreen) { switch (currentScreen) {
case TITLE: DrawTitleScreen(); break; case TITLE: DrawTitleScreen(); break;
case GAMEPLAY: DrawGameplayScreen(); break; case GAMEPLAY: DrawGameplayScreen(); break;
case GAMEOVER: DrawGameoverScreen(); break; case GAMEOVER: DrawGameoverScreen(); break;
@ -104,4 +103,5 @@ void gameLoop(void)
void unloadGame(void) void unloadGame(void)
{ {
UnloadGameplayScreen(); UnloadGameplayScreen();
UnloadTitleScreen();
} }

View file

@ -15,8 +15,10 @@ extern GameScreen currentScreen;
void gameReset(void); void gameReset(void);
void InitTitleScreen(void);
void UpdateTitleScreen(void); void UpdateTitleScreen(void);
void DrawTitleScreen(void); void DrawTitleScreen(void);
void UnloadTitleScreen(void);
void InitGameplayScreen(void); void InitGameplayScreen(void);

14
src/Textures.h Normal file
View file

@ -0,0 +1,14 @@
/*
- Avoid ~ a game by Canneddonuts
- Filename ~ Textures.h
- Author ~ Return0ne
- 2022
- *no license*
*/
#ifndef TEXTURES_HEADER
#define TEXTURES_HEADER
extern Texture2D background;
#endif

View file

@ -11,9 +11,15 @@
#include "Screens.h" #include "Screens.h"
#include "Controls.h" #include "Controls.h"
#include "Score.h" #include "Score.h"
#include "Textures.h"
int titleSelected = 0; int titleSelected = 0;
void InitTitleScreen(void)
{
background = LoadTexture("assets/gfx/background.png");
}
void UpdateTitleScreen(void) void UpdateTitleScreen(void)
{ {
if (INPUT_UP_PRESSED) titleSelected++; if (INPUT_UP_PRESSED) titleSelected++;
@ -28,15 +34,15 @@ void UpdateTitleScreen(void)
void DrawTitleScreen(void) void DrawTitleScreen(void)
{ {
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), ORANGE); DrawTexture(background, 0, 0, GRAY);
DrawText("Controls", 10, 10, 30, PURPLE); DrawText("Controls", 10, 10, 30, BLUE);
DrawText(TextFormat("BEST: %i", bestscore), 600, 0, 30, WHITE); 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 the arrow keys or 'DPAD' to move and 'X' to dash", 10, 40, 10, WHITE);
DrawText("Press 'ENTER' or 'START' to pause", 10, 60, 10, RED); DrawText("Press 'ENTER' or 'START' to pause", 10, 60, 10, WHITE);
DrawText("Press 'M' to mute", 10, 80, 10, RED); DrawText("Press 'M' to mute", 10, 80, 10, WHITE);
DrawText("Press 'Left-ALT' + 'F' for full screen", 10, 100, 10, RED); DrawText("Press 'Left-ALT' + 'F' for full screen", 10, 100, 10, WHITE);
DrawText("Press 'R' to restart", 10, 120, 10, RED); DrawText("Press 'R' to restart", 10, 120, 10, WHITE);
DrawText("Press 'ENTER' or 'START' to select an option", 10, 140, 10, RED); DrawText("Press 'ENTER' or 'START' to select an option", 10, 140, 10, WHITE);
DrawText("Avoid", 330, 20, 50, BLUE); DrawText("Avoid", 330, 20, 50, BLUE);
if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE); if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE);
else DrawText("PLAY", 360, 220, 20, BLUE); else DrawText("PLAY", 360, 220, 20, BLUE);
@ -47,3 +53,8 @@ void DrawTitleScreen(void)
if (titleSelected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE); if (titleSelected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE);
else DrawText("MORE GAMES", 320, 260, 20, BLUE); else DrawText("MORE GAMES", 320, 260, 20, BLUE);
} }
void UnloadTitleScreen(void)
{
UnloadTexture(background);
}