Sets of pipes generate but its horrifying
This commit is contained in:
parent
a3dc058f99
commit
cb1846c80a
BIN
gfx/bothPipes.png
Normal file
BIN
gfx/bothPipes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
@ -6,3 +6,4 @@ logo.png
|
||||
pipeBottom.png
|
||||
pipeTop.png
|
||||
scoreCardBig.png
|
||||
bothPipes.png
|
Binary file not shown.
@ -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;
|
||||
}
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
void setSpr(C2D_Sprite* newSpr);
|
||||
|
||||
C2D_Sprite* spr;
|
||||
C2D_Sprite spr;
|
||||
|
||||
private:
|
||||
float x, y;
|
||||
|
@ -12,5 +12,6 @@
|
||||
#define SPR_PIPETOP 5
|
||||
|
||||
#define SPR_SCORECARD 6
|
||||
#define SPR_BOTHPIPES 7
|
||||
|
||||
#endif
|
@ -7,6 +7,7 @@
|
||||
#include <citro2d.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#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,15 +32,14 @@ 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,13 +125,15 @@ 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];
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user