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) {
133 void Application::Update(int dt) {
134 const float delta = dt / 1e3;
135 controlled->acc = Vector<float>(control * 10);
142 void Application::Render() {
143 constexpr Color background(0x00, 0x00, 0x00);
144 constexpr Color univGrid(0xEE, 0xEE, 0xEE);
145 constexpr Color secGrid(0x77, 0x77, 0x77);
146 constexpr Color entityColor(0x00, 0xAA, 0xAA);
147 constexpr Color focusColor(0xFA, 0xFA, 0x00);
149 SDL_Surface *dst = screen.Screen();
150 const Vector<int> begin = cam.ToScreen(Vector<float>(0, 0));
151 const Vector<int> end =
152 cam.ToScreen((univ.size * univ.secSize * univ.areaSize)) + Vector<int>(1, 1);;
154 Fill(dst, background);
155 Grid(dst, begin, end, cam.ToScale(univ.areaSize), secGrid);
156 Grid(dst, begin, end, cam.ToScale(univ.secSize * univ.areaSize), univGrid);
157 Cross(dst, cam.ToScreen(focus.Pos()), 15, focusColor);
159 for (const Entity &e : univ.Entities()) {
160 Cross(dst, cam.ToScreen((e.area * univ.areaSize) + Vector<int>(e.pos)), 10, entityColor);