/minild29

To get this branch, use:
bzr branch http://9ix.org/bzr/minild29

« back to all changes in this revision

Viewing changes to Dark.cpp

  • Committer: Josh C
  • Date: 2011-09-18 22:31:01 UTC
  • Revision ID: josh@9ix.org-20110918223101-7s86wvx5dkkekhgg
now they chase you (hunt)

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
 
85
85
    // How far away can they hear your footsteps?
86
86
    // The circle is diameter 300 at MAXSPEED, 32 (2x your size) at 0 speed
87
 
    noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
 
87
    noisiness = ((magnitude / MAXSPEED *(300-32)) + 32) /2;
88
88
 
89
89
    dark->position = position;
90
90
 
106
106
    scale = Vector2(0.25, 0.25);
107
107
 
108
108
    AddTag("creature");
109
 
    AddTag("Solid");
110
109
    SetCollider(new RectangleCollider(16, 16));
111
110
 
112
111
    alert = Assets::RequestAudio("alert.ogg");
209
208
            maxspeed = 0; // give them a running start
210
209
            sniff->Stop();
211
210
            freakout->Play();
212
 
            Ping::NewPing(position, 8.0f, 64.0f, 0.15f); 
 
211
            // TODO: big yellow ping
213
212
            aiTime = 0.0f;
214
213
            noiseTime = 0.0f;
215
214
          }
217
216
        // Go back to IDLE if:
218
217
        // * we hit a wall
219
218
        // * we stalk for more than 10-15s
220
 
        if ((aiTime > 15.0f) || Collide("wall") || Collide("creaturewall"))
 
219
        if ((aiTime > 15.0f) || Collide("wall"))
221
220
          {
222
221
            // play frustrated noise?
223
222
            state = "idle";
231
230
      {
232
231
        aiTime += Monocle::deltaTime;
233
232
        noiseTime += Monocle::deltaTime;
234
 
        graceTime += Monocle::deltaTime;
235
233
 
236
 
        if ((graceTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
 
234
        if ((aiTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
237
235
          maxspeed = DEFAULT_MAXSPEED;
238
236
 
239
237
        // if we hear the player (
243
241
          {
244
242
            direction = (player->position - position).GetNormalized();
245
243
            aiTime = 0.0f;
246
 
            if (noiseTime > 2.0f) {
 
244
            if (noiseTime > 1.0f) {
247
245
              freakout->Play();
248
 
              Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
 
246
              // TODO: big yellow ping
249
247
              noiseTime = 0.0f;
250
248
            }
251
249
          }
256
254
            //alert->Play();
257
255
            direction = Vector2::zero;
258
256
            aiTime = 0.0f;
259
 
            noiseTime = 0.0f;
260
 
            graceTime = 0.0f;
261
257
        }
262
258
 
263
 
        // if we collide with you, move you back to the starting point
264
 
        if (Collide("player")) {
265
 
          // TODO: first, make chompy noises and wait a second or 3?
266
 
          DarkScene *scene = (DarkScene *) GetScene();
267
 
          Entity* playersp = scene->GetFirstEntityWithTag("playerspawner");
268
 
          scene->player->position = playersp->position;
269
 
        }
 
259
        // if we collide with you... game over?
270
260
      }
271
261
 
272
262
    velocity += direction * ACCELERATION * Monocle::deltaTime;
281
271
    bool ycol = false;
282
272
 
283
273
    position.x += velocity.x * Monocle::deltaTime;
284
 
    while (Collide("Solid") || Collide("creaturewall"))
 
274
    while (Collide("Solid"))
285
275
      {
286
276
        xcol = true;
287
277
        if (velocity.x == 0) { break; }
291
281
    if (xcol) {velocity.x = 0;}
292
282
 
293
283
    position.y += velocity.y * Monocle::deltaTime;
294
 
    while (Collide("Solid") || Collide("creaturewall"))
 
284
    while (Collide("Solid"))
295
285
      {
296
286
        ycol = true;
297
287
        if (velocity.y == 0) { break; }
400
390
        Vector2 s = e->scale;
401
391
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
402
392
      }
403
 
 
404
 
    std::list<Entity*> *creaturewalls = GetAllTag("creaturewall");
405
 
    for (std::list<Entity*>::iterator i = creaturewalls->begin(); i != creaturewalls->end(); ++i)
406
 
      {
407
 
        Entity *e = (*i);
408
 
        Vector2 s = e->scale;
409
 
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
410
 
      }
411
393
   
412
394
    Graphics::SetBackgroundColor(Color::green * 0.2f);
413
395