added stats to level select and better firework amounts

This commit is contained in:
Return0ne 2022-09-25 12:25:31 -04:00
parent 3537a6d37e
commit b4b53ddedd
4 changed files with 50 additions and 35 deletions

View File

@ -12,15 +12,26 @@
#include "Controls.h"
#include "Options.h"
#include "Gameplay.h"
#include "Score.h"
#include "Stats.h"
#include "Timers.h"
#include "Music.h"
#include "Gfx.h"
int score = 0, bestscore = 0, finishfromGameplayScreen = 0;
int score = 0, bestscore = 0, finishfromGameplayScreen = 0, redfeathers = 0, greenfeathers = 0;
Music Gameplaysong = { 0 };
bool CheckFireworkActivity(void)
{
int matches = 0, val = 0;
for (int i = 0; i < MAX_FIREWORKS; i++) {
if (fireworks[i].active == val) matches++;
}
if (matches == MAX_FIREWORKS) return true;
else return false;
}
void LoadGamplayScreen(void)
{
player.fxhit = LoadSound("assets/sfx/hit.wav");
@ -95,13 +106,19 @@ void InitGameplayScreen(void)
feather.power = 0;
for (int i = 0; i < MAX_FIREWORKS; i++) {
fireworks[i].active = 0;
fireworks[i].active = 1;
fireworks[i].hitbox = (Rectangle) {
630,
GetRandomValue(0, GetScreenHeight()),
GetScreenWidth() + firework_sprite.width,
0,
(float) firework_sprite.width/2 + 10,
(float) firework_sprite.height
};
fireworks[i].hitbox.y = GetRandomValue(0, GetScreenHeight() - firework_sprite.height);
switch (level) {
case LEVEL1: fireworks[i].speed.x = GetRandomValue(100, 300); break;
case LEVEL2: fireworks[i].speed.x = GetRandomValue(400, 600); break;
case LEVEL3: fireworks[i].speed.x = GetRandomValue(800, 1000); break;
}
fireworks[i].color = RAYWHITE;
}
@ -117,13 +134,16 @@ void InitGameplayScreen(void)
shoot[i].active = false;
shoot[i].color = RED;
}
fireworkAmount = 100;
switch (level) {
case LEVEL1: fireworkAmount = 50; break;
case LEVEL2: fireworkAmount = 200; break;
case LEVEL3: fireworkAmount = 500; break;
}
pause = 0;
DebugMode = 0;
pauseTimer = 0;
score = 0;
scoreTimer = 0;
GI_callcount++;
}
@ -169,12 +189,11 @@ void ResetFeather(void)
}
void UpdateGameplayScreen(void)
{
if (INPUT_OPTION_PRESSED) pause = !pause;
// code to end the game
if (level > 2) { StopMusicStream(Gameplaysong); finishfromGameplayScreen = 3; }
if (fireworkAmount < 1 && level < 2) { StopMusicStream(Gameplaysong); levelunlocked++; finishfromGameplayScreen = 4; }
if (CheckFireworkActivity() && level < 2) { StopMusicStream(Gameplaysong); levelunlocked++; finishfromGameplayScreen = 4; }
if (!mute) UpdateMusicStream(Gameplaysong);
@ -231,7 +250,8 @@ void UpdateGameplayScreen(void)
// pass the address of each struct to the UpdateiFrameTimer function
UpdateiFrameTimer(&player);
UpdateiFrameTimer(&enemy);
if (score >= bestscore) bestscore = score;
greenfeathers = player.hp;
redfeathers = ammo;
// Debug stuff
if (IsKeyPressed(KEY_D)) DebugMode = !DebugMode;
@ -311,7 +331,7 @@ void UpdateGameplayScreen(void)
case 0:
fireworks[i].hitbox.x = GetScreenWidth() + firework_sprite.width;
fireworks[i].active = 1;
if (fireworkAmount > 0) { fireworkAmount--; fireworks[i].active = 1; }
fireworks[i].hitbox.y = GetRandomValue(0, GetScreenHeight() - firework_sprite.height);
switch (level) {
case LEVEL1: fireworks[i].speed.x = GetRandomValue(100, 300); break;
@ -323,7 +343,7 @@ void UpdateGameplayScreen(void)
fireworks[i].hitbox.x += GetFrameTime() * -fireworks[i].speed.x;
// Firework wall collision
if (((fireworks[i].hitbox.x + -firework_sprite.width) > GetScreenWidth()
|| (fireworks[i].hitbox.x <= -firework_sprite.width))) { fireworkAmount--; fireworks[i].active = 0; }
|| (fireworks[i].hitbox.x <= -firework_sprite.width))) fireworks[i].active = 0;
break;
}
}
@ -371,8 +391,8 @@ void DrawGameplayScreen(void)
DrawText(TextFormat("= %i", player.hp), 30, 30, 30, GREEN);
DrawTexture(feather_sprite, 80, 0, RED);
DrawText(TextFormat("= %i", ammo), 110, 30, 30, RED);
if (level == 2) DrawText(TextFormat("ENEMY HP: %i", enemy.hp), GetScreenWidth() - 200, 0, 30, RED);
else DrawText(TextFormat("FIREWORKS LEFT: %i", fireworkAmount), GetScreenWidth() - 260, 0, 20, GREEN);
if (level == 2) DrawText(TextFormat("ENEMY HP: %i", enemy.hp), GetScreenWidth() - 380, 0, 20, RED);
DrawText(TextFormat("FIREWORKS LEFT: %i", fireworkAmount), GetScreenWidth() - 240, 0, 20, GREEN);
if (score >= 10000) DrawText(TextFormat("SCORE: %i", score), 10, 65, 30, (Color){ 222, 181, 0, 255 });
else DrawText(TextFormat("SCORE: %i", score), 10, 65, 30, BLUE);
if (pause && (((int)pauseTimer/30)%2)) DrawTextEx(ZadoBold, "PAUSED", (Vector2){ 280, 160 }, 60, 2, WHITE);

View File

@ -9,6 +9,7 @@
#include "../include/raylib.h"
#include "Screens.h"
#include "Stats.h"
#include "Controls.h"
#include "Gfx.h"
@ -16,6 +17,7 @@ int finishfromLevelSelScreen = 0, levelSelected = 1, levelunlocked = 0;
void InitLevelSelScreen(void)
{
feather_sprite = LoadTexture("assets/gfx/feather.png");
finishfromLevelSelScreen = 0;
}
@ -35,6 +37,13 @@ void DrawLevelSelScreen(void)
{
DrawTexture(background, 0, 0, GRAY);
DrawTexture(feather_sprite, 0, 0, GREEN);
DrawText(TextFormat("= %i", greenfeathers), 30, 30, 30, GREEN);
DrawTexture(feather_sprite, 80, 0, RED);
DrawText(TextFormat("= %i", redfeathers), 110, 30, 30, RED);
if (score >= 10000) DrawText(TextFormat("SCORE: %i", score), 10, 65, 30, (Color){ 222, 181, 0, 255 });
else DrawText(TextFormat("SCORE: %i", score), 10, 65, 30, BLUE);
if (levelSelected == 1) DrawText("1", 100, 220, 30, WHITE);
else DrawText("1", 100, 220, 30, BLUE);
@ -49,6 +58,7 @@ void DrawLevelSelScreen(void)
void UnloadLevelSelScreen(void)
{
UnloadTexture(feather_sprite);
}
int FinishLevelSelScreen(void)

View File

@ -1,15 +1,16 @@
/*
- Avoid ~ a game by Canneddonuts
- Filename ~ Score.h
- Filename ~ Stats.h
- Author ~ Return0ne
- 2022
- *no license*
*/
#ifndef SCORE_HEADER
#define SCORE_HEADER
#ifndef STATS_HEADER
#define STATS_HEADER
extern int bestscore;
extern int score;
extern int greenfeathers;
extern int redfeathers;
#endif

View File

@ -12,26 +12,11 @@
#include "Controls.h"
#include "Music.h"
#include "Options.h"
#include "Score.h"
#include "Gfx.h"
int titleSelected = 0, finishfromTitleScreen = 0;
Music Titlesong = { 0 };
void DrawScore(void)
{
if (bestscore >= 10000)
DrawText(TextFormat("BEST: %i", bestscore), 580, 0, 30, (Color){ 222, 181, 0, 255 });
else if (bestscore >= 5000)
DrawText(TextFormat("BEST: %i", bestscore), 580, 0, 30, (Color){ 149, 148, 147, 255 });
else if (bestscore >= 1000)
DrawText(TextFormat("BEST: %i", bestscore), 580, 0, 30,(Color){ 138, 72, 4, 255 });
else
DrawText(TextFormat("BEST: %i", bestscore), 580, 0, 30, BLUE);
}
void InitTitleScreen(void)
{
titleSelected = 0;
@ -58,7 +43,6 @@ void DrawTitleScreen(void)
DrawTexture(background, 0, 0, GRAY);
DrawTextEx(ZadoBold, "Avoid", (Vector2){ 300, 0 }, 80, 5, BLUE);
DrawText("Controls", 5, 10, 30, BLUE);
DrawScore();
DrawText("Press the arrow keys or 'DPAD' to move and 'X' to dash", 5, 40, 10, WHITE);
DrawText("Press 'ENTER' or 'START' to pause", 5, 60, 10, WHITE);
DrawText("Press 'M' to mute", 5, 80, 10, WHITE);