Compare commits
10 Commits
d9628233ce
...
e5e5342a6c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e5e5342a6c | ||
![]() |
6b89a9ec67 | ||
![]() |
b86959df36 | ||
![]() |
d5562e7ef0 | ||
![]() |
6c7e5ab425 | ||
![]() |
36e6fa79ff | ||
![]() |
ace966491b | ||
![]() |
cb1846c80a | ||
![]() |
a3dc058f99 | ||
![]() |
9ccb5007af |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
*.3dsx
|
*.3dsx
|
||||||
*.smdh
|
|
||||||
*.elf
|
*.elf
|
||||||
|
|
||||||
build
|
build
|
||||||
|
BIN
Flappy3DS.smdh
Normal file
BIN
Flappy3DS.smdh
Normal file
Binary file not shown.
2
Makefile
2
Makefile
@ -182,7 +182,7 @@ endif
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@echo clean ...
|
||||||
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD)
|
@rm -fr $(BUILD) $(TARGET).3dsx $(TARGET).elf $(GFXBUILD)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s
|
$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s
|
||||||
|
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
|
pipeBottom.png
|
||||||
pipeTop.png
|
pipeTop.png
|
||||||
scoreCardBig.png
|
scoreCardBig.png
|
||||||
|
bothPipes.png
|
Binary file not shown.
@ -1,42 +1,83 @@
|
|||||||
#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);
|
||||||
// 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) {
|
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;
|
||||||
|
|
||||||
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);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::draw() {
|
void Sprite::draw() {
|
||||||
C2D_DrawSprite(this->spr);
|
C2D_DrawSprite(&this->spr);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sprite::getPosX() {
|
float Sprite::getPosX() {
|
||||||
@ -48,9 +89,13 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sprite::copy(Sprite* other) {
|
||||||
|
memcpy(&other, this, sizeof(this));
|
||||||
}
|
}
|
@ -13,24 +13,34 @@ 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);
|
||||||
|
|
||||||
|
void setHitbox(float width, float height);
|
||||||
|
|
||||||
|
bool isCollidingWith(Sprite &other);
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
float getPosX();
|
float getPosX();
|
||||||
|
|
||||||
float getPosY();
|
float getPosY();
|
||||||
|
|
||||||
|
float* getCenter();
|
||||||
|
|
||||||
C2D_Sprite* getSpr();
|
C2D_Sprite* getSpr();
|
||||||
|
|
||||||
void setSpr(C2D_Sprite* newSpr);
|
void setSpr(C2D_Sprite* newSpr);
|
||||||
|
|
||||||
C2D_Sprite* spr;
|
void copy(Sprite* other);
|
||||||
|
|
||||||
|
C2D_Sprite spr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float x, y;
|
float x, y;
|
||||||
|
float width, height; // for hitbox
|
||||||
|
float center[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -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
|
@ -7,21 +7,24 @@
|
|||||||
#include <citro2d.h>
|
#include <citro2d.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "Sprite.h"
|
#include "Sprite.hpp"
|
||||||
|
|
||||||
#include "SpriteList.h"
|
#include "SpriteList.h"
|
||||||
|
|
||||||
#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,24 +32,38 @@ 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);
|
||||||
|
sprites[SPR_BIRD].setHitbox(17, 12);
|
||||||
|
|
||||||
// set bottom screen scorecard
|
// set bottom screen scorecard
|
||||||
sprites[SPR_SCORECARD].setCenter(0.0, 0.0);
|
sprites[SPR_SCORECARD].setCenter(0.0, 0.0);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void introScene();
|
||||||
|
void gameScene();
|
||||||
|
void gameOverScene();
|
||||||
|
|
||||||
|
// void (*currentScene)(C3D_RenderTarget*, C3D_RenderTarget*) = &gameScene;
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
@ -84,12 +101,14 @@ int main(int argc, char* argv[]) {
|
|||||||
// init gravity calc vars
|
// init gravity calc vars
|
||||||
float a = 0.4; // acceleration
|
float a = 0.4; // acceleration
|
||||||
float v = 0; // velocity
|
float v = 0; // velocity
|
||||||
|
float pipeSpeed = -1;
|
||||||
|
|
||||||
// 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;
|
||||||
|
bool gameOver = false;
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (aptMainLoop()) {
|
while (aptMainLoop()) {
|
||||||
@ -104,19 +123,41 @@ 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);
|
||||||
|
|
||||||
sprites[SPR_PIPETOP].move(-0.2, 0);
|
if (!gameOver && (kDown & KEY_A)) {
|
||||||
sprites[SPR_PIPEBOTTOM].move(-0.2, 0);
|
|
||||||
|
|
||||||
if (kDown & KEY_A) {
|
|
||||||
v = -5.5;
|
v = -5.5;
|
||||||
// moveSprite(&sprites[SPR_BIRD], 0, v);
|
sprites[SPR_BIRD].move(0, v, true);
|
||||||
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
|
// 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);
|
||||||
@ -128,27 +169,22 @@ 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);
|
for (int i = 0; i < NUM_PIPES; i++) {
|
||||||
// drawSprite(SPR_PIPETOP);
|
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);
|
||||||
// drawSprite(SPR_SCORECARD);
|
|
||||||
sprites[SPR_SCORECARD].draw();
|
sprites[SPR_SCORECARD].draw();
|
||||||
// C2D_DrawSprite(&scoreSprite->spr);
|
|
||||||
|
|
||||||
|
|
||||||
C2D_DrawText(&scoreText, 0, 240, 88, 0.0f, 0.9f, 0.9f);
|
C2D_DrawText(&scoreText, 0, 240, 88, 0.0f, 0.9f, 0.9f);
|
||||||
C3D_FrameEnd(0);
|
C3D_FrameEnd(0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete graphics
|
// Delete graphics
|
||||||
C2D_SpriteSheetFree(spriteSheet);
|
C2D_SpriteSheetFree(spriteSheet);
|
||||||
C2D_TextBufDelete(g_staticBuf);
|
C2D_TextBufDelete(g_staticBuf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user