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:
pradyun 2023-09-16 15:11:27 +12:00
parent 1c39d3bba0
commit 9795b38e9e
6 changed files with 34 additions and 16 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
build
.DS_Store
.vscode

View File

@ -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);
}

View File

@ -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

View File

@ -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() {

View File

@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
level = game;
// Main loop
while (aptMainLoop()) {
while (aptMainLoop() && level->isActive) {
level->run();
}

View File

@ -1,2 +1,2 @@
# need to have ftpd open for this
curl -T B2DFlappy3DS.3dsx ftp://192.168.88.131:5000/3ds/
curl -T Flappy3DS.3dsx ftp://192.168.88.131:5000/3ds/