61
Collider *collider = NULL;
63
61
position.x += velocity.x * Monocle::deltaTime;
64
while (Collide("Solid") || (collider = Collide("creature")))
62
while (Collide("Solid"))
66
// Don't colide with hunters. We should just die.
68
Creature *c = (Creature *) collider->GetEntity();
69
if (c->state == "hunt") { break; }
73
65
if (velocity.x == 0) { break; }
74
66
//printf("collision1\n");
77
69
if (xcol) {velocity.x = 0;}
80
71
position.y += velocity.y * Monocle::deltaTime;
81
while (Collide("Solid") || (collider = Collide("creature")))
72
while (Collide("Solid"))
83
// Don't colide with hunters. We should just die.
85
Creature *c = (Creature *) collider->GetEntity();
86
if (c->state == "hunt") { break; }
90
75
if (velocity.y == 0) { break; }
91
76
//printf("collision2\n");
100
85
// How far away can they hear your footsteps?
101
86
// The circle is diameter 300 at MAXSPEED, 32 (2x your size) at 0 speed
102
noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
87
noisiness = ((magnitude / MAXSPEED *(300-32)) + 32) /2;
104
89
dark->position = position;
123
108
AddTag("creature");
124
109
SetCollider(new RectangleCollider(16, 16));
126
alert = Assets::RequestAudio("alert.ogg");
127
freakout = Assets::RequestAudio("freakout.ogg");
128
chomp = Assets::RequestAudio("chomp.ogg");
129
111
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
130
112
skitter1->SetLoops(0); //loop indefinitely
113
alert = Assets::RequestAudio("alert.ogg");
131
114
sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
132
115
sniff->SetLoops(0);
219
204
|| Collide("player")
223
direction = (player->position - position).GetNormalized();
224
maxspeed = 0; // give them a running start
227
Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
232
// Go back to IDLE if:
234
// * we stalk for more than 10-15s
235
if ((aiTime > 15.0f) || Collide("wall") || Collide("creaturewall"))
237
// play frustrated noise?
241
maxspeed = DEFAULT_MAXSPEED;
242
direction = Vector2::zero;
245
else if (state == "hunt")
247
aiTime += Monocle::deltaTime;
248
noiseTime += Monocle::deltaTime;
249
graceTime += Monocle::deltaTime;
251
if ((graceTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
252
maxspeed = DEFAULT_MAXSPEED;
254
// if we hear the player (
255
Player *player = ((DarkScene *)scene)->player;
256
if ( (player->position - position).GetSquaredMagnitude() <
257
pow(player->noisiness, 2) )
259
direction = (player->position - position).GetNormalized();
261
if (noiseTime > 2.0f) {
263
Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
268
// I guess chill out if it's been a while
269
if (aiTime > 15.0f) {
272
direction = Vector2::zero;
278
// if we collide with you, move you back to the starting point
279
if (Collide("player")) {
280
// TODO: first wait a second or 3?
282
DarkScene *scene = (DarkScene *) GetScene();
283
Entity* playersp = scene->GetFirstEntityWithTag("playerspawner");
284
scene->player->position = playersp->position;
208
direction = (player->position - position).GetNormalized();
209
//maxspeed = DEFAULT_MAXSPEED;
210
// Play hunt noise (REEET!)
215
//after 6 or 7 seconds on the noiseTime clock, play sound and ping again
216
// if we hit a wall, call off the search?
217
//we'll want to play that sound again
218
// do others go ALERT if we start stalking?
219
//probably a timeout here too.
288
222
velocity += direction * ACCELERATION * Monocle::deltaTime;
416
350
Vector2 s = e->scale;
417
351
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
420
std::list<Entity*> *creaturewalls = GetAllTag("creaturewall");
421
for (std::list<Entity*>::iterator i = creaturewalls->begin(); i != creaturewalls->end(); ++i)
424
Vector2 s = e->scale;
425
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
428
354
Graphics::SetBackgroundColor(Color::green * 0.2f);