27
if (Input::IsKeyMaskHeld("left"))
29
velocity.x -= ACCELERATION * Monocle::deltaTime;
31
if (Input::IsKeyMaskHeld("right"))
33
velocity.x += ACCELERATION * Monocle::deltaTime;
35
if (Input::IsKeyMaskHeld("up"))
37
velocity.y -= ACCELERATION * Monocle::deltaTime;
39
if (Input::IsKeyMaskHeld("down"))
41
velocity.y += ACCELERATION * Monocle::deltaTime;
44
// velocity will approach 0 in steps of FRICTION * dt
45
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
46
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
51
position.x += velocity.x * Monocle::deltaTime;
52
while (Collide("Solid"))
55
if (velocity.x == 0) { break; }
56
//printf("collision1\n");
57
position.x -= SIGN(velocity.x, 0.1);
59
if (xcol) {velocity.x = 0;}
61
position.y += velocity.y * Monocle::deltaTime;
62
while (Collide("Solid"))
65
if (velocity.y == 0) { break; }
66
//printf("collision2\n");
67
position.y -= SIGN(velocity.y, 0.1);
69
if (ycol) {velocity.y = 0;}
71
if (velocity.GetSquaredMagnitude() > 20)
74
footsteps->Pause(); //Stop()?
22
76
//Scene::GetCamera()->position = position;
79
Creature::Creature() : Entity(),
84
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
85
sprite->Add("idle", 0, 0, 0.35f);
86
sprite->Add("move", 1, 2, 4.0f);
91
SetCollider(new RectangleCollider(32, 32));
93
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
94
skitter1->SetLoops(0); //loop indefinitely
96
velocity = Vector2::Random() * ACCELERATION;
98
//set aiTime to random so creatures tick at different times
99
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
102
void Creature::Update()
106
aiTime += Monocle::deltaTime;
113
direction = Vector2::zero;
117
if (state != "wander") {
118
//printf("wander\n");
119
direction = Vector2::Random();
128
velocity += direction * ACCELERATION * Monocle::deltaTime;
130
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
131
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
136
position.x += velocity.x * Monocle::deltaTime;
137
while (Collide("Solid"))
140
if (velocity.x == 0) { break; }
141
//printf("collision1\n");
142
position.x -= SIGN(velocity.x, 0.1);
144
if (xcol) {velocity.x = 0;}
146
position.y += velocity.y * Monocle::deltaTime;
147
while (Collide("Solid"))
150
if (velocity.y == 0) { break; }
151
//printf("collision2\n");
152
position.y -= SIGN(velocity.y, 0.1);
154
if (ycol) {velocity.y = 0;}
156
if (velocity.GetSquaredMagnitude() > 20)
159
sprite->Play("move");
163
skitter1->Pause(); //Stop()?
164
sprite->Play("idle");
57
198
// load level from files
58
199
Level::LoadProject("project.xml");
59
200
Level::Load("level.xml", this);
202
std::list<Entity*> *inv = GetAllTag("invisible");
203
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
206
Vector2 s = e->scale;
207
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
61
210
Player *player = new Player;
62
211
player->position = Graphics::GetScreenCenter();
65
Graphics::SetBackgroundColor(Color::green * 0.2f);
214
Creature *creature = new Creature;
215
creature->position = Graphics::GetScreenCenter();
218
Creature *creature2 = new Creature;
219
creature2->position = Graphics::GetScreenCenter();
222
Graphics::SetBackgroundColor(Color::black * 0.2f);