diff --git a/.DS_Store b/.DS_Store index 38d0e2c..513f252 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/gfx/bothPipes.png b/gfx/bothPipes.png new file mode 100644 index 0000000..4c996ee Binary files /dev/null and b/gfx/bothPipes.png differ diff --git a/gfx/sprites.t3s b/gfx/sprites.t3s index 0b0469d..3d5b8f5 100644 --- a/gfx/sprites.t3s +++ b/gfx/sprites.t3s @@ -5,4 +5,5 @@ floor.png logo.png pipeBottom.png pipeTop.png -scoreCardBig.png \ No newline at end of file +scoreCardBig.png +bothPipes.png \ No newline at end of file diff --git a/romfs/gfx/sprites.t3x b/romfs/gfx/sprites.t3x index 1af748c..746959f 100644 Binary files a/romfs/gfx/sprites.t3x and b/romfs/gfx/sprites.t3x differ diff --git a/source/Sprite.cpp b/source/Sprite.cpp index 27882b4..afa8e98 100644 --- a/source/Sprite.cpp +++ b/source/Sprite.cpp @@ -3,21 +3,21 @@ Sprite::Sprite() { // C2D_SpriteSetCenter(&this->spr, 0.5f, 0.5f); // C2D_SpriteSetPos(&this->spr, 400/2, 240/2); - this->x = 200; this->y = 120; this->spr = new C2D_Sprite; + this->x = 200; this->y = 120; } Sprite::Sprite(C2D_Sprite* spr, float x, float y) { - this->x = x; this->y = y; this->spr = spr; + this->x = x; this->y = y; this->spr = *spr; - C2D_SpriteSetCenter(this->spr, 0.5f, 0.5f); - C2D_SpriteSetPos(this->spr, x, y); + C2D_SpriteSetCenter(&this->spr, 0.5f, 0.5f); + C2D_SpriteSetPos(&this->spr, x, y); } void Sprite::setPosition(float x, float y) { this->x = x; this->y = y; - C2D_SpriteSetPos(this->spr, x, y); + C2D_SpriteSetPos(&this->spr, x, y); } void Sprite::move(float dx, float dy, bool overrideOOB) { @@ -33,15 +33,15 @@ void Sprite::move(float dx, float dy, bool overrideOOB) { this->x += dx; this->y += dy; - C2D_SpriteSetPos(this->spr, this->x, this->y); + C2D_SpriteSetPos(&this->spr, this->x, this->y); } void Sprite::setCenter(float x, float y) { - C2D_SpriteSetCenter(this->spr, x, y); + C2D_SpriteSetCenter(&this->spr, x, y); } void Sprite::draw() { - C2D_DrawSprite(this->spr); + C2D_DrawSprite(&this->spr); } float Sprite::getPosX() { @@ -53,9 +53,9 @@ float Sprite::getPosY() { } C2D_Sprite* Sprite::getSpr() { - return this->spr; + return &this->spr; } void Sprite::setSpr(C2D_Sprite* newSpr) { - this->spr = newSpr; + this->spr = *newSpr; } \ No newline at end of file diff --git a/source/Sprite.hpp b/source/Sprite.hpp index f6cd8dd..150efd1 100644 --- a/source/Sprite.hpp +++ b/source/Sprite.hpp @@ -27,7 +27,7 @@ public: void setSpr(C2D_Sprite* newSpr); - C2D_Sprite* spr; + C2D_Sprite spr; private: float x, y; diff --git a/source/SpriteList.h b/source/SpriteList.h index aec0959..b681bee 100644 --- a/source/SpriteList.h +++ b/source/SpriteList.h @@ -12,5 +12,6 @@ #define SPR_PIPETOP 5 #define SPR_SCORECARD 6 +#define SPR_BOTHPIPES 7 #endif \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 1fe35ca..b6bcaf0 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include "Sprite.hpp" @@ -15,13 +16,15 @@ #define MAX_SPRITES 768 #define SCREEN_WIDTH 400 #define SCREEN_HEIGHT 240 - +#define NUM_PIPES 5 // init spritesheet static C2D_SpriteSheet spriteSheet; Sprite sprites[MAX_SPRITES]; +Sprite pipes[NUM_PIPES]; static void initSprites() { + srand(time(NULL)); size_t numImages = C2D_SpriteSheetCount(spriteSheet); for (size_t i = 0; i < numImages; i++) { @@ -29,14 +32,13 @@ static void initSprites() { float x = SCREEN_WIDTH / 2; float y = SCREEN_HEIGHT / 2; - C2D_SpriteFromSheet(thisSprite->spr, spriteSheet, i); - C2D_SpriteSetCenter(thisSprite->spr, 0.5f, 0.5f); + C2D_SpriteFromSheet(&thisSprite->spr, spriteSheet, i); + C2D_SpriteSetCenter(&thisSprite->spr, 0.5f, 0.5f); thisSprite->setPosition(x, y); } // set bird consts sprites[SPR_BIRD].setPosition(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 3); - // set bottom screen scorecard sprites[SPR_SCORECARD].setCenter(0.0, 0.0); @@ -45,6 +47,13 @@ static void initSprites() { sprites[SPR_PIPETOP].setPosition(280, 3); sprites[SPR_PIPEBOTTOM].setPosition(280, 280); + + // if theres a better way to do this,,, i dont know it + for (int i = 0; i < NUM_PIPES; i++) { + memcpy(&pipes[i], &sprites[SPR_BOTHPIPES], sizeof(sprites[SPR_BOTHPIPES])); + pipes[i].setCenter(0.5f, 0.5f); + pipes[i].setPosition(SCREEN_WIDTH + 8*i, rand() % SCREEN_HEIGHT + 20); + } } @@ -88,7 +97,7 @@ int main(int argc, char* argv[]) { // set bg properties sprites[SPR_BG].setPosition(200, 120); - C2D_SpriteSetScale(sprites[SPR_BG].spr, 2.7778, 2.7907); // scale image to 400x240 (3ds screen res) + C2D_SpriteSetScale(&sprites[SPR_BG].spr, 2.7778, 2.7907); // scale image to 400x240 (3ds screen res) size_t score = 0; @@ -105,7 +114,7 @@ int main(int argc, char* argv[]) { // 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, v*9.8); @@ -116,14 +125,16 @@ int main(int argc, char* argv[]) { score++; } - sprites[SPR_PIPETOP].move(pipeSpeed, 0, true); - sprites[SPR_PIPEBOTTOM].move(pipeSpeed, 0, true); + for (int i = 0; i < NUM_PIPES; i++) { + pipes[i].move(pipeSpeed, 0, true); - if (sprites[SPR_PIPETOP].getPosX() < -10) { - sprites[SPR_PIPETOP].setPosition(SCREEN_WIDTH, 3); - sprites[SPR_PIPEBOTTOM].setPosition(SCREEN_WIDTH, 280); + if (pipes[i].getPosX() < -10) { + pipes[i].setPosition(SCREEN_WIDTH, rand() % SCREEN_HEIGHT); + } } + + // make score text char scoreString[(((sizeof score) * CHAR_BIT) + 2)/3 + 2]; sprintf(scoreString, "%d", score); @@ -138,8 +149,9 @@ int main(int argc, char* argv[]) { sprites[SPR_BG].draw(); sprites[SPR_BIRD].draw(); - sprites[SPR_PIPETOP].draw(); - sprites[SPR_PIPEBOTTOM].draw(); + for (int i = 0; i < NUM_PIPES; i++) { + pipes[i].draw(); + } C2D_TargetClear(bottom, C2D_Color32f(0.3294f, 0.7529f, 0.7882f, 1.0f)); C2D_SceneBegin(bottom);