diff --git a/source/Sprite.cpp b/source/Sprite.cpp index ce05d69..e2763fd 100644 --- a/source/Sprite.cpp +++ b/source/Sprite.cpp @@ -1,4 +1,4 @@ -#include "Sprite.h" +#include "Sprite.hpp" Sprite::Sprite() { // C2D_SpriteSetCenter(&this->spr, 0.5f, 0.5f); @@ -20,10 +20,15 @@ void Sprite::setPosition(float x, float y) { C2D_SpriteSetPos(this->spr, x, y); } -void Sprite::move(float dx, float dy) { - if (this->x >= 400 || this->x < 1 || this->y >= 240 || this->x < 1) { - return; +void Sprite::move(float dx, float dy, bool overrideOOB) { + if (!overrideOOB) { + // make sure translate doesnt move to OOB + const float newX = this->x + dx; + const float newY = this->y + dy; + if (!((unsigned)(newX-1) <= 398 && (unsigned)(newY-1) <= 238)) { + return; } + } this->x += dx; this->y += dy; diff --git a/source/Sprite.h b/source/Sprite.hpp similarity index 87% rename from source/Sprite.h rename to source/Sprite.hpp index b6d87c3..f6cd8dd 100644 --- a/source/Sprite.h +++ b/source/Sprite.hpp @@ -13,7 +13,7 @@ public: void setPosition(float x, float y); - void move(float dx, float dy); + void move(float dx, float dy, bool overrideOOB=false); void setCenter(float x, float y); diff --git a/source/main.cpp b/source/main.cpp index 8c4f1b0..e91a14a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -8,7 +8,7 @@ #include #include -#include "Sprite.h" +#include "Sprite.hpp" #include "SpriteList.h" @@ -43,8 +43,8 @@ static void initSprites() { sprites[SPR_SCORECARD].setPosition(2, 40); - sprites[SPR_PIPETOP].setPosition(280, 14); - sprites[SPR_PIPEBOTTOM].setPosition(280, 200); + sprites[SPR_PIPETOP].setPosition(280, 3); + sprites[SPR_PIPEBOTTOM].setPosition(280, 280); } @@ -106,8 +106,8 @@ int main(int argc, char* argv[]) { sprites[SPR_BIRD].move(0, v); C2D_SpriteSetRotationDegrees(sprites[SPR_BIRD].spr, v*9.8); - sprites[SPR_PIPETOP].move(-0.2, 0); - sprites[SPR_PIPEBOTTOM].move(-0.2, 0); + sprites[SPR_PIPETOP].move(-3, 0, true); + sprites[SPR_PIPEBOTTOM].move(-3, 0, true); if (kDown & KEY_A) { v = -5.5; @@ -128,13 +128,11 @@ int main(int argc, char* argv[]) { C3D_FrameBegin(C3D_FRAME_SYNCDRAW); C2D_TargetClear(top, C3D_CLEAR_COLOR); C2D_SceneBegin(top); - // drawSprite(SPR_BG); - // drawSprite(SPR_BIRD); sprites[SPR_BG].draw(); sprites[SPR_BIRD].draw(); - // drawSprite(SPR_PIPEBOTTOM); - // drawSprite(SPR_PIPETOP); + sprites[SPR_PIPETOP].draw(); + sprites[SPR_PIPEBOTTOM].draw(); C2D_TargetClear(bottom, C2D_Color32f(0.3294f, 0.7529f, 0.7882f, 1.0f)); C2D_SceneBegin(bottom);