Compare commits

..

No commits in common. "15b16071c911d0b88fcfcababf6935a4cb8df4f5" and "dd801873deb5f3e4dc3f255cf5dd10a1550f17f1" have entirely different histories.

10 changed files with 15 additions and 86 deletions

29
.vscode/launch.json vendored
View file

@ -187,35 +187,6 @@
],
"avoidWindowsConsoleRedirection": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "(gdb, lxdream-nitro) Launch flappyBird.elf",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/src/flappyBird.elf",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/opt/toolchains/dc/sh-elf/bin/sh-elf-gdb",
"miDebuggerServerAddress": "localhost:3263",
"debugServerPath": "/home/user/Downloads/lxdream-nitro/builddir/lxdream-nitro",
"debugServerArgs": "-d -g 3263 -e ${workspaceFolder}/build/src/flappyBird.elf",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set SuperH architechture",
"text": "set architecture sh4"
}
],
"avoidWindowsConsoleRedirection": false,
"internalConsoleOptions": "openOnSessionStart"
}
]
}

View file

@ -16,7 +16,6 @@ public:
std::vector<Entity*> children = {};
virtual void Draw() {};
virtual void Update() {};
virtual void Start() {};
bool b_destroyed = false;
Vector3 GetPosition() const;
Vector3 GetGlobalPosition() const;

View file

@ -2,11 +2,6 @@
#define ASSETS_HH
#include <vector>
namespace assets {
struct Image {
int width;
int height;
std::vector<unsigned char> data;
};
extern Image bird;
std::vector<unsigned char> bird();
}
#endif

View file

@ -1,29 +1,22 @@
#include "Bird.hh"
#include "Assets.hh"
#include <GL/gl.h>
#include <cstdio>
#include <vector>
void Bird::Draw() {
engine::Vector3 one = {-1.0, -1.0, 0.0};
engine::Vector3 two = {0.0, 1.0, 0.0};
engine::Vector3 three = {1.0, -1.0, 0.0f};
glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
// glColor3f(1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3fv((float*)&(one));
// glColor3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3fv((float*)&two);
// glColor3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(0.5f, 1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3fv((float*)&three);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void Bird::Update() {
@ -70,17 +63,3 @@ Bird::Bird(engine::Engine* engie, engine::Entity* parent, PipesContainer* pipes)
: Entity(engie, parent) {
this->pipes = pipes;
}
void Bird::Start() {
auto bird = assets::bird;
glGenTextures(1, &ui_birdTexture);
glBindTexture(GL_TEXTURE_2D, ui_birdTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bird.width, bird.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bird.data.data());
}

View file

@ -7,7 +7,6 @@ class Bird : public engine::Entity {
public:
void Draw() override;
void Update() override;
void Start() override;
Bird(engine::Engine* engie, engine::Entity* parent, PipesContainer* pipes);
bool b_isHit = false;
@ -16,6 +15,5 @@ class Bird : public engine::Entity {
static constexpr float JUMP_CONST = 0.5;
float f_verticalSpeed = JUMP_CONST;
PipesContainer *pipes = nullptr;
unsigned int ui_birdTexture = 0;
};
#endif

View file

@ -105,7 +105,3 @@ FlappyBird::~FlappyBird()
p_thread->detach();
delete p_thread;
}
void FlappyBird::Start() {
p_bird->Start();
}

View file

@ -11,7 +11,6 @@
class FlappyBird : public engine::Engine {
void GameLoop() override;
void Start() override;
void SpawnPipes();
void MainGameLoop();
void MainMenuLoop();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 426 B

23
src/flappyBird/generateAssets.py Executable file → Normal file
View file

@ -1,32 +1,27 @@
#!/usr/bin/env python3
import argparse
from pathlib import Path
from PIL import Image
parser = argparse.ArgumentParser()
parser.add_argument("variable")
parser.add_argument("function")
parser.add_argument("input")
parser.add_argument("output")
args = parser.parse_args()
variable = args.variable
function = args.function
input = Path(args.input)
output = Path(args.output)
if not input.exists():
print("Input " + str(input.absolute()) + " not found.")
print("Input " + str(path.absolute()) + " not found.")
raise SystemExit(1)
hexList = list()
imageWidth = 0
imageHeight = 0
with Image.open(input) as image:
imageWidth = image.width
imageHeight = image.height
# flatten a tuple of RGBA bytes into a list of bytes
byteList = [item for tup in [*image.getdata()] for item in tup]
imageBytes = bytes(image.getdata())
byteList = list(imageBytes)
for byte in byteList:
hexList.append(f'0x{byte:02x}')
@ -36,11 +31,9 @@ code = f"""#include <Assets.hh>
#include <vector>
namespace assets {{
Image {variable} = {{
.width = {imageWidth},
.height = {imageHeight},
.data = {{ {','.join(hexList)} }}
}};
std::vector<unsigned char> {function}() {{
return {{ {','.join(hexList)} }};
}}
}}
"""

View file

@ -5,9 +5,8 @@ flappy_sources = [
'MainMenu.cc'
]
assets = find_program('generateAssets.py')
asset_gen = generator(assets, output: '@BASENAME@.cc', arguments: ['@EXTRA_ARGS@', '@INPUT@', '@OUTPUT@'])
bird = asset_gen.process('assets/yellowbird-downflap.png', extra_args: ['bird'])
python3 = find_program('python3')
bird = custom_target('bird', output: 'birdSprite.cc', input: ['generateAssets.py', 'assets/yellowbird-downflap.png'], command: [python3, '@INPUT0@', 'bird', '@INPUT1@', '@OUTPUT@'])
flappy_bird = static_library('flappyBird', [flappy_sources, bird], dependencies: deps, include_directories: incdirs)
flappy_dep = declare_dependency(link_with: [flappy_bird], include_directories: incdirs)