engine: added method to close level from within
removed collision detection for now bird no longer rotates indefinitely when falling
This commit is contained in:
parent
1c39d3bba0
commit
9795b38e9e
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
|
||||
build
|
||||
.DS_Store
|
||||
.vscode
|
@ -33,6 +33,14 @@ void Level::run() {
|
||||
C3D_FrameEnd(0);
|
||||
}
|
||||
|
||||
void Level::exit() {
|
||||
this->isActive = false;
|
||||
}
|
||||
|
||||
bool Level::active() {
|
||||
this->isActive;// && aptMainLoop();
|
||||
}
|
||||
|
||||
void Level::cleanup() {
|
||||
C2D_SpriteSheetFree(spritesheet);
|
||||
}
|
@ -58,6 +58,7 @@ public:
|
||||
C3D_RenderTarget* bottom;
|
||||
Level* level;
|
||||
bool hasBeenSetup = false;
|
||||
bool isActive = true;
|
||||
|
||||
virtual void setup() = 0;
|
||||
virtual void update() = 0;
|
||||
@ -70,6 +71,12 @@ public:
|
||||
// sets up the level if it hasnt been, then updates the logic, and draws the frame
|
||||
void run();
|
||||
|
||||
// stops the current level, mostly to be used to exit to hbmenu (see examples)
|
||||
void exit();
|
||||
|
||||
// returns the status of the level, whether it's been exited or not
|
||||
bool active();
|
||||
|
||||
virtual void cleanup() = 0;
|
||||
};
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "Level.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
#define SPR_BIRD 0
|
||||
|
||||
@ -70,15 +71,16 @@ struct MainLevel: Level {
|
||||
// Respond to user input
|
||||
u32 kDown = hidKeysDown();
|
||||
if (kDown & KEY_START)
|
||||
svcBreak(USERBREAK_USER); // break in order to return to hbmenu
|
||||
// svcExitProcess(); // break in order to return to hbmenu
|
||||
this->exit();
|
||||
|
||||
|
||||
// gravity calcs
|
||||
v += a;
|
||||
sprites[SPR_BIRD].move(0, v);
|
||||
C2D_SpriteSetRotationDegrees(&sprites[SPR_BIRD].spr, v*9.8);
|
||||
C2D_SpriteSetRotationDegrees(&sprites[SPR_BIRD].spr, std::min(v*9.8, 90.0));
|
||||
|
||||
if (!gameOver && (kDown & KEY_A)) {
|
||||
if (kDown & KEY_A) {
|
||||
v = -5.5;
|
||||
sprites[SPR_BIRD].move(0, v, true);
|
||||
}
|
||||
@ -88,15 +90,15 @@ struct MainLevel: Level {
|
||||
gameOver = true;
|
||||
}
|
||||
|
||||
if (!gameOver) {
|
||||
// if (!gameOver) {
|
||||
for (int i = 0; i < NUM_PIPES; i++) {
|
||||
pipes[i].move(pipeSpeed, 0, true);
|
||||
|
||||
// collision detection
|
||||
if (pipes[i].isCollidingWith(sprites[SPR_BIRD])) {
|
||||
gameOver = true;
|
||||
break;
|
||||
}
|
||||
// if (pipes[i].isCollidingWith(sprites[SPR_BIRD])) {
|
||||
// gameOver = true;
|
||||
// break;
|
||||
// }
|
||||
|
||||
// inc score
|
||||
if (pipes[i].getPosX() == sprites[SPR_BIRD].getPosX())
|
||||
@ -107,13 +109,13 @@ struct MainLevel: Level {
|
||||
pipes[i].setPosition(SCREEN_WIDTH, (rand() % 150) + 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
// make score text
|
||||
// char scoreString[(((sizeof score) * CHAR_BIT) + 2)/3 + 2];
|
||||
// sprintf(scoreString, "%d", score);
|
||||
// C2D_TextFontParse(&scoreText, font, g_staticBuf, scoreString);
|
||||
// C2D_TextOptimize(&scoreText);
|
||||
char scoreString[(((sizeof score) * 8) + 2)/3 + 2];
|
||||
sprintf(scoreString, "%d", score);
|
||||
C2D_TextFontParse(&scoreText, font, g_staticBuf, scoreString);
|
||||
C2D_TextOptimize(&scoreText);
|
||||
}
|
||||
|
||||
void drawTop() {
|
||||
@ -127,7 +129,7 @@ struct MainLevel: Level {
|
||||
|
||||
void drawBottom() {
|
||||
sprites[SPR_SCORECARD].draw();
|
||||
// C2D_DrawText(&scoreText, 0, 240, 88, 0.0f, 0.9f, 0.9f);
|
||||
C2D_DrawText(&scoreText, 0, 240, 88, 0.0f, 0.9f, 0.9f);
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
|
@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
|
||||
level = game;
|
||||
|
||||
// Main loop
|
||||
while (aptMainLoop()) {
|
||||
while (aptMainLoop() && level->isActive) {
|
||||
level->run();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user