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