]> git.localhorst.tv Git - space.git/blobdiff - src/app/Application.cpp
controlled entity
[space.git] / src / app / Application.cpp
index 247819c41bd0088d9f1a51e9b3dc7745954ff17c..b2ef9161287b5cf77e30ca188386174f116d1390 100644 (file)
@@ -9,12 +9,12 @@ namespace space {
 
 Application::Application(InitScreen &s)
 : screen(s)
-, univ(10, 10, 10, 10, 10)
+, univ(Vector<int>(10, 10), Vector<int>(10, 10), Vector<int>(10, 10), 10)
 , focus(Vector<float>(500, 500), 500)
 , cam(800, 800, focus.Pos())
 , last(SDL_GetTicks())
 , running(false) {
-
+       controlled = univ.AddEntity(Entity());
 }
 
 
@@ -75,6 +75,18 @@ void Application::OnKeyDown(const SDL_KeyboardEvent &e) {
                case SDLK_RIGHT:
                        focus.MoveRight();
                        break;
+               case SDLK_w:
+                       control.y -= 1;
+                       break;
+               case SDLK_s:
+                       control.y += 1;
+                       break;
+               case SDLK_a:
+                       control.x -= 1;
+                       break;
+               case SDLK_d:
+                       control.x += 1;
+                       break;
                default:
                        break;
        }
@@ -94,6 +106,18 @@ void Application::OnKeyUp(const SDL_KeyboardEvent &e) {
                case SDLK_RIGHT:
                        focus.StopRight();
                        break;
+               case SDLK_w:
+                       control.y += 1;
+                       break;
+               case SDLK_s:
+                       control.y -= 1;
+                       break;
+               case SDLK_a:
+                       control.x += 1;
+                       break;
+               case SDLK_d:
+                       control.x -= 1;
+                       break;
                default:
                        break;
        }
@@ -101,26 +125,33 @@ void Application::OnKeyUp(const SDL_KeyboardEvent &e) {
 
 
 void Application::Update(int dt) {
-       focus.Update(dt / 1e3);
+       const float delta = dt / 1e3;
+       controlled->acc = Vector<float>(control * 10);
+       univ.Update(delta);
+       focus.Update(delta);
 }
 
 
 void Application::Render() {
        constexpr Color background(0x00, 0x00, 0x00);
-       constexpr Color univGrid(0xFF, 0xFF, 0xFF);
-       constexpr Color sectGrid(0xAA, 0xAA, 0xAA);
-
-       constexpr Vector<int> areaSize(10, 10);
-       constexpr Vector<int> sectSize(areaSize * 10);
-       constexpr Vector<int> univSize(sectSize * 10);
+       constexpr Color univGrid(0xEE, 0xEE, 0xEE);
+       constexpr Color secGrid(0x77, 0x77, 0x77);
+       constexpr Color entityColor(0x00, 0xAA, 0xAA);
+       constexpr Color focusColor(0xFA, 0xFA, 0x00);
 
        SDL_Surface *dst = screen.Screen();
-       Vector<int> offset = cam.Offset();
+       const Vector<int> begin = cam.Offset();
+       const Vector<int> end =
+               begin + (univ.size * univ.secSize * univ.areaSize) + Vector<int>(1, 1);
 
        Fill(dst, background);
-       Grid(dst, offset, offset + univSize + Vector<int>(1, 1), areaSize, sectGrid);
-       Grid(dst, offset, offset + univSize + Vector<int>(1, 1), sectSize, univGrid);
-       Cross(dst, offset + Vector<int>(focus.Pos()), 15, Color(0xFF, 0xFF, 0x00));
+       Grid(dst, begin, end, univ.areaSize, secGrid);
+       Grid(dst, begin, end, univ.secSize * univ.areaSize, univGrid);
+       Cross(dst, begin + Vector<int>(focus.Pos()), 15, focusColor);
+
+       for (const Entity &e : univ.Entities()) {
+               Cross(dst, begin + (e.area * univ.areaSize) + Vector<int>(e.pos), 10, entityColor);
+       }
 }
 
 }