added iframes and better hitboxes
This commit is contained in:
parent
9588fc1417
commit
5d45fea734
4 changed files with 78 additions and 24 deletions
|
@ -26,7 +26,7 @@
|
||||||
# Define required environment variables
|
# Define required environment variables
|
||||||
#------------------------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------------------------
|
||||||
# Define target platform: PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
|
# Define target platform: PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
|
||||||
PLATFORM ?= PLATFORM_DESKTOP
|
PLATFORM ?= PLATFORM_WEB
|
||||||
|
|
||||||
# Define project variables
|
# Define project variables
|
||||||
PROJECT_NAME ?= index
|
PROJECT_NAME ?= index
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "Controls.h"
|
#include "Controls.h"
|
||||||
#include "Gameplay.h"
|
#include "Gameplay.h"
|
||||||
#include "Score.h"
|
#include "Score.h"
|
||||||
|
#include "Timers.h"
|
||||||
#include "Textures.h"
|
#include "Textures.h"
|
||||||
|
|
||||||
int score = 0, bestscore = 0;
|
int score = 0, bestscore = 0;
|
||||||
|
@ -25,7 +26,7 @@ void InitGameplayScreen(void)
|
||||||
player_sprite = LoadTexture("assets/gfx/player.png");
|
player_sprite = LoadTexture("assets/gfx/player.png");
|
||||||
player.currentframe = 0;
|
player.currentframe = 0;
|
||||||
player.speed = 300.0f;
|
player.speed = 300.0f;
|
||||||
player.hp = 30;
|
player.hp = MAX_PLAYER_HP;
|
||||||
player.frameRec = (Rectangle) {
|
player.frameRec = (Rectangle) {
|
||||||
player.hitbox.x,
|
player.hitbox.x,
|
||||||
player.hitbox.y,
|
player.hitbox.y,
|
||||||
|
@ -36,8 +37,12 @@ void InitGameplayScreen(void)
|
||||||
0,
|
0,
|
||||||
50,
|
50,
|
||||||
(float) player_sprite.width/3,
|
(float) player_sprite.width/3,
|
||||||
(float) player_sprite.height
|
(float) player_sprite.height/2 + 5
|
||||||
};
|
};
|
||||||
|
player_iframeTimer = 0;
|
||||||
|
player_in = false;
|
||||||
|
player.color = RAYWHITE;
|
||||||
|
player_flashtimer = 0;
|
||||||
|
|
||||||
enemy_sprite = LoadTexture("assets/gfx/enemy.png");
|
enemy_sprite = LoadTexture("assets/gfx/enemy.png");
|
||||||
enemy.currentframe = 0;
|
enemy.currentframe = 0;
|
||||||
|
@ -49,6 +54,7 @@ void InitGameplayScreen(void)
|
||||||
(float) enemy_sprite.width,
|
(float) enemy_sprite.width,
|
||||||
(float) enemy_sprite.height
|
(float) enemy_sprite.height
|
||||||
};
|
};
|
||||||
|
enemy.color = RAYWHITE;
|
||||||
|
|
||||||
|
|
||||||
heart_sprite = LoadTexture("assets/gfx/health.png");
|
heart_sprite = LoadTexture("assets/gfx/health.png");
|
||||||
|
@ -68,9 +74,10 @@ void InitGameplayScreen(void)
|
||||||
fireworks[i].hitbox = (Rectangle) {
|
fireworks[i].hitbox = (Rectangle) {
|
||||||
630,
|
630,
|
||||||
GetRandomValue(0, GetScreenHeight()),
|
GetRandomValue(0, GetScreenHeight()),
|
||||||
(float) firework_sprite.width,
|
(float) firework_sprite.width/2 + 10,
|
||||||
(float) firework_sprite.height
|
(float) firework_sprite.height
|
||||||
};
|
};
|
||||||
|
fireworks[i].color = RAYWHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pause = 0;
|
pause = 0;
|
||||||
|
@ -84,13 +91,17 @@ void ResetGameplayScreen(void)
|
||||||
// code to reset all variables without reloading assets
|
// code to reset all variables without reloading assets
|
||||||
player.currentframe = 0;
|
player.currentframe = 0;
|
||||||
player.speed = 300.0f;
|
player.speed = 300.0f;
|
||||||
player.hp = 30;
|
player.hp = MAX_PLAYER_HP;
|
||||||
player.hitbox = (Rectangle) {
|
player.hitbox = (Rectangle) {
|
||||||
0,
|
0,
|
||||||
50,
|
50,
|
||||||
(float) player_sprite.width/3,
|
(float) player_sprite.width/3,
|
||||||
(float) player_sprite.height
|
(float) player_sprite.height/2 + 5
|
||||||
};
|
};
|
||||||
|
player_iframeTimer = 0;
|
||||||
|
player_in = false;
|
||||||
|
player.color = RAYWHITE;
|
||||||
|
player_flashtimer = 0;
|
||||||
|
|
||||||
enemy.currentframe = 0;
|
enemy.currentframe = 0;
|
||||||
enemy.speed = 100.0f;
|
enemy.speed = 100.0f;
|
||||||
|
@ -117,7 +128,7 @@ void ResetGameplayScreen(void)
|
||||||
fireworks[i].hitbox = (Rectangle) {
|
fireworks[i].hitbox = (Rectangle) {
|
||||||
630,
|
630,
|
||||||
GetRandomValue(0, GetScreenHeight()),
|
GetRandomValue(0, GetScreenHeight()),
|
||||||
(float) firework_sprite.width,
|
(float) firework_sprite.width/2 + 10,
|
||||||
(float) firework_sprite.height
|
(float) firework_sprite.height
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -128,6 +139,29 @@ void ResetGameplayScreen(void)
|
||||||
score = 0;
|
score = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DamagePlayer(void)
|
||||||
|
{
|
||||||
|
if (!player_in) {
|
||||||
|
player.hp--;
|
||||||
|
player_in = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.currentframe = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateiFrameTimer(void)
|
||||||
|
{
|
||||||
|
if (player_in) {
|
||||||
|
player_iframeTimer++;
|
||||||
|
if (player_flashtimer % 2 == 0) player.color = BLANK;
|
||||||
|
else player.color = RAYWHITE;
|
||||||
|
if (player_iframeTimer >= 60) {
|
||||||
|
player_in = false;
|
||||||
|
player_iframeTimer = 0;
|
||||||
|
}
|
||||||
|
} else player.color = RAYWHITE;
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateGameplayScreen(void)
|
void UpdateGameplayScreen(void)
|
||||||
{
|
{
|
||||||
if (IsKeyPressed(KEY_M)) mute = !mute;
|
if (IsKeyPressed(KEY_M)) mute = !mute;
|
||||||
|
@ -151,6 +185,8 @@ void UpdateGameplayScreen(void)
|
||||||
heart.sprite_pos = (Vector2){ heart.hitbox.x, heart.hitbox.y };
|
heart.sprite_pos = (Vector2){ heart.hitbox.x, heart.hitbox.y };
|
||||||
enemy.sprite_pos = (Vector2){ enemy.hitbox.x, enemy.hitbox.y };
|
enemy.sprite_pos = (Vector2){ enemy.hitbox.x, enemy.hitbox.y };
|
||||||
|
|
||||||
|
player_flashtimer++;
|
||||||
|
|
||||||
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
||||||
fireworks[i].sprite_pos = (Vector2){ fireworks[i].hitbox.x, fireworks[i].hitbox.y };
|
fireworks[i].sprite_pos = (Vector2){ fireworks[i].hitbox.x, fireworks[i].hitbox.y };
|
||||||
}
|
}
|
||||||
|
@ -164,6 +200,8 @@ void UpdateGameplayScreen(void)
|
||||||
if ((player.hitbox.y + player.hitbox.height) >= GetScreenHeight()) player.hitbox.y = GetScreenHeight() - player.hitbox.height;
|
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;
|
else if (player.hitbox.y <= 0) player.hitbox.y = 0;
|
||||||
|
|
||||||
|
UpdateiFrameTimer();
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_D)) DebugMode = !DebugMode;
|
if (IsKeyPressed(KEY_D)) DebugMode = !DebugMode;
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_R)) {
|
if (IsKeyPressed(KEY_R)) {
|
||||||
|
@ -178,7 +216,7 @@ void UpdateGameplayScreen(void)
|
||||||
|
|
||||||
if (heart.active) {
|
if (heart.active) {
|
||||||
if (CheckCollisionRecs(player.hitbox, heart.hitbox)) {
|
if (CheckCollisionRecs(player.hitbox, heart.hitbox)) {
|
||||||
player.hp = 30;
|
player.hp = MAX_PLAYER_HP;
|
||||||
heart.hitbox.x = GetRandomValue(0, GetScreenWidth() - heart_sprite.width);
|
heart.hitbox.x = GetRandomValue(0, GetScreenWidth() - heart_sprite.width);
|
||||||
heart.hitbox.y = GetRandomValue(0, GetScreenHeight() - heart_sprite.height);
|
heart.hitbox.y = GetRandomValue(0, GetScreenHeight() - heart_sprite.height);
|
||||||
heart.active = false;
|
heart.active = false;
|
||||||
|
@ -194,17 +232,12 @@ void UpdateGameplayScreen(void)
|
||||||
if (((enemy.hitbox.y + enemy.hitbox.height) >= GetScreenHeight()
|
if (((enemy.hitbox.y + enemy.hitbox.height) >= GetScreenHeight()
|
||||||
|| (enemy.hitbox.y <= 0))) enemy.speed *= -1.0f;
|
|| (enemy.hitbox.y <= 0))) enemy.speed *= -1.0f;
|
||||||
|
|
||||||
if (CheckCollisionRecs(player.hitbox, enemy.hitbox)) {
|
if (CheckCollisionRecs(player.hitbox, enemy.hitbox)) DamagePlayer();
|
||||||
player.hp -= GetFrameTime() * 3.0f;
|
else player.currentframe = 0;
|
||||||
player.currentframe = 1;
|
|
||||||
} else player.currentframe = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
||||||
if (CheckCollisionRecs(player.hitbox, fireworks[i].hitbox)) {
|
if (CheckCollisionRecs(player.hitbox, fireworks[i].hitbox)) DamagePlayer();
|
||||||
player.hp -= GetFrameTime() * 3.0f;
|
|
||||||
player.currentframe = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (fireworks[i].hp) {
|
switch (fireworks[i].hp) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -232,21 +265,23 @@ void DrawGameplayScreen(void)
|
||||||
if (DebugMode) {
|
if (DebugMode) {
|
||||||
DrawRectangleRec(player.hitbox, BLUE);
|
DrawRectangleRec(player.hitbox, BLUE);
|
||||||
DrawRectangleRec(heart.hitbox, GREEN);
|
DrawRectangleRec(heart.hitbox, GREEN);
|
||||||
DrawText(TextFormat("enemy.hitbox.y: %f", enemy.hitbox.y), 10, 200, 20, RED);
|
DrawText(TextFormat("enemy.hitbox.y: %f", enemy.hitbox.y), 10, 200, 20, GREEN);
|
||||||
DrawText(TextFormat("player.hitbox.y: %f", player.hitbox.y), 10, 230, 20, RED);
|
DrawText(TextFormat("player.hitbox.y: %f", player.hitbox.y), 10, 230, 20, GREEN);
|
||||||
DrawRectangleRec(enemy.hitbox, BLACK);
|
DrawRectangleRec(enemy.hitbox, BLACK);
|
||||||
DrawText(TextFormat("firework_sprite.width: %d", firework_sprite.width), 10, 270, 20, RED);
|
DrawText(TextFormat("firework_sprite.width: %d", firework_sprite.width), 10, 270, 20, GREEN);
|
||||||
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
||||||
DrawText(TextFormat("fireworks[i].hp: %d", fireworks[i].hp), 10, 250, 20, RED);
|
DrawText(TextFormat("fireworks[i].hp: %d", fireworks[i].hp), 10, 250, 20, GREEN);
|
||||||
DrawRectangleRec(fireworks[i].hitbox, BLACK);
|
DrawRectangleRec(fireworks[i].hitbox, BLACK);
|
||||||
}
|
}
|
||||||
|
DrawText(TextFormat("player_iframeTimer: %d", player_iframeTimer), 10, 300, 20, GREEN);
|
||||||
|
DrawText(TextFormat("player_in: %d", player_in), 10, 320, 20, GREEN);
|
||||||
}
|
}
|
||||||
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);
|
||||||
DrawTexture(enemy_sprite, enemy.sprite_pos.x, enemy.sprite_pos.y, RAYWHITE);
|
DrawTexture(enemy_sprite, enemy.sprite_pos.x, enemy.sprite_pos.y, enemy.color);
|
||||||
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
for (int i = 0; i < MAX_FIREWORKS; i++) {
|
||||||
DrawTexture(firework_sprite, fireworks[i].sprite_pos.x, fireworks[i].sprite_pos.y, RAYWHITE);
|
DrawTexture(firework_sprite, fireworks[i].sprite_pos.x, fireworks[i].sprite_pos.y, fireworks[i].color);
|
||||||
}
|
}
|
||||||
DrawTextureRec(player_sprite, player.frameRec, player.sprite_pos, RAYWHITE);
|
DrawTextureRec(player_sprite, player.frameRec, player.sprite_pos, player.color);
|
||||||
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);
|
||||||
if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, PURPLE);
|
if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, PURPLE);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define GAMEPLAY_HEADER
|
#define GAMEPLAY_HEADER
|
||||||
|
|
||||||
#define MAX_FIREWORKS 10
|
#define MAX_FIREWORKS 10
|
||||||
|
#define MAX_PLAYER_HP 5
|
||||||
|
|
||||||
struct Actor {
|
struct Actor {
|
||||||
float speed;
|
float speed;
|
||||||
|
@ -18,6 +19,7 @@ struct Actor {
|
||||||
Vector2 sprite_pos;
|
Vector2 sprite_pos;
|
||||||
Rectangle frameRec;
|
Rectangle frameRec;
|
||||||
Rectangle hitbox;
|
Rectangle hitbox;
|
||||||
|
Color color;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Item {
|
struct Item {
|
||||||
|
@ -30,10 +32,11 @@ struct Actor player = { 0 };
|
||||||
struct Actor enemy = { 0 };
|
struct Actor enemy = { 0 };
|
||||||
struct Actor fireworks[MAX_FIREWORKS] = { 0 };
|
struct Actor fireworks[MAX_FIREWORKS] = { 0 };
|
||||||
struct Item heart = { 0 };
|
struct Item heart = { 0 };
|
||||||
int pauseTimer;
|
|
||||||
Sound fxbounce = { 0 };
|
Sound fxbounce = { 0 };
|
||||||
bool pause;
|
bool pause;
|
||||||
bool mute;
|
bool mute;
|
||||||
|
bool player_in;
|
||||||
|
|
||||||
bool DebugMode;
|
bool DebugMode;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
16
src/Timers.h
Normal file
16
src/Timers.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
- Avoid ~ a game by Canneddonuts
|
||||||
|
- Filename ~ Timers.h
|
||||||
|
- Author ~ Return0ne
|
||||||
|
- 2022
|
||||||
|
- *no license*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TIMERS_HEADER
|
||||||
|
#define TIMERS_HEADER
|
||||||
|
|
||||||
|
int pauseTimer;
|
||||||
|
int player_iframeTimer;
|
||||||
|
int player_flashtimer;
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue