1 #include "Application.h"
3 #include "../graphics/Color.h"
4 #include "../graphics/primitive.h"
5 #include "../sdl/InitScreen.h"
10 Application::Application(InitScreen &s)
12 , univ(Vector<int>(10, 10), Vector<int>(10, 10), Vector<int>(10, 10), 10)
13 , focus(Vector<float>(500, 500), 500)
14 , cam(800, 800, focus.Pos())
15 , last(SDL_GetTicks())
17 controlled = univ.AddEntity(Entity());
21 void Application::Run() {
24 Uint32 now = SDL_GetTicks();
25 int delta = now - last;
32 void Application::Loop(int delta) {
40 void Application::HandleEvents() {
42 while (SDL_PollEvent(&event)) {
48 screen.Resize(event.resize.w, event.resize.h);
49 cam.Resize(event.resize.w, event.resize.h);
64 void Application::OnKeyDown(const SDL_KeyboardEvent &e) {
65 switch (e.keysym.sym) {
101 void Application::OnKeyUp(const SDL_KeyboardEvent &e) {
102 switch (e.keysym.sym) {
139 void Application::Update(int dt) {
140 const float delta = dt / 1e3;
141 controlled->acc = Vector<float>(control * 10);
148 void Application::Render() {
149 constexpr Color background(0x00, 0x00, 0x00);
150 constexpr Color univGrid(0xEE, 0xEE, 0xEE);
151 constexpr Color secGrid(0x77, 0x77, 0x77);
152 constexpr Color entityColor(0x00, 0xAA, 0xAA);
153 constexpr Color focusColor(0xFA, 0xFA, 0x00);
155 SDL_Surface *dst = screen.Screen();
156 const Vector<int> begin = cam.ToScreen(Vector<float>(0, 0));
157 const Vector<int> end =
158 cam.ToScreen((univ.size * univ.secSize * univ.areaSize))
161 Fill(dst, background);
162 Grid2(dst, begin, end, cam.ToScale(univ.areaSize), univ.secSize, secGrid, univGrid);
163 Cross(dst, cam.ToScreen(focus.Pos()), 15, focusColor);
165 for (const Entity &e : univ.Entities()) {
166 Cross(dst, cam.ToScreen((e.area * univ.areaSize) + Vector<int>(e.pos)), 10, entityColor);