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(10, 10, 10, 10, 10)
13 , focus(Vector<float>(500, 500), 500)
14 , cam(800, 800, focus.Pos())
15 , last(SDL_GetTicks())
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) {
83 void Application::OnKeyUp(const SDL_KeyboardEvent &e) {
84 switch (e.keysym.sym) {
103 void Application::Update(int dt) {
104 focus.Update(dt / 1e3);
108 void Application::Render() {
109 constexpr Color background(0x00, 0x00, 0x00);
110 constexpr Color univGrid(0xFF, 0xFF, 0xFF);
111 constexpr Color sectGrid(0xAA, 0xAA, 0xAA);
113 constexpr Vector<int> areaSize(10, 10);
114 constexpr Vector<int> sectSize(areaSize * 10);
115 constexpr Vector<int> univSize(sectSize * 10);
117 SDL_Surface *dst = screen.Screen();
118 Vector<int> offset = cam.Offset();
120 Fill(dst, background);
121 Grid(dst, offset, offset + univSize + Vector<int>(1, 1), areaSize, sectGrid);
122 Grid(dst, offset, offset + univSize + Vector<int>(1, 1), sectSize, univGrid);
123 Cross(dst, offset + Vector<int>(focus.Pos()), 15, Color(0xFF, 0xFF, 0x00));