Fix main loop, add example and cleanup
This commit is contained in:
+11
-59
@@ -1,67 +1,19 @@
|
||||
#include "window/window.h"
|
||||
#include "app/app.h"
|
||||
|
||||
using namespace app;
|
||||
|
||||
int main() {
|
||||
printf("Starting engine...\n");
|
||||
int loading_image = window.load_image("assets/images/menu_bg.png", 1.0f, true);
|
||||
|
||||
Window w({800, 600}, "Render Test");
|
||||
Animation loading_animation = {
|
||||
.frames = {loading_image},
|
||||
.frame_rate = 1.0f, // Not animated, so frame rate doesn't matter
|
||||
.loop = false
|
||||
};
|
||||
|
||||
int img = w.load_image("./assets/images/arrow.png", true);
|
||||
int font = w.load_font(
|
||||
"./assets/fonts/charybdis.ttf",
|
||||
24,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
);
|
||||
App app({720, 480}, "Mysth Engine", loading_animation);
|
||||
|
||||
int text = w.create_text(font, "Hello Engine", 12, {255, 255, 255, 255});
|
||||
|
||||
float t = 0.0f;
|
||||
|
||||
bool running = true;
|
||||
|
||||
printf("Entering main loop...\n");
|
||||
|
||||
while (running) {
|
||||
Event e;
|
||||
while (w.poll(e)) {
|
||||
switch (e.type) {
|
||||
case Event::QUIT:
|
||||
printf("Exiting\n");
|
||||
running = false;
|
||||
break;
|
||||
case Event::KEY_DOWN:
|
||||
printf("Key down: %d\n", e.key.key);
|
||||
if (e.key.key == 41) {
|
||||
printf("Exiting\n");
|
||||
running = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
w.consume(e);
|
||||
}
|
||||
|
||||
w.clear();
|
||||
|
||||
// animated position
|
||||
t += 0.016f;
|
||||
float x = 200 + std::sin(t) * 100;
|
||||
float y = 150 + std::cos(t) * 100;
|
||||
|
||||
// background rect (low z)
|
||||
w.draw_rect({{0, 0}, {800, 600}}, {20, 20, 30, 255}, 0, 20.0f);
|
||||
|
||||
// image (mid z)
|
||||
w.draw(img, {x, y}, 1.0f, t * 50.0f, {2.0f, 2.0f}, 1.0f);
|
||||
|
||||
// text (top z)
|
||||
w.write(text, {0, 0}, 2.0f, 0.0f, {1.0f, 1.0f});
|
||||
|
||||
w.render();
|
||||
}
|
||||
app.loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user