52
49
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
53
50
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
55
if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
56
velocity = velocity.GetNormalized() * MAXSPEED;
61
if (Collide("exit")) {
62
Scene *s = GetScene();
65
Text *win1 = new Text("You made it safely through the dark!",
66
Assets::RequestFont("LiberationSans-Regular.ttf", 50.0f));
67
win1->position = Vector2(-350,0);
70
Text *win2 = new Text("Congratulations!",
71
Assets::RequestFont("LiberationSans-Regular.ttf", 50.0f));
72
win2->position = Vector2(-150,50);
76
Collider *collider = NULL;
78
55
position.x += velocity.x * Monocle::deltaTime;
79
while (Collide("Solid") || (collider = Collide("creature")))
56
while (Collide("Solid"))
81
// Don't colide with hunters. We should just die.
83
Creature *c = (Creature *) collider->GetEntity();
84
if (c->state == "hunt") { break; }
88
59
if (velocity.x == 0) { break; }
89
60
//printf("collision1\n");
92
63
if (xcol) {velocity.x = 0;}
95
65
position.y += velocity.y * Monocle::deltaTime;
96
while (Collide("Solid") || (collider = Collide("creature")))
66
while (Collide("Solid"))
98
// Don't colide with hunters. We should just die.
100
Creature *c = (Creature *) collider->GetEntity();
101
if (c->state == "hunt") { break; }
105
69
if (velocity.y == 0) { break; }
106
70
//printf("collision2\n");
107
71
position.y -= SIGN(velocity.y, 0.1);
109
73
if (ycol) {velocity.y = 0;}
111
float magnitude = velocity.GetMagnitude();
113
footsteps->SetVolume(magnitude / MAXSPEED);
115
// How far away can they hear your footsteps?
116
// The circle is diameter 300 at MAXSPEED, 32 (2x your size) at 0 speed
117
noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
75
if (velocity.GetSquaredMagnitude() > 20)
78
footsteps->Pause(); //Stop()?
119
80
dark->position = position;
138
97
AddTag("creature");
139
98
SetCollider(new RectangleCollider(16, 16));
141
alert = Assets::RequestAudio("alert.ogg");
142
freakout = Assets::RequestAudio("freakout.ogg");
143
chomp = Assets::RequestAudio("chomp.ogg");
144
100
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
145
101
skitter1->SetLoops(0); //loop indefinitely
146
sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
149
maxspeed = DEFAULT_MAXSPEED;
103
velocity = Vector2::Random() * MAXSPEED;
151
105
//set aiTime to random so creatures tick at different times
152
106
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
157
109
void Creature::Update()
159
111
Entity::Update();
161
if (state == "idle" || state == "wander")
113
aiTime += Monocle::deltaTime;
163
aiTime += Monocle::deltaTime;
170
direction = Vector2::zero;
174
if (state != "wander") {
175
//printf("wander\n");
176
direction = Vector2::Random();
185
Player *player = ((DarkScene *)scene)->player;
186
if ( (player->position - position).GetSquaredMagnitude() <
187
pow(player->noisiness, 2) )
192
120
direction = Vector2::zero;
193
Ping::NewPing(position, 8.0f, 32.0f, 0.15f); // ping diameter 16-64 over .5s
194
aiTime = 0.0f; // diff variable? stateTime?
196
} // if idle or wander
197
else if (state == "alert")
199
aiTime += Monocle::deltaTime;
201
// if we've been listening past the grace period and hear
202
// something, switch state again
203
// We hear the player at DOUBLE noisiness distance, cuz WE'RE LISNING!
204
Player *player = ((DarkScene *)scene)->player;
205
if ( aiTime > 1.0f &&
206
(player->position - position).GetSquaredMagnitude() <
207
pow(player->noisiness * 2, 2) )
210
Ping::NewPing(position, 8.0f, 32.0f, 0.15f);
211
direction = (player->position - position).GetNormalized();
212
maxspeed = STALKSPEED;
216
// if we've been listening a long time, switch back to idle
218
//printf("end alert\n");
223
else if (state == "stalk")
225
aiTime += Monocle::deltaTime;
228
// * it's been >1s & we hear the player
229
// * we collide with the player
230
Player *player = ((DarkScene *)scene)->player;
231
if ((aiTime > 1.0f &&
232
(player->position - position).GetSquaredMagnitude() <
233
pow(player->noisiness, 2) )
238
direction = (player->position - position).GetNormalized();
239
maxspeed = 0; // give them a running start
242
Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
247
// Go back to IDLE if:
249
// * we stalk for more than 10-15s
250
if ((aiTime > 15.0f) || Collide("wall") || Collide("creaturewall"))
252
// play frustrated noise?
256
maxspeed = DEFAULT_MAXSPEED;
257
direction = Vector2::zero;
260
else if (state == "hunt")
262
aiTime += Monocle::deltaTime;
263
noiseTime += Monocle::deltaTime;
264
graceTime += Monocle::deltaTime;
266
if ((graceTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
267
maxspeed = DEFAULT_MAXSPEED;
269
// if we hear the player (
270
Player *player = ((DarkScene *)scene)->player;
271
if ( (player->position - position).GetSquaredMagnitude() <
272
pow(player->noisiness, 2) )
274
direction = (player->position - position).GetNormalized();
276
if (noiseTime > 2.0f) {
278
Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
124
if (state != "wander") {
125
//printf("wander\n");
126
direction = Vector2::Random();
283
// I guess chill out if it's been a while
284
if (aiTime > 15.0f) {
287
direction = Vector2::zero;
293
// if we collide with you, move you back to the starting point
294
if (Collide("player")) {
295
// TODO: first wait a second or 3?
297
DarkScene *scene = (DarkScene *) GetScene();
298
Entity* playersp = scene->GetFirstEntityWithTag("playerspawner");
299
scene->player->position = playersp->position;
303
135
velocity += direction * ACCELERATION * Monocle::deltaTime;
305
137
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
306
138
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
308
if (velocity.GetSquaredMagnitude() > pow(maxspeed, 2))
309
velocity = velocity.GetNormalized() * maxspeed;
311
140
bool xcol = false;
312
141
bool ycol = false;
314
143
position.x += velocity.x * Monocle::deltaTime;
315
while (Collide("Solid") || Collide("creaturewall"))
144
while (Collide("Solid"))
318
147
if (velocity.x == 0) { break; }
425
206
Level::LoadProject("project.xml");
426
207
Level::Load("level.xml", this);
431
std::list<Entity*> *walls = GetAllTag("wall");
432
for (std::list<Entity*>::iterator i = walls->begin(); i != walls->end(); ++i)
435
Vector2 s = e->scale;
436
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
439
std::list<Entity*> *creaturewalls = GetAllTag("creaturewall");
440
for (std::list<Entity*>::iterator i = creaturewalls->begin(); i != creaturewalls->end(); ++i)
443
Vector2 s = e->scale;
444
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
447
Entity* exit = GetFirstEntityWithTag("exit");
448
Vector2 s = exit->scale;
449
exit->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
209
std::list<Entity*> *inv = GetAllTag("invisible");
210
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
213
Vector2 s = e->scale;
214
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
452
Graphics::SetBackgroundColor(Color::green * 0.2f);
456
void DarkScene::HideSpawners()
458
std::list<Entity*> *spawners = GetAllTag("spawner");
459
if (spawners == NULL) {printf("NO SPAWNERS!!!\n");}
460
for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
461
(*i)->isVisible = false;
464
void DarkScene::ShowSpawners()
466
std::list<Entity*> *spawners = GetAllTag("spawner");
467
for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
468
(*i)->isVisible = true;
471
void DarkScene::Spawn()
473
Entity* playersp = GetFirstEntityWithTag("playerspawner");
474
player = new Player();
475
player->position = playersp->position;;
217
Player *player = new Player;
218
player->position = Graphics::GetScreenCenter();
477
220
Add(player->dark);
479
std::list<Entity*> *spawners = GetAllTag("creaturespawner");
480
// Ugh, monocle is double-entering all the tags...
483
for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
485
Creature *creature = new Creature();
486
creature->position = (*i)->position;
222
Creature *creature = new Creature;
223
creature->position = Graphics::GetScreenCenter();
226
Creature *creature2 = new Creature;
227
creature2->position = Graphics::GetScreenCenter();
230
Graphics::SetBackgroundColor(Color::green * 0.2f);
491
234
void DarkScene::Update()