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);
90
SetCollider(new RectangleCollider(32, 32));
92
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
93
skitter1->SetLoops(0); //loop indefinitely
95
velocity = Vector2::Random() * ACCELERATION;
97
//set aiTime to random so creatures tick at different times
98
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
101
void Creature::Update()
105
aiTime += Monocle::deltaTime;
112
direction = Vector2::zero;
116
if (state != "wander") {
117
//printf("wander\n");
118
direction = Vector2::Random();
127
velocity += direction * ACCELERATION * Monocle::deltaTime;
129
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
130
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
135
position.x += velocity.x * Monocle::deltaTime;
136
while (Collide("Solid"))
139
if (velocity.x == 0) { break; }
140
//printf("collision1\n");
141
position.x -= SIGN(velocity.x, 0.1);
143
if (xcol) {velocity.x = 0;}
145
position.y += velocity.y * Monocle::deltaTime;
146
while (Collide("Solid"))
149
if (velocity.y == 0) { break; }
150
//printf("collision2\n");
151
position.y -= SIGN(velocity.y, 0.1);
153
if (ycol) {velocity.y = 0;}
155
if (velocity.GetSquaredMagnitude() > 20)
158
skitter1->Pause(); //Stop()?
57
191
// load level from files
58
192
Level::LoadProject("project.xml");
59
193
Level::Load("level.xml", this);
195
std::list<Entity*> *inv = GetAllTag("invisible");
196
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
199
Vector2 s = e->scale;
200
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
61
203
Player *player = new Player;
62
204
player->position = Graphics::GetScreenCenter();
207
Creature *creature = new Creature;
208
creature->position = Graphics::GetScreenCenter();
211
Creature *creature2 = new Creature;
212
creature2->position = Graphics::GetScreenCenter();
65
215
Graphics::SetBackgroundColor(Color::green * 0.2f);