]> git.localhorst.tv Git - gworm.git/blob - src/gworm.cpp
efd5757324b36bcd89b8d71fe12ba6c21038f707
[gworm.git] / src / gworm.cpp
1 #include "app/Application.h"
2 #include "app/SDL.h"
3 #include "graphics/Canvas.h"
4 #include "graphics/Window.h"
5 #include "world/Entity.h"
6 #include "world/World.h"
7
8 using namespace gworm;
9
10
11 namespace {
12
13 void make_planet(World &world, Vector<int> center, int radius) {
14         const Vector<int> begin(0, 0);
15         const Vector<int> end(world.Size());
16         const int sqrad = radius * radius;
17
18         for (Vector<int> pos(begin); pos.y < end.y; ++pos.y) {
19                 for (pos.x = 0; pos.x < end.x; ++pos.x) {
20                         Vector<int> diff(center - pos);
21                         int sqdist = Dot(diff, diff);
22                         if (sqdist <= sqrad) {
23                                 world.SetMass(pos, 1e10);
24                                 world.SetColor(pos, Color(0x00, 0x00, 0xA0));
25                         } else {
26                                 world.SetMass(pos, 0);
27                                 world.SetColor(pos, Color(0x00, 0x00, 0x00, 0x00));
28                         }
29                 }
30         }
31 }
32
33 }
34
35
36 int main(int argc, const char *argv[]) {
37         SDL sdl(SDL_INIT_VIDEO);
38         Window win(
39                 "gworm",
40                 Window::POS_UNDEF,
41                 Vector<int>(800, 600),
42                 SDL_WINDOW_RESIZABLE
43         );
44         Canvas canv(win.CreateCanvas(
45                 0
46         ));
47
48         World world(Vector<int>(500, 500));
49         make_planet(world, Vector<int>(250, 250), 220);
50
51         Entity e;
52         e.vel = Vector<float>(-19, 19);
53         e.mass = 1;
54         world.AddEntity(e);
55
56         Application app(canv, world);
57         app.Run();
58
59         return 0;
60 }