refactor to strut and single file
This commit is contained in:
parent
5629d6aecd
commit
1c39d3bba0
@ -1,8 +1,35 @@
|
||||
#include "MainLevel.hpp"
|
||||
#include "Level.hpp"
|
||||
|
||||
MainLevel::MainLevel(C3D_RenderTarget* top, C3D_RenderTarget* bottom): Level(this, "romfs:/gfx/sprites.t3x", top, bottom) {}
|
||||
#define SPR_BIRD 0
|
||||
|
||||
void MainLevel::setup() {
|
||||
#define SPR_BG 1
|
||||
#define SPR_FLOOR 2
|
||||
#define SPR_LOGO 3
|
||||
#define SPR_PIPEBOTTOM 4
|
||||
#define SPR_PIPETOP 5
|
||||
|
||||
#define SPR_SCORECARD 6
|
||||
#define SPR_BOTHPIPES 7
|
||||
|
||||
#define NUM_PIPES 5
|
||||
|
||||
struct MainLevel: Level {
|
||||
float a = 0.4; // acceleration
|
||||
float v = 0; // velocity
|
||||
float pipeSpeed = -1;
|
||||
|
||||
Sprite pipes[NUM_PIPES];
|
||||
|
||||
int score = 0;
|
||||
bool gameOver = false;
|
||||
|
||||
C2D_TextBuf g_staticBuf;
|
||||
C2D_Text scoreText;
|
||||
C2D_Font font;
|
||||
|
||||
MainLevel(C3D_RenderTarget* top, C3D_RenderTarget* bottom): Level(this, "romfs:/gfx/sprites.t3x", top, bottom) {}
|
||||
|
||||
void setup() {
|
||||
//* SPRITE INIT *//
|
||||
// set bird consts
|
||||
sprites[SPR_BIRD].setPosition(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 3);
|
||||
@ -34,9 +61,10 @@ void MainLevel::setup() {
|
||||
font = C2D_FontLoad("romfs:/gfx/fbfont.bcfnt");
|
||||
C2D_TextFontParse(&scoreText, font, g_staticBuf, "0");
|
||||
C2D_TextOptimize(&scoreText);
|
||||
}
|
||||
|
||||
void MainLevel::update() {
|
||||
};
|
||||
|
||||
void update() {
|
||||
hidScanInput();
|
||||
|
||||
// Respond to user input
|
||||
@ -88,7 +116,7 @@ void MainLevel::update() {
|
||||
// C2D_TextOptimize(&scoreText);
|
||||
}
|
||||
|
||||
void MainLevel::drawTop() {
|
||||
void drawTop() {
|
||||
sprites[SPR_BG].draw();
|
||||
sprites[SPR_BIRD].draw();
|
||||
|
||||
@ -97,13 +125,15 @@ void MainLevel::drawTop() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainLevel::drawBottom() {
|
||||
void drawBottom() {
|
||||
sprites[SPR_SCORECARD].draw();
|
||||
// C2D_DrawText(&scoreText, 0, 240, 88, 0.0f, 0.9f, 0.9f);
|
||||
}
|
||||
|
||||
void MainLevel::cleanup() {
|
||||
void cleanup() {
|
||||
C2D_SpriteSheetFree(spritesheet);
|
||||
C2D_TextBufDelete(g_staticBuf);
|
||||
C2D_FontFree(font);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,50 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef MAINLEVEL_HPP
|
||||
#define MAINLEVEL_HPP
|
||||
|
||||
#include "Level.hpp"
|
||||
|
||||
#define SPR_BIRD 0
|
||||
|
||||
#define SPR_BG 1
|
||||
#define SPR_FLOOR 2
|
||||
#define SPR_LOGO 3
|
||||
#define SPR_PIPEBOTTOM 4
|
||||
#define SPR_PIPETOP 5
|
||||
|
||||
#define SPR_SCORECARD 6
|
||||
#define SPR_BOTHPIPES 7
|
||||
|
||||
#define NUM_PIPES 5
|
||||
|
||||
class MainLevel: public Level {
|
||||
public:
|
||||
float a = 0.4; // acceleration
|
||||
float v = 0; // velocity
|
||||
float pipeSpeed = -1;
|
||||
|
||||
Sprite pipes[NUM_PIPES];
|
||||
|
||||
int score = 0;
|
||||
bool gameOver = false;
|
||||
|
||||
C2D_TextBuf g_staticBuf;
|
||||
C2D_Text scoreText;
|
||||
C2D_Font font;
|
||||
|
||||
MainLevel(C3D_RenderTarget* top, C3D_RenderTarget* bottom);
|
||||
|
||||
void setup();
|
||||
|
||||
void update();
|
||||
|
||||
void drawTop();
|
||||
|
||||
void drawBottom();
|
||||
|
||||
void cleanup();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -10,7 +10,7 @@
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "MainLevel.hpp"
|
||||
#include "MainLevel.cpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user