1 #include "app/Application.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"
11 using namespace gworm;
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;
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));
30 world.SetMass(pos, 0);
31 world.SetColor(pos, Color(0x00, 0x00, 0x00, 0x00));
40 int main(int argc, const char *argv[]) {
41 SDL sdl(SDL_INIT_VIDEO);
45 Vector<int>(800, 600),
48 Canvas canv(win.CreateCanvas(
52 World world(Vector<int>(500, 500));
53 make_planet(world, Vector<int>(250, 250), 220);
56 orb.vel = Vector<float>(-19, 19);
61 coll.pos = Vector<float>(250, -25);
62 coll.vel = Vector<float>(-10, 0);
64 world.AddEntity(coll);
66 cout << "normal at top: " << world.NormalAt(Vector<float>(250, 30)) << endl;
67 cout << "normal at left: " << world.NormalAt(Vector<float>(30, 250)) << endl;
69 Application app(canv, world);