added backgrounds

This commit is contained in:
Return0ne 2022-06-16 22:17:26 -04:00
parent 6672c7bb7d
commit e4b8831e8d
12 changed files with 79 additions and 39 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: 2.1 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@ -10,6 +10,7 @@
#include "Screens.h"
#include "Controls.h"
#include "Textures.h"
void UpdateCreditsScreen(void)
{
@ -18,11 +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);
}

View File

@ -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);

View File

@ -12,6 +12,7 @@
#include "Controls.h"
#include "Gameplay.h"
#include "Score.h"
#include "Textures.h"
int score = 0, bestscore = 0;
@ -38,12 +39,12 @@ 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 = true;
@ -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 = true;
};
heart.active = true;
ball.position = (Vector2){ 50, 50 };
ball.radius = 20;
@ -148,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;
@ -179,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);
@ -192,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);
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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
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 "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);
}