61
Collider *collider = NULL;
61
63
position.x += velocity.x * Monocle::deltaTime;
62
while (Collide("Solid"))
64
while (Collide("Solid") || (collider = Collide("creature")))
66
// Don't colide with hunters. We should just die.
68
Creature *c = (Creature *) collider->GetEntity();
69
if (c->state == "hunt") { break; }
65
73
if (velocity.x == 0) { break; }
66
74
//printf("collision1\n");
69
77
if (xcol) {velocity.x = 0;}
71
80
position.y += velocity.y * Monocle::deltaTime;
72
while (Collide("Solid"))
81
while (Collide("Solid") || (collider = Collide("creature")))
83
// Don't colide with hunters. We should just die.
85
Creature *c = (Creature *) collider->GetEntity();
86
if (c->state == "hunt") { break; }
75
90
if (velocity.y == 0) { break; }
76
91
//printf("collision2\n");
85
100
// How far away can they hear your footsteps?
86
101
// The circle is diameter 300 at MAXSPEED, 32 (2x your size) at 0 speed
87
noisiness = ((magnitude / MAXSPEED *(300-32)) + 32) /2;
102
noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
89
104
dark->position = position;
94
109
Creature::Creature() : Entity(),
97
111
ACCELERATION(1200),
112
DEFAULT_MAXSPEED(80.0f),
101
115
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
102
116
sprite->Add("idle", 0, 0, 0.35f);
103
117
sprite->Add("move", 1, 2, 4.0f);
118
sprite->Add("slowmove", 1, 2, 2.0f);
104
119
sprite->Play("idle");
105
120
SetGraphic(sprite);
106
121
scale = Vector2(0.25, 0.25);
108
123
AddTag("creature");
109
124
SetCollider(new RectangleCollider(16, 16));
126
alert = Assets::RequestAudio("alert.ogg");
127
freakout = Assets::RequestAudio("freakout.ogg");
128
chomp = Assets::RequestAudio("chomp.ogg");
111
129
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
112
130
skitter1->SetLoops(0); //loop indefinitely
113
alert = Assets::RequestAudio("alert.ogg");
114
stalk = Assets::RequestAudio("stalk.ogg");
131
sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
116
velocity = Vector2::Random() * MAXSPEED;
134
maxspeed = DEFAULT_MAXSPEED;
118
136
//set aiTime to random so creatures tick at different times
119
137
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
174
192
pow(player->noisiness * 2, 2) )
178
195
Ping::NewPing(position, 8.0f, 32.0f, 0.15f);
179
direction = (player->position - position).GetNormalized() * STALKSPEED;
196
direction = (player->position - position).GetNormalized();
197
maxspeed = STALKSPEED;
184
201
// if we've been listening a long time, switch back to idle
203
219
|| 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.
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;
220
288
velocity += direction * ACCELERATION * Monocle::deltaTime;
222
290
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
223
291
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
225
if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
226
velocity = velocity.GetNormalized() * MAXSPEED;
293
if (velocity.GetSquaredMagnitude() > pow(maxspeed, 2))
294
velocity = velocity.GetNormalized() * maxspeed;
228
296
bool xcol = false;
229
297
bool ycol = false;
231
299
position.x += velocity.x * Monocle::deltaTime;
232
while (Collide("Solid"))
300
while (Collide("Solid") || Collide("creaturewall"))
235
303
if (velocity.x == 0) { break; }
249
317
if (ycol) {velocity.y = 0;}
251
if (velocity.GetSquaredMagnitude() > 20)
253
Vector2 distance = ((DarkScene *)scene)->player->position - position;
319
Vector2 distance = ((DarkScene *)scene)->player->position - position;
320
if (state == "stalk")
322
float vol = (distance.GetMagnitude() / -250.0f) + 1.0f;
323
sniff->SetVolume(vol);
325
sprite->Play("slowmove");
327
else if (velocity.GetSquaredMagnitude() > 20)
254
329
// at distance 0, vol should be 1.0. at 800, it should be 0.
255
float vol = (distance.GetMagnitude() / -800.0f) + 1.0f;
330
float vol = (distance.GetMagnitude() / -600.0f) + 1.0f;
256
331
skitter1->SetVolume(vol);
257
332
skitter1->Play();
258
333
sprite->Play("move");
341
416
Vector2 s = e->scale;
342
417
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));
345
428
Graphics::SetBackgroundColor(Color::green * 0.2f);