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