Compare commits
2 commits
2e3d37385b
...
e4b8831e8d
Author | SHA1 | Date | |
---|---|---|---|
e4b8831e8d | |||
6672c7bb7d |
12 changed files with 93 additions and 66 deletions
1
asset-src/gfx/background.piskel
Normal file
1
asset-src/gfx/background.piskel
Normal file
File diff suppressed because one or more lines are too long
9
asset-src/gfx/background_pal.json
Normal file
9
asset-src/gfx/background_pal.json
Normal 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
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 |
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "Screens.h"
|
||||
#include "Controls.h"
|
||||
#include "Textures.h"
|
||||
|
||||
void UpdateCreditsScreen(void)
|
||||
{
|
||||
|
@ -18,15 +19,11 @@ void UpdateCreditsScreen(void)
|
|||
|
||||
void DrawCreditsScreen(void)
|
||||
{
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GREEN);
|
||||
|
||||
DrawText("Avoid", 330, 20, 50, MAGENTA);
|
||||
|
||||
DrawTexture(background, 0, 0, DARKGRAY);
|
||||
DrawText("CREDITS", 290, 20, 50, BLUE);
|
||||
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("A Canneddonuts project 2022", 10, 270, 40, BLUE);
|
||||
DrawText(TextFormat("Build compiled on %s", __DATE__), 10, 310, 30, YELLOW);
|
||||
DrawText("Press 'ENTER' ", 10, 350, 20, WHITE);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ void UpdateGameoverScreen(void)
|
|||
|
||||
void DrawGameoverScreen(void)
|
||||
{
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE);
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
||||
DrawText("GAMEOVER", 250, 20, 50, RED);
|
||||
if (gameoverSelected == 0) DrawText("RETRY", 350, 200, 20, WHITE);
|
||||
else DrawText("RETRY", 350, 200, 20, RED);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "Controls.h"
|
||||
#include "Gameplay.h"
|
||||
#include "Score.h"
|
||||
#include "Textures.h"
|
||||
|
||||
int score = 0, bestscore = 0;
|
||||
|
||||
|
@ -38,14 +39,14 @@ void InitGameplayScreen(void)
|
|||
(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.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;
|
||||
heart.active = true;
|
||||
|
||||
ball.position = (Vector2){ 50, 50 };
|
||||
ball.speed = (Vector2){ 400.0f, 300.0f };
|
||||
|
@ -55,7 +56,7 @@ void InitGameplayScreen(void)
|
|||
ball.active = true;
|
||||
|
||||
pause = 0;
|
||||
mute = 0;
|
||||
mute = true;
|
||||
DebugMode = 0;
|
||||
pauseTimer = 0;
|
||||
}
|
||||
|
@ -78,8 +79,8 @@ void ResetGameplayScreen(void)
|
|||
GetRandomValue(0, GetScreenHeight() - heart.sprite.height),
|
||||
(float) heart.sprite.width,
|
||||
(float) heart.sprite.height
|
||||
};
|
||||
heart.active = false;
|
||||
};
|
||||
heart.active = true;
|
||||
|
||||
ball.position = (Vector2){ 50, 50 };
|
||||
ball.radius = 20;
|
||||
|
@ -93,20 +94,20 @@ void ResetGameplayScreen(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
|
||||
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;
|
||||
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 };
|
||||
|
@ -114,16 +115,7 @@ void UpdateGameplayScreen(void)
|
|||
|
||||
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;
|
||||
if (score % 1000 == 0) heart.active = true;
|
||||
|
||||
// Player to da wallz collies
|
||||
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) {
|
||||
score++;
|
||||
|
||||
if (score >= bestscore) bestscore = 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;
|
||||
|
@ -188,7 +181,7 @@ void UpdateGameplayScreen(void)
|
|||
|
||||
void DrawGameplayScreen(void)
|
||||
{
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
||||
DrawTexture(background, 0, 0, RAYWHITE);
|
||||
DrawFPS(10, 430);
|
||||
DrawText(TextFormat("HP: %i", player.hp), 10, 10, 20, RED);
|
||||
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 (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);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,16 +9,16 @@
|
|||
#ifndef GAMEPLAY_HEADER
|
||||
#define GAMEPLAY_HEADER
|
||||
|
||||
typedef struct Ball {
|
||||
struct Ball {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
float radius;
|
||||
float growth;
|
||||
Color color;
|
||||
bool active;
|
||||
} Ball;
|
||||
};
|
||||
|
||||
typedef struct Player {
|
||||
struct Player {
|
||||
Texture2D sprite;
|
||||
float speed;
|
||||
int hp;
|
||||
|
@ -26,20 +26,20 @@ typedef struct Player {
|
|||
Vector2 sprite_pos;
|
||||
Rectangle frameRec;
|
||||
Rectangle hitbox;
|
||||
} Player;
|
||||
};
|
||||
|
||||
typedef struct Item {
|
||||
struct Item {
|
||||
Texture2D sprite;
|
||||
Vector2 sprite_pos;
|
||||
Rectangle hitbox;
|
||||
bool active;
|
||||
} Item;
|
||||
};
|
||||
|
||||
struct Player player = { 0 };
|
||||
struct Ball ball = { 0 };
|
||||
struct Item heart = { 0 };
|
||||
int pauseTimer;
|
||||
Sound fxbounce = { 0 };
|
||||
Player player = { 0 };
|
||||
Ball ball = { 0 };
|
||||
Item heart = { 0 };
|
||||
bool pause;
|
||||
bool mute;
|
||||
bool DebugMode;
|
||||
|
|
10
src/Main.c
10
src/Main.c
|
@ -9,8 +9,6 @@
|
|||
#include "../include/raylib.h"
|
||||
|
||||
#include "Screens.h"
|
||||
#include "Controls.h"
|
||||
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
|
@ -21,7 +19,7 @@ static const int screenWidth = 800;
|
|||
static const int screenHeight = 450;
|
||||
|
||||
GameScreen currentScreen = 0;
|
||||
|
||||
Texture2D background = { 0 };
|
||||
|
||||
// Game functions
|
||||
static void gameSetup(void);
|
||||
|
@ -61,6 +59,7 @@ void gameSetup(void)
|
|||
currentScreen = TITLE;
|
||||
|
||||
InitGameplayScreen();
|
||||
InitTitleScreen();
|
||||
}
|
||||
|
||||
void updateGame(void)
|
||||
|
@ -68,7 +67,7 @@ void updateGame(void)
|
|||
// code that runs as long as the program is running
|
||||
if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
|
||||
|
||||
switch(currentScreen) {
|
||||
switch (currentScreen) {
|
||||
case TITLE: UpdateTitleScreen(); break;
|
||||
case GAMEPLAY: UpdateGameplayScreen(); break;
|
||||
case GAMEOVER: UpdateGameoverScreen(); break;
|
||||
|
@ -84,7 +83,7 @@ void drawGame(void)
|
|||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
switch(currentScreen) {
|
||||
switch (currentScreen) {
|
||||
case TITLE: DrawTitleScreen(); break;
|
||||
case GAMEPLAY: DrawGameplayScreen(); break;
|
||||
case GAMEOVER: DrawGameoverScreen(); break;
|
||||
|
@ -104,4 +103,5 @@ void gameLoop(void)
|
|||
void unloadGame(void)
|
||||
{
|
||||
UnloadGameplayScreen();
|
||||
UnloadTitleScreen();
|
||||
}
|
||||
|
|
|
@ -15,8 +15,10 @@ extern GameScreen currentScreen;
|
|||
|
||||
void gameReset(void);
|
||||
|
||||
void InitTitleScreen(void);
|
||||
void UpdateTitleScreen(void);
|
||||
void DrawTitleScreen(void);
|
||||
void UnloadTitleScreen(void);
|
||||
|
||||
|
||||
void InitGameplayScreen(void);
|
||||
|
|
14
src/Textures.h
Normal file
14
src/Textures.h
Normal 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
|
27
src/Title.c
27
src/Title.c
|
@ -11,9 +11,15 @@
|
|||
#include "Screens.h"
|
||||
#include "Controls.h"
|
||||
#include "Score.h"
|
||||
#include "Textures.h"
|
||||
|
||||
int titleSelected = 0;
|
||||
|
||||
void InitTitleScreen(void)
|
||||
{
|
||||
background = LoadTexture("assets/gfx/background.png");
|
||||
}
|
||||
|
||||
void UpdateTitleScreen(void)
|
||||
{
|
||||
if (INPUT_UP_PRESSED) titleSelected++;
|
||||
|
@ -28,15 +34,15 @@ void UpdateTitleScreen(void)
|
|||
|
||||
void DrawTitleScreen(void)
|
||||
{
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), ORANGE);
|
||||
DrawText("Controls", 10, 10, 30, PURPLE);
|
||||
DrawTexture(background, 0, 0, GRAY);
|
||||
DrawText("Controls", 10, 10, 30, BLUE);
|
||||
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("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, WHITE);
|
||||
DrawText("Press 'M' to mute", 10, 80, 10, WHITE);
|
||||
DrawText("Press 'Left-ALT' + 'F' for full screen", 10, 100, 10, WHITE);
|
||||
DrawText("Press 'R' to restart", 10, 120, 10, WHITE);
|
||||
DrawText("Press 'ENTER' or 'START' to select an option", 10, 140, 10, WHITE);
|
||||
DrawText("Avoid", 330, 20, 50, BLUE);
|
||||
if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE);
|
||||
else DrawText("PLAY", 360, 220, 20, BLUE);
|
||||
|
@ -47,3 +53,8 @@ void DrawTitleScreen(void)
|
|||
if (titleSelected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE);
|
||||
else DrawText("MORE GAMES", 320, 260, 20, BLUE);
|
||||
}
|
||||
|
||||
void UnloadTitleScreen(void)
|
||||
{
|
||||
UnloadTexture(background);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue