Sets of pipes generate but its horrifying

This commit is contained in:
pradyun 2023-03-11 18:39:31 +13:00
parent a3dc058f99
commit cb1846c80a
8 changed files with 39 additions and 25 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
gfx/bothPipes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -5,4 +5,5 @@ floor.png
logo.png logo.png
pipeBottom.png pipeBottom.png
pipeTop.png pipeTop.png
scoreCardBig.png scoreCardBig.png
bothPipes.png

Binary file not shown.

View File

@ -3,21 +3,21 @@
Sprite::Sprite() { Sprite::Sprite() {
// C2D_SpriteSetCenter(&this->spr, 0.5f, 0.5f); // C2D_SpriteSetCenter(&this->spr, 0.5f, 0.5f);
// C2D_SpriteSetPos(&this->spr, 400/2, 240/2); // 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) { 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_SpriteSetCenter(&this->spr, 0.5f, 0.5f);
C2D_SpriteSetPos(this->spr, x, y); C2D_SpriteSetPos(&this->spr, x, y);
} }
void Sprite::setPosition(float x, float y) { void Sprite::setPosition(float x, float y) {
this->x = x; this->x = x;
this->y = y; this->y = y;
C2D_SpriteSetPos(this->spr, x, y); C2D_SpriteSetPos(&this->spr, x, y);
} }
void Sprite::move(float dx, float dy, bool overrideOOB) { 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->x += dx;
this->y += dy; 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) { void Sprite::setCenter(float x, float y) {
C2D_SpriteSetCenter(this->spr, x, y); C2D_SpriteSetCenter(&this->spr, x, y);
} }
void Sprite::draw() { void Sprite::draw() {
C2D_DrawSprite(this->spr); C2D_DrawSprite(&this->spr);
} }
float Sprite::getPosX() { float Sprite::getPosX() {
@ -53,9 +53,9 @@ float Sprite::getPosY() {
} }
C2D_Sprite* Sprite::getSpr() { C2D_Sprite* Sprite::getSpr() {
return this->spr; return &this->spr;
} }
void Sprite::setSpr(C2D_Sprite* newSpr) { void Sprite::setSpr(C2D_Sprite* newSpr) {
this->spr = newSpr; this->spr = *newSpr;
} }

View File

@ -27,7 +27,7 @@ public:
void setSpr(C2D_Sprite* newSpr); void setSpr(C2D_Sprite* newSpr);
C2D_Sprite* spr; C2D_Sprite spr;
private: private:
float x, y; float x, y;

View File

@ -12,5 +12,6 @@
#define SPR_PIPETOP 5 #define SPR_PIPETOP 5
#define SPR_SCORECARD 6 #define SPR_SCORECARD 6
#define SPR_BOTHPIPES 7
#endif #endif

View File

@ -7,6 +7,7 @@
#include <citro2d.h> #include <citro2d.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <limits.h> #include <limits.h>
#include "Sprite.hpp" #include "Sprite.hpp"
@ -15,13 +16,15 @@
#define MAX_SPRITES 768 #define MAX_SPRITES 768
#define SCREEN_WIDTH 400 #define SCREEN_WIDTH 400
#define SCREEN_HEIGHT 240 #define SCREEN_HEIGHT 240
#define NUM_PIPES 5
// init spritesheet // init spritesheet
static C2D_SpriteSheet spriteSheet; static C2D_SpriteSheet spriteSheet;
Sprite sprites[MAX_SPRITES]; Sprite sprites[MAX_SPRITES];
Sprite pipes[NUM_PIPES];
static void initSprites() { static void initSprites() {
srand(time(NULL));
size_t numImages = C2D_SpriteSheetCount(spriteSheet); size_t numImages = C2D_SpriteSheetCount(spriteSheet);
for (size_t i = 0; i < numImages; i++) { for (size_t i = 0; i < numImages; i++) {
@ -29,14 +32,13 @@ static void initSprites() {
float x = SCREEN_WIDTH / 2; float x = SCREEN_WIDTH / 2;
float y = SCREEN_HEIGHT / 2; float y = SCREEN_HEIGHT / 2;
C2D_SpriteFromSheet(thisSprite->spr, spriteSheet, i); C2D_SpriteFromSheet(&thisSprite->spr, spriteSheet, i);
C2D_SpriteSetCenter(thisSprite->spr, 0.5f, 0.5f); C2D_SpriteSetCenter(&thisSprite->spr, 0.5f, 0.5f);
thisSprite->setPosition(x, y); thisSprite->setPosition(x, y);
} }
// set bird consts // set bird consts
sprites[SPR_BIRD].setPosition(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 3); sprites[SPR_BIRD].setPosition(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 3);
// set bottom screen scorecard // set bottom screen scorecard
sprites[SPR_SCORECARD].setCenter(0.0, 0.0); sprites[SPR_SCORECARD].setCenter(0.0, 0.0);
@ -45,6 +47,13 @@ static void initSprites() {
sprites[SPR_PIPETOP].setPosition(280, 3); sprites[SPR_PIPETOP].setPosition(280, 3);
sprites[SPR_PIPEBOTTOM].setPosition(280, 280); 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 // set bg properties
sprites[SPR_BG].setPosition(200, 120); 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; size_t score = 0;
@ -105,7 +114,7 @@ int main(int argc, char* argv[]) {
// gravity calcs // gravity calcs
v += a; v += a;
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);
@ -116,14 +125,16 @@ int main(int argc, char* argv[]) {
score++; score++;
} }
sprites[SPR_PIPETOP].move(pipeSpeed, 0, true); for (int i = 0; i < NUM_PIPES; i++) {
sprites[SPR_PIPEBOTTOM].move(pipeSpeed, 0, true); pipes[i].move(pipeSpeed, 0, true);
if (sprites[SPR_PIPETOP].getPosX() < -10) { if (pipes[i].getPosX() < -10) {
sprites[SPR_PIPETOP].setPosition(SCREEN_WIDTH, 3); pipes[i].setPosition(SCREEN_WIDTH, rand() % SCREEN_HEIGHT);
sprites[SPR_PIPEBOTTOM].setPosition(SCREEN_WIDTH, 280); }
} }
// make score text // make score text
char scoreString[(((sizeof score) * CHAR_BIT) + 2)/3 + 2]; char scoreString[(((sizeof score) * CHAR_BIT) + 2)/3 + 2];
sprintf(scoreString, "%d", score); sprintf(scoreString, "%d", score);
@ -138,8 +149,9 @@ int main(int argc, char* argv[]) {
sprites[SPR_BG].draw(); sprites[SPR_BG].draw();
sprites[SPR_BIRD].draw(); sprites[SPR_BIRD].draw();
sprites[SPR_PIPETOP].draw(); for (int i = 0; i < NUM_PIPES; i++) {
sprites[SPR_PIPEBOTTOM].draw(); pipes[i].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);