diff --git a/.gitignore b/.gitignore index 2c7c6d5..f9034c5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build .DS_Store +.vscode \ No newline at end of file diff --git a/include/Level.cpp b/include/Level.cpp index 6114eca..6d48f09 100644 --- a/include/Level.cpp +++ b/include/Level.cpp @@ -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); } \ No newline at end of file diff --git a/include/Level.hpp b/include/Level.hpp index b14574c..f2ef9ce 100644 --- a/include/Level.hpp +++ b/include/Level.hpp @@ -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 diff --git a/source/MainLevel.cpp b/source/MainLevel.cpp index 83bf2cb..110773a 100644 --- a/source/MainLevel.cpp +++ b/source/MainLevel.cpp @@ -1,4 +1,5 @@ #include "Level.hpp" +#include #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() { diff --git a/source/main.cpp b/source/main.cpp index cee14dc..fd3f81e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -31,7 +31,7 @@ int main(int argc, char* argv[]) { level = game; // Main loop - while (aptMainLoop()) { + while (aptMainLoop() && level->isActive) { level->run(); } diff --git a/upload.sh b/upload.sh index 32d1c0b..b2561ae 100755 --- a/upload.sh +++ b/upload.sh @@ -1,2 +1,2 @@ # need to have ftpd open for this -curl -T B2DFlappy3DS.3dsx ftp://192.168.88.131:5000/3ds/ \ No newline at end of file +curl -T Flappy3DS.3dsx ftp://192.168.88.131:5000/3ds/ \ No newline at end of file