mirror of
https://github.com/joel16/PSPickr.git
synced 2024-11-26 21:10:27 +00:00
game: Hide boxes after 5 seconds if no input is made (for difficulty)
This commit is contained in:
parent
5b699ed1cd
commit
ff0ce13d05
7
include/timer.hpp
Normal file
7
include/timer.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace Timer {
|
||||
void Init(void);
|
||||
void Reset(void);
|
||||
float Get(void);
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include "fs.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "textures.hpp"
|
||||
#include "timer.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace Game {
|
||||
@ -12,6 +13,18 @@ namespace Game {
|
||||
static bool pattern[16];
|
||||
static unsigned int color[3];
|
||||
|
||||
static const g2dColor CLEAR_COLOUR = G2D_RGBA(245, 245, 245, 255);
|
||||
static const g2dColor TITLE_COLOUR = G2D_RGBA(175, 175, 175, 255);
|
||||
static const g2dColor TITLE_COLOUR2 = G2D_RGBA(236, 143, 140, 255);
|
||||
static const g2dColor FONT_COLOUR = G2D_RGBA(145, 145, 145, 255);
|
||||
static const g2dColor INSTR_BOX_COLOUR1 = G2D_RGBA(88, 163, 229, 255);
|
||||
static const g2dColor INSTR_BOX_COLOUR2 = G2D_RGBA(151, 147, 231, 255);
|
||||
static const g2dColor TINT_COLOUR = G2D_RGBA(50, 50, 50, 200);
|
||||
static const g2dColor HIGHLIGHT_COLOUR = G2D_RGBA(0, 0, 0, 255);
|
||||
static const g2dColor TIMER_COLOUR_HEALTHY = G2D_RGBA(0, 255, 0, 255);
|
||||
static const g2dColor TIMER_COLOUR_UNHEALTHY = G2D_RGBA(255, 0, 0, 255);
|
||||
static const g2dColor TRANSPARENT_BG_COLOUR = G2D_RGBA(0, 0, 0, 100);
|
||||
|
||||
void MainMenu(void) {
|
||||
const std::string subtitle_0 = "One of these colours is not like the other one!";
|
||||
const std::string subtitle_1 = "Which one?";
|
||||
@ -20,20 +33,26 @@ namespace Game {
|
||||
const std::string instruc_2 = "Press Start to exit";
|
||||
const std::string text = "Based on Sean M. Tracey's Pickr";
|
||||
|
||||
g2dClear(WHITE);
|
||||
GUI::FontSetStyle(1.2f, G2D_RGBA(0, 0, 0, 0), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth("PSPickr")) / 2, 80, "PSPickr");
|
||||
g2dClear(CLEAR_COLOUR);
|
||||
GUI::FontSetStyle(1.2f, TITLE_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth("PSPickr")) / 2, 70, "PSPickr");
|
||||
|
||||
GUI::FontSetStyle(1.0f, G2D_RGBA(0, 0, 0, 200), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::FontSetStyle(1.0f, FONT_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(subtitle_0)) / 2, 95, subtitle_0);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(subtitle_1)) / 2, 110, subtitle_1);
|
||||
|
||||
GUI::FontSetStyle(0.8f, G2D_RGBA(0, 0, 0, 200), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(instruc_0)) / 2, 140, instruc_0);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(instruc_1)) / 2, 160, instruc_1);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(instruc_2)) / 2, 180, instruc_2);
|
||||
GUI::FontSetStyle(1.0f, CLEAR_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
|
||||
GUI::FontSetStyle(0.8f, G2D_RGBA(0, 0, 0, 200), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawRect(((480 - GUI::GetTextWidth(instruc_0)) / 2) - 10, 120, GUI::GetTextWidth(instruc_0) + 20, 32, INSTR_BOX_COLOUR1);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(instruc_0)) / 2, 140, instruc_0);
|
||||
|
||||
GUI::DrawRect(((480 - GUI::GetTextWidth(instruc_1)) / 2) - 10, 160, GUI::GetTextWidth(instruc_1) + 20, 32, INSTR_BOX_COLOUR2);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(instruc_1)) / 2, 180, instruc_1);
|
||||
|
||||
GUI::FontSetStyle(1.0f, FONT_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(instruc_2)) / 2, 210, instruc_2);
|
||||
|
||||
GUI::FontSetStyle(0.8f, TITLE_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
intraFontPrintf(g_font, 10, 262, "Version %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);
|
||||
GUI::DrawText((470 - GUI::GetTextWidth(text)), 262, text);
|
||||
g2dFlip(G2D_VSYNC);
|
||||
@ -86,7 +105,7 @@ namespace Game {
|
||||
|
||||
static void Begin(bool timer) {
|
||||
int x, y;
|
||||
bool win = false, paused = false;
|
||||
bool win = false, paused = false, hide = false;
|
||||
|
||||
char stage_str[10], row_str[13];
|
||||
std::snprintf(stage_str, 10, "Score %d", stages);
|
||||
@ -95,8 +114,18 @@ namespace Game {
|
||||
time_left = 480;
|
||||
Game::Fill();
|
||||
diff = (rand() % 2) ? diff : -diff;
|
||||
Timer::Init();
|
||||
|
||||
while (true && time_left > 0 && lives > 0) {
|
||||
if ((!hide) && (Timer::Get() >= 5.f)) {
|
||||
hide = true;
|
||||
Timer::Reset();
|
||||
}
|
||||
else if (hide && Timer::Get() >= 0.5f) {
|
||||
hide = false;
|
||||
Timer::Reset();
|
||||
}
|
||||
|
||||
int ctrl = Utils::ReadControls();
|
||||
Utils::SetBounds(selection, 0, 15);
|
||||
|
||||
@ -132,18 +161,18 @@ namespace Game {
|
||||
}
|
||||
|
||||
y = 34;
|
||||
g2dClear(GRAY);
|
||||
g2dClear(CLEAR_COLOUR);
|
||||
|
||||
for (int i = 0, max = (lives < 5) ? 5 : lives; i < max; i++) {
|
||||
if (i < lives) {
|
||||
GUI::DrawImage(Textures::GetLives(), 5 + i * 13, 5, tex_size, tex_size);
|
||||
}
|
||||
else {
|
||||
GUI::DrawImageTint(Textures::GetLives(), 5 + i * 13, 5, tex_size, tex_size, G2D_RGBA(50, 50, 50, 200));
|
||||
GUI::DrawImageTint(Textures::GetLives(), 5 + i * 13, 5, tex_size, tex_size, TINT_COLOUR);
|
||||
}
|
||||
}
|
||||
|
||||
GUI::FontSetStyle(1.0f, G2D_RGBA(255, 255, 255, 255), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::FontSetStyle(1.0f, FONT_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((472 - GUI::GetTextWidth(stage_str)), 17, stage_str);
|
||||
GUI::DrawText((472 - GUI::GetTextWidth(row_str)), 35, row_str);
|
||||
|
||||
@ -152,10 +181,13 @@ namespace Game {
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (selection == (i * 4 + j)) {
|
||||
GUI::DrawRect(x - 1, y - 1, 52, 52, G2D_RGBA(255, 255, 255, 255));
|
||||
GUI::DrawRect(x - 1, y - 1, 52, 52, HIGHLIGHT_COLOUR);
|
||||
}
|
||||
|
||||
if (!hide || paused) {
|
||||
GUI::DrawRect(x, y, 50, 50, (pattern[i * 4 + j]) ? G2D_RGBA(color[0] - diff, color[1] - diff, color[2] - diff, 255) : G2D_RGBA(color[0], color[1], color[2], 255));
|
||||
}
|
||||
|
||||
x += 52;
|
||||
}
|
||||
|
||||
@ -163,16 +195,16 @@ namespace Game {
|
||||
}
|
||||
|
||||
if (timer) {
|
||||
GUI::DrawRect(0, 257, time_left, 15, (time_left > 100) ? G2D_RGBA(0, 255, 0, 255) : G2D_RGBA(255, 0, 0, 255));
|
||||
GUI::DrawRect(0, 257, time_left, 15, (time_left > 100) ? TIMER_COLOUR_HEALTHY : TIMER_COLOUR_UNHEALTHY);
|
||||
}
|
||||
|
||||
if (paused) {
|
||||
GUI::DrawRect(0, 0, 480, 282, G2D_RGBA(128, 128, 128, 130));
|
||||
GUI::DrawRect(0, 0, 480, 282, TRANSPARENT_BG_COLOUR);
|
||||
|
||||
GUI::FontSetStyle(1.0f, G2D_RGBA(200, 0, 0, 255), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((472 - GUI::GetTextWidth("Paused")) / 2, 100, "Paused");
|
||||
GUI::FontSetStyle(1.0f, TITLE_COLOUR2, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((472 - GUI::GetTextWidth("PAUSED")) / 2, 100, "PAUSED");
|
||||
|
||||
GUI::FontSetStyle(1.0f, G2D_RGBA(0, 0, 0, 255), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::FontSetStyle(1.0f, CLEAR_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((472 - GUI::GetTextWidth("Press start to continue")) / 2, 130, "Press start to continue");
|
||||
GUI::DrawText((472 - GUI::GetTextWidth(PSP_CTRL_CANCEL == PSP_CTRL_CIRCLE? "Press O button to exit" : "Press X button to exit")) / 2,
|
||||
150, PSP_CTRL_CANCEL == PSP_CTRL_CIRCLE? "Press O button to exit" : "Press X button to exit");
|
||||
@ -230,16 +262,19 @@ namespace Game {
|
||||
break;
|
||||
}
|
||||
|
||||
g2dClear(WHITE);
|
||||
GUI::FontSetStyle(1.5f, G2D_RGBA(200, 0, 0, 255), INTRAFONT_ALIGN_LEFT);
|
||||
g2dClear(CLEAR_COLOUR);
|
||||
|
||||
GUI::FontSetStyle(1.2f, TITLE_COLOUR2, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth("GAME OVER")) / 2, 40, "GAME OVER");
|
||||
|
||||
GUI::FontSetStyle(1.0f, G2D_RGBA(128, 128, 128, 255), INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(stages_str)) / 2, 80, stages_str);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(score_str)) / 2, 100, score_str);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(matches_str)) / 2, 120, matches_str);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth("Press X to try again")) / 2, 140, "Press X to try again");
|
||||
GUI::FontSetStyle(1.0f, CLEAR_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawRect(((480 - GUI::GetTextWidth("Press X to try again")) / 2) - 10, 60, GUI::GetTextWidth("Press X to try again") + 20, 32, INSTR_BOX_COLOUR1);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth("Press X to try again")) / 2, 80, "Press X to try again");
|
||||
|
||||
GUI::FontSetStyle(1.0f, FONT_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(stages_str)) / 2, 110, stages_str);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(score_str)) / 2, 130, score_str);
|
||||
GUI::DrawText((480 - GUI::GetTextWidth(matches_str)) / 2, 150, matches_str);
|
||||
|
||||
g2dFlip(G2D_VSYNC);
|
||||
}
|
||||
|
23
source/timer.cpp
Normal file
23
source/timer.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <pspkernel.h>
|
||||
#include <time.h>
|
||||
#include <psprtc.h>
|
||||
|
||||
namespace Timer {
|
||||
static u64 tick = 0;
|
||||
static u32 res = 0;
|
||||
|
||||
void Init(void) {
|
||||
res = sceRtcGetTickResolution();
|
||||
sceRtcGetCurrentTick(&tick);
|
||||
}
|
||||
|
||||
void Reset(void) {
|
||||
sceRtcGetCurrentTick(&tick);
|
||||
}
|
||||
|
||||
float Get(void) {
|
||||
u64 curr_tick = 0;
|
||||
sceRtcGetCurrentTick(&curr_tick);
|
||||
return (curr_tick - tick) * 1.0f / res;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user