there is a PIPE and it MOVES

This commit is contained in:
breadone 2023-03-11 16:56:28 +13:00
parent d9628233ce
commit 9ccb5007af
3 changed files with 17 additions and 14 deletions

View File

@ -1,4 +1,4 @@
#include "Sprite.h" #include "Sprite.hpp"
Sprite::Sprite() { Sprite::Sprite() {
// C2D_SpriteSetCenter(&this->spr, 0.5f, 0.5f); // 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); C2D_SpriteSetPos(this->spr, x, y);
} }
void Sprite::move(float dx, float dy) { void Sprite::move(float dx, float dy, bool overrideOOB) {
if (this->x >= 400 || this->x < 1 || this->y >= 240 || this->x < 1) { if (!overrideOOB) {
return; // 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->x += dx;
this->y += dy; this->y += dy;

View File

@ -13,7 +13,7 @@ public:
void setPosition(float x, float y); 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); void setCenter(float x, float y);

View File

@ -8,7 +8,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include "Sprite.h" #include "Sprite.hpp"
#include "SpriteList.h" #include "SpriteList.h"
@ -43,8 +43,8 @@ static void initSprites() {
sprites[SPR_SCORECARD].setPosition(2, 40); sprites[SPR_SCORECARD].setPosition(2, 40);
sprites[SPR_PIPETOP].setPosition(280, 14); sprites[SPR_PIPETOP].setPosition(280, 3);
sprites[SPR_PIPEBOTTOM].setPosition(280, 200); sprites[SPR_PIPEBOTTOM].setPosition(280, 280);
} }
@ -106,8 +106,8 @@ int main(int argc, char* argv[]) {
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, v*9.8);
sprites[SPR_PIPETOP].move(-0.2, 0); sprites[SPR_PIPETOP].move(-3, 0, true);
sprites[SPR_PIPEBOTTOM].move(-0.2, 0); sprites[SPR_PIPEBOTTOM].move(-3, 0, true);
if (kDown & KEY_A) { if (kDown & KEY_A) {
v = -5.5; v = -5.5;
@ -128,13 +128,11 @@ int main(int argc, char* argv[]) {
C3D_FrameBegin(C3D_FRAME_SYNCDRAW); C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(top, C3D_CLEAR_COLOR); C2D_TargetClear(top, C3D_CLEAR_COLOR);
C2D_SceneBegin(top); C2D_SceneBegin(top);
// drawSprite(SPR_BG);
// drawSprite(SPR_BIRD);
sprites[SPR_BG].draw(); sprites[SPR_BG].draw();
sprites[SPR_BIRD].draw(); sprites[SPR_BIRD].draw();
// drawSprite(SPR_PIPEBOTTOM); sprites[SPR_PIPETOP].draw();
// drawSprite(SPR_PIPETOP); sprites[SPR_PIPEBOTTOM].draw();
C2D_TargetClear(bottom, C2D_Color32f(0.3294f, 0.7529f, 0.7882f, 1.0f)); C2D_TargetClear(bottom, C2D_Color32f(0.3294f, 0.7529f, 0.7882f, 1.0f));
C2D_SceneBegin(bottom); C2D_SceneBegin(bottom);