24
if (Input::IsKeyMaskHeld("left"))
26
velocity.x -= ACCELERATION * Monocle::deltaTime;
28
if (Input::IsKeyMaskHeld("right"))
30
velocity.x += ACCELERATION * Monocle::deltaTime;
32
if (Input::IsKeyMaskHeld("up"))
34
velocity.y -= ACCELERATION * Monocle::deltaTime;
36
if (Input::IsKeyMaskHeld("down"))
38
velocity.y += ACCELERATION * Monocle::deltaTime;
41
// velocity will approach 0 in steps of FRICTION * dt
42
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
43
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
48
position.x += velocity.x * Monocle::deltaTime;
49
while (Collide("Solid"))
52
if (velocity.x == 0) { break; }
53
//printf("collision1\n");
54
position.x -= SIGN(velocity.x, 0.1);
56
if (xcol) {velocity.x = 0;}
58
position.y += velocity.y * Monocle::deltaTime;
59
while (Collide("Solid"))
62
if (velocity.y == 0) { break; }
63
//printf("collision2\n");
64
position.y -= SIGN(velocity.y, 0.1);
66
if (ycol) {velocity.y = 0;}
69
22
//Scene::GetCamera()->position = position;
72
Creature::Creature() : Entity(),
77
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
78
sprite->Add("idle", 0, 0, 0.35f);
83
SetCollider(new RectangleCollider(32, 32));
85
velocity = Vector2::Random() * ACCELERATION;
87
//set aiTime to random so creatures tick at different times
88
aiTime= (float(rand()) / float(RAND_MAX)) * 2.0f;
91
void Creature::Update()
95
aiTime += Monocle::deltaTime;
101
direction = Vector2::zero;
105
direction = Vector2::Random();
113
velocity += direction * ACCELERATION * Monocle::deltaTime;
115
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
116
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
121
position.x += velocity.x * Monocle::deltaTime;
122
while (Collide("Solid"))
125
if (velocity.x == 0) { break; }
126
//printf("collision1\n");
127
position.x -= SIGN(velocity.x, 0.1);
129
if (xcol) {velocity.x = 0;}
131
position.y += velocity.y * Monocle::deltaTime;
132
while (Collide("Solid"))
135
if (velocity.y == 0) { break; }
136
//printf("collision2\n");
137
position.y -= SIGN(velocity.y, 0.1);
139
if (ycol) {velocity.y = 0;}
172
57
// load level from files
173
58
Level::LoadProject("project.xml");
174
59
Level::Load("level.xml", this);
176
std::list<Entity*> *inv = GetAllTag("invisible");
177
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
180
Vector2 s = e->scale;
181
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
184
61
Player *player = new Player;
185
62
player->position = Graphics::GetScreenCenter();
188
Creature *creature = new Creature;
189
creature->position = Graphics::GetScreenCenter();
192
65
Graphics::SetBackgroundColor(Color::green * 0.2f);