Compare commits

..

No commits in common. "e5e5342a6ce0ac282ab36da5c207ab4ea1ddd133" and "d9628233cec57ec6f68845d8649892efc4091888" have entirely different histories.

12 changed files with 46 additions and 138 deletions

BIN
.DS_Store vendored

Binary file not shown.

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.3dsx
*.smdh
*.elf
build

Binary file not shown.

View File

@ -182,7 +182,7 @@ endif
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).3dsx $(TARGET).elf $(GFXBUILD)
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD)
#---------------------------------------------------------------------------------
$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

View File

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

Binary file not shown.

View File

@ -1,83 +1,42 @@
#include "Sprite.hpp"
#include "Sprite.h"
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->x = 200; this->y = 120; this->spr = new C2D_Sprite;
}
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) {
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;
}
}
void Sprite::move(float dx, float dy) {
if (this->x >= 400 || this->x < 1 || this->y >= 240 || this->x < 1) {
return;
}
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) {
this->center[0] = x; this->center[1] = y;
C2D_SpriteSetCenter(&this->spr, x, y);
}
void Sprite::setHitbox(float w, float h) {
this->width = w; this->height = h;
}
bool Sprite::isCollidingWith(Sprite &other) {
// hitbox not set
if (this->width == 0 && this->height == 0) return false;
const float thisHalfWidth = this->width/2;
const float otherHalfWidth = other.width/2;
const float thisHalfHeight = this->height/2;
const float otherHalfHeight = other.height/2;
// check x collision
if (this->x + thisHalfWidth >= other.x - otherHalfWidth ||
this->x - thisHalfWidth <= other.x + otherHalfWidth
) {
return true;
}
// check y collision
if (this->y + thisHalfHeight >= other.y - otherHalfHeight ||
this->y - thisHalfHeight <= other.y + otherHalfHeight
) {
return true;
}
return false;
}
float* Sprite::getCenter() {
return this->center;
C2D_SpriteSetCenter(this->spr, x, y);
}
void Sprite::draw() {
C2D_DrawSprite(&this->spr);
C2D_DrawSprite(this->spr);
}
float Sprite::getPosX() {
@ -89,13 +48,9 @@ float Sprite::getPosY() {
}
C2D_Sprite* Sprite::getSpr() {
return &this->spr;
return this->spr;
}
void Sprite::setSpr(C2D_Sprite* newSpr) {
this->spr = *newSpr;
}
void Sprite::copy(Sprite* other) {
memcpy(&other, this, sizeof(this));
this->spr = newSpr;
}

View File

@ -13,34 +13,24 @@ public:
void setPosition(float x, float y);
void move(float dx, float dy, bool overrideOOB=false);
void move(float dx, float dy);
void setCenter(float x, float y);
void setHitbox(float width, float height);
bool isCollidingWith(Sprite &other);
void draw();
float getPosX();
float getPosY();
float* getCenter();
C2D_Sprite* getSpr();
void setSpr(C2D_Sprite* newSpr);
void copy(Sprite* other);
C2D_Sprite spr;
C2D_Sprite* spr;
private:
float x, y;
float width, height; // for hitbox
float center[2];
};
#endif

View File

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

View File

@ -7,24 +7,21 @@
#include <citro2d.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include "Sprite.hpp"
#include "Sprite.h"
#include "SpriteList.h"
#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++) {
@ -32,38 +29,24 @@ 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);
sprites[SPR_BIRD].setHitbox(17, 12);
// set bottom screen scorecard
sprites[SPR_SCORECARD].setCenter(0.0, 0.0);
sprites[SPR_SCORECARD].setPosition(2, 40);
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 + 40 + i * (100), (rand() % 150) + 50);
pipes[i].setHitbox(26, 403);
}
sprites[SPR_PIPETOP].setPosition(280, 14);
sprites[SPR_PIPEBOTTOM].setPosition(280, 200);
}
void introScene();
void gameScene();
void gameOverScene();
// void (*currentScene)(C3D_RenderTarget*, C3D_RenderTarget*) = &gameScene;
int main(int argc, char* argv[]) {
@ -101,14 +84,12 @@ int main(int argc, char* argv[]) {
// init gravity calc vars
float a = 0.4; // acceleration
float v = 0; // velocity
float pipeSpeed = -1;
// 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;
bool gameOver = false;
// Main loop
while (aptMainLoop()) {
@ -123,41 +104,19 @@ 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);
if (!gameOver && (kDown & KEY_A)) {
sprites[SPR_PIPETOP].move(-0.2, 0);
sprites[SPR_PIPEBOTTOM].move(-0.2, 0);
if (kDown & KEY_A) {
v = -5.5;
sprites[SPR_BIRD].move(0, v, true);
// moveSprite(&sprites[SPR_BIRD], 0, v);
sprites[SPR_BIRD].move(0, v);
// temp score = num of flaps
score++;
}
// bird hitting ground is game over
if (sprites[SPR_BIRD].getPosY() == SCREEN_HEIGHT) {
gameOver = true;
}
if (!gameOver) {
for (int i = 0; i < NUM_PIPES; i++) {
pipes[i].move(pipeSpeed, 0, true);
// collision detection
if (pipes[i].isCollidingWith(sprites[SPR_BIRD])) {
gameOver = true;
break;
}
// inc score
if (pipes[i].getPosX() == sprites[SPR_BIRD].getPosX())
score++;
// send pipes back to front of screen
if (pipes[i].getPosX() < -(SCREEN_WIDTH/NUM_PIPES)) {
pipes[i].setPosition(SCREEN_WIDTH, (rand() % 150) + 50);
}
}
}
// make score text
char scoreString[(((sizeof score) * CHAR_BIT) + 2)/3 + 2];
sprintf(scoreString, "%d", score);
@ -169,22 +128,27 @@ 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();
for (int i = 0; i < NUM_PIPES; i++) {
pipes[i].draw();
}
// drawSprite(SPR_PIPEBOTTOM);
// drawSprite(SPR_PIPETOP);
C2D_TargetClear(bottom, C2D_Color32f(0.3294f, 0.7529f, 0.7882f, 1.0f));
C2D_SceneBegin(bottom);
// drawSprite(SPR_SCORECARD);
sprites[SPR_SCORECARD].draw();
// C2D_DrawSprite(&scoreSprite->spr);
C2D_DrawText(&scoreText, 0, 240, 88, 0.0f, 0.9f, 0.9f);
C3D_FrameEnd(0);
}
// Delete graphics
C2D_SpriteSheetFree(spriteSheet);
C2D_TextBufDelete(g_staticBuf);

View File

@ -1,2 +1,2 @@
# need to have ftpd open for this
curl -T Flappy3DS.3dsx ftp://192.168.88.131:5000/3ds/
curl -T Flappy3DS.3dsx ftp://192.168.88.172:5000/3ds/breadbrew/