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
|
build
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.vscode
|
@ -33,6 +33,14 @@ void Level::run() {
|
|||||||
C3D_FrameEnd(0);
|
C3D_FrameEnd(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Level::exit() {
|
||||||
|
this->isActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Level::active() {
|
||||||
|
this->isActive;// && aptMainLoop();
|
||||||
|
}
|
||||||
|
|
||||||
void Level::cleanup() {
|
void Level::cleanup() {
|
||||||
C2D_SpriteSheetFree(spritesheet);
|
C2D_SpriteSheetFree(spritesheet);
|
||||||
}
|
}
|
@ -58,6 +58,7 @@ public:
|
|||||||
C3D_RenderTarget* bottom;
|
C3D_RenderTarget* bottom;
|
||||||
Level* level;
|
Level* level;
|
||||||
bool hasBeenSetup = false;
|
bool hasBeenSetup = false;
|
||||||
|
bool isActive = true;
|
||||||
|
|
||||||
virtual void setup() = 0;
|
virtual void setup() = 0;
|
||||||
virtual void update() = 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
|
// sets up the level if it hasnt been, then updates the logic, and draws the frame
|
||||||
void run();
|
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;
|
virtual void cleanup() = 0;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "Level.hpp"
|
#include "Level.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#define SPR_BIRD 0
|
#define SPR_BIRD 0
|
||||||
|
|
||||||
@ -70,15 +71,16 @@ struct MainLevel: Level {
|
|||||||
// Respond to user input
|
// Respond to user input
|
||||||
u32 kDown = hidKeysDown();
|
u32 kDown = hidKeysDown();
|
||||||
if (kDown & KEY_START)
|
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
|
// gravity calcs
|
||||||
v += a;
|
v += a;
|
||||||
sprites[SPR_BIRD].move(0, v);
|
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;
|
v = -5.5;
|
||||||
sprites[SPR_BIRD].move(0, v, true);
|
sprites[SPR_BIRD].move(0, v, true);
|
||||||
}
|
}
|
||||||
@ -88,15 +90,15 @@ struct MainLevel: Level {
|
|||||||
gameOver = true;
|
gameOver = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gameOver) {
|
// if (!gameOver) {
|
||||||
for (int i = 0; i < NUM_PIPES; i++) {
|
for (int i = 0; i < NUM_PIPES; i++) {
|
||||||
pipes[i].move(pipeSpeed, 0, true);
|
pipes[i].move(pipeSpeed, 0, true);
|
||||||
|
|
||||||
// collision detection
|
// collision detection
|
||||||
if (pipes[i].isCollidingWith(sprites[SPR_BIRD])) {
|
// if (pipes[i].isCollidingWith(sprites[SPR_BIRD])) {
|
||||||
gameOver = true;
|
// gameOver = true;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// inc score
|
// inc score
|
||||||
if (pipes[i].getPosX() == sprites[SPR_BIRD].getPosX())
|
if (pipes[i].getPosX() == sprites[SPR_BIRD].getPosX())
|
||||||
@ -107,13 +109,13 @@ struct MainLevel: Level {
|
|||||||
pipes[i].setPosition(SCREEN_WIDTH, (rand() % 150) + 50);
|
pipes[i].setPosition(SCREEN_WIDTH, (rand() % 150) + 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
|
|
||||||
// make score text
|
// make score text
|
||||||
// char scoreString[(((sizeof score) * CHAR_BIT) + 2)/3 + 2];
|
char scoreString[(((sizeof score) * 8) + 2)/3 + 2];
|
||||||
// sprintf(scoreString, "%d", score);
|
sprintf(scoreString, "%d", score);
|
||||||
// C2D_TextFontParse(&scoreText, font, g_staticBuf, scoreString);
|
C2D_TextFontParse(&scoreText, font, g_staticBuf, scoreString);
|
||||||
// C2D_TextOptimize(&scoreText);
|
C2D_TextOptimize(&scoreText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTop() {
|
void drawTop() {
|
||||||
@ -127,7 +129,7 @@ struct MainLevel: Level {
|
|||||||
|
|
||||||
void drawBottom() {
|
void drawBottom() {
|
||||||
sprites[SPR_SCORECARD].draw();
|
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() {
|
void cleanup() {
|
||||||
|
@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
|
|||||||
level = game;
|
level = game;
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (aptMainLoop()) {
|
while (aptMainLoop() && level->isActive) {
|
||||||
level->run();
|
level->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user