1 #include "Application.h"
3 #include "../graphics/Canvas.h"
4 #include "../graphics/Color.h"
9 Application::Application(Canvas &c)
11 , univ(Vector<int>(10, 10), Vector<int>(10, 10), Vector<int>(10, 10))
12 , focus(Vector<float>(500, 500), 500)
13 , cam(c.Size(), focus.Pos())
14 , last(SDL_GetTicks())
16 controlled = univ.AddEntity(Entity());
20 void Application::Run() {
23 Uint32 now = SDL_GetTicks();
24 int delta = now - last;
31 void Application::Loop(int delta) {
39 void Application::HandleEvents() {
41 while (SDL_PollEvent(&event)) {
47 if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
48 cam.Resize(event.window.data1, event.window.data2);
52 if (!event.key.repeat) {
57 if (!event.key.repeat) {
68 void Application::OnKeyDown(const SDL_KeyboardEvent &e) {
69 switch (e.keysym.sym) {
105 void Application::OnKeyUp(const SDL_KeyboardEvent &e) {
106 switch (e.keysym.sym) {
143 void Application::Update(int dt) {
144 const float delta = dt / 1e3;
145 controlled->acc = Vector<float>(control * 10);
148 focus.SetSpeed(500 / cam.Zoom());
153 void Application::Render() {
154 constexpr Color background(0x00, 0x00, 0x00);
155 constexpr Color univGrid(0xEE, 0xEE, 0xEE);
156 constexpr Color secGrid(0x77, 0x77, 0x77);
157 constexpr Color entityColor(0x00, 0xAA, 0xAA);
158 constexpr Color focusColor(0xFA, 0xFA, 0x00);
160 canvas.SetColor(background);
164 cam.ToScreen(Vector<float>(0, 0)),
165 cam.ToScale(univ.size * univ.secSize * univ.areaSize),
166 cam.ToScale(univ.areaSize),
171 canvas.SetColor(focusColor);
172 canvas.Cross(cam.ToScreen(focus.Pos()), 15);
174 canvas.SetColor(entityColor);
175 for (const Entity &e : univ.Entities()) {
177 cam.ToScreen(Vector<float>(e.area * univ.areaSize) + e.pos),