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;
61
78
position.x += velocity.x * Monocle::deltaTime;
62
while (Collide("Solid"))
79
while (Collide("Solid") || (collider = Collide("creature")))
81
// Don't colide with hunters. We should just die.
83
Creature *c = (Creature *) collider->GetEntity();
84
if (c->state == "hunt") { break; }
65
88
if (velocity.x == 0) { break; }
66
89
//printf("collision1\n");
69
92
if (xcol) {velocity.x = 0;}
71
95
position.y += velocity.y * Monocle::deltaTime;
72
while (Collide("Solid"))
96
while (Collide("Solid") || (collider = Collide("creature")))
98
// Don't colide with hunters. We should just die.
100
Creature *c = (Creature *) collider->GetEntity();
101
if (c->state == "hunt") { break; }
75
105
if (velocity.y == 0) { break; }
76
106
//printf("collision2\n");
85
115
// How far away can they hear your footsteps?
86
116
// The circle is diameter 300 at MAXSPEED, 32 (2x your size) at 0 speed
87
noisiness = ((magnitude / MAXSPEED *(300-32)) + 32) /2;
117
noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
89
119
dark->position = position;
94
124
Creature::Creature() : Entity(),
97
126
ACCELERATION(1200),
127
DEFAULT_MAXSPEED(80.0f),
101
130
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
102
131
sprite->Add("idle", 0, 0, 0.35f);
103
132
sprite->Add("move", 1, 2, 4.0f);
133
sprite->Add("slowmove", 1, 2, 2.0f);
104
134
sprite->Play("idle");
105
135
SetGraphic(sprite);
106
136
scale = Vector2(0.25, 0.25);
108
138
AddTag("creature");
109
139
SetCollider(new RectangleCollider(16, 16));
141
alert = Assets::RequestAudio("alert.ogg");
142
freakout = Assets::RequestAudio("freakout.ogg");
143
chomp = Assets::RequestAudio("chomp.ogg");
111
144
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
112
145
skitter1->SetLoops(0); //loop indefinitely
113
alert = Assets::RequestAudio("alert.ogg");
114
stalk = Assets::RequestAudio("stalk.ogg");
146
sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
116
velocity = Vector2::Random() * MAXSPEED;
149
maxspeed = DEFAULT_MAXSPEED;
118
151
//set aiTime to random so creatures tick at different times
119
152
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
174
207
pow(player->noisiness * 2, 2) )
178
210
Ping::NewPing(position, 8.0f, 32.0f, 0.15f);
179
direction = (player->position - position).GetNormalized() * STALKSPEED;
211
direction = (player->position - position).GetNormalized();
212
maxspeed = STALKSPEED;
184
216
// if we've been listening a long time, switch back to idle
203
234
|| Collide("player")
207
direction = (player->position - position).GetNormalized() * HUNTSPEED;
208
// Play hunt noise (REEET!)
213
//after 6 or 7 seconds on the noiseTime clock, play sound and ping again
214
// if we hit a wall, call off the search?
215
//we'll want to play that sound again
216
// do others go ALERT if we start stalking?
217
//probably a timeout here too.
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);
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;
220
303
velocity += direction * ACCELERATION * Monocle::deltaTime;
222
305
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
223
306
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
225
if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
226
velocity = velocity.GetNormalized() * MAXSPEED;
308
if (velocity.GetSquaredMagnitude() > pow(maxspeed, 2))
309
velocity = velocity.GetNormalized() * maxspeed;
228
311
bool xcol = false;
229
312
bool ycol = false;
231
314
position.x += velocity.x * Monocle::deltaTime;
232
while (Collide("Solid"))
315
while (Collide("Solid") || Collide("creaturewall"))
235
318
if (velocity.x == 0) { break; }
249
332
if (ycol) {velocity.y = 0;}
251
if (velocity.GetSquaredMagnitude() > 20)
253
Vector2 distance = ((DarkScene *)scene)->player->position - position;
334
Vector2 distance = ((DarkScene *)scene)->player->position - position;
335
if (state == "stalk")
337
float vol = (distance.GetMagnitude() / -250.0f) + 1.0f;
338
sniff->SetVolume(vol);
340
sprite->Play("slowmove");
342
else if (velocity.GetSquaredMagnitude() > 20)
254
344
// at distance 0, vol should be 1.0. at 800, it should be 0.
255
float vol = (distance.GetMagnitude() / -800.0f) + 1.0f;
345
float vol = (distance.GetMagnitude() / -600.0f) + 1.0f;
256
346
skitter1->SetVolume(vol);
257
347
skitter1->Play();
258
348
sprite->Play("move");
310
400
Graphics::Set2D(1024, 768);
402
Text *inst1 = new Text("Use arrow keys to move");
403
inst1->position = Vector2(-492, -354);
312
406
Text *inst2 = new Text("Press ESC to quit");
313
inst2->position = Vector2(-492, -354); // 20px h, 30px v from U-L corner
407
inst2->position = Vector2(-492, -334); // 20px h, 30px v from U-L corner
316
410
Input::DefineMaskKey("left", KEY_LEFT);
341
435
Vector2 s = e->scale;
342
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));
345
452
Graphics::SetBackgroundColor(Color::green * 0.2f);