/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:
58
58
    bool xcol = false;
59
59
    bool ycol = false;
60
60
 
61
 
    Collider *collider = NULL;
62
 
 
63
61
    position.x += velocity.x * Monocle::deltaTime;
64
 
    while (Collide("Solid") || (collider = Collide("creature")))
 
62
    while (Collide("Solid"))
65
63
      {
66
 
        // Don't colide with hunters.  We should just die.
67
 
        if (collider) {
68
 
          Creature *c = (Creature *) collider->GetEntity();
69
 
          if (c->state == "hunt") { break; }
70
 
        }
71
 
 
72
64
        xcol = true;
73
65
        if (velocity.x == 0) { break; }
74
66
        //printf("collision1\n");
76
68
      }
77
69
    if (xcol) {velocity.x = 0;}
78
70
 
79
 
    collider = NULL;
80
71
    position.y += velocity.y * Monocle::deltaTime;
81
 
    while (Collide("Solid") || (collider = Collide("creature")))
 
72
    while (Collide("Solid"))
82
73
      {
83
 
        // Don't colide with hunters.  We should just die.
84
 
        if (collider) {
85
 
          Creature *c = (Creature *) collider->GetEntity();
86
 
          if (c->state == "hunt") { break; }
87
 
        }
88
 
 
89
74
        ycol = true;
90
75
        if (velocity.y == 0) { break; }
91
76
        //printf("collision2\n");
99
84
 
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;
103
88
 
104
89
    dark->position = position;
105
90
 
125
110
 
126
111
    alert = Assets::RequestAudio("alert.ogg");
127
112
    freakout = Assets::RequestAudio("freakout.ogg");
128
 
    chomp = Assets::RequestAudio("chomp.ogg");
129
113
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
130
114
    skitter1->SetLoops(0); //loop indefinitely
131
115
    sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
224
208
            maxspeed = 0; // give them a running start
225
209
            sniff->Stop();
226
210
            freakout->Play();
227
 
            Ping::NewPing(position, 8.0f, 64.0f, 0.15f); 
 
211
            // TODO: big yellow ping
228
212
            aiTime = 0.0f;
229
213
            noiseTime = 0.0f;
230
214
          }
232
216
        // Go back to IDLE if:
233
217
        // * we hit a wall
234
218
        // * we stalk for more than 10-15s
235
 
        if ((aiTime > 15.0f) || Collide("wall") || Collide("creaturewall"))
 
219
        if ((aiTime > 15.0f) || Collide("wall"))
236
220
          {
237
221
            // play frustrated noise?
238
222
            state = "idle";
246
230
      {
247
231
        aiTime += Monocle::deltaTime;
248
232
        noiseTime += Monocle::deltaTime;
249
 
        graceTime += Monocle::deltaTime;
250
233
 
251
 
        if ((graceTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
 
234
        if ((aiTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
252
235
          maxspeed = DEFAULT_MAXSPEED;
253
236
 
254
237
        // if we hear the player (
258
241
          {
259
242
            direction = (player->position - position).GetNormalized();
260
243
            aiTime = 0.0f;
261
 
            if (noiseTime > 2.0f) {
 
244
            if (noiseTime > 1.0f) {
262
245
              freakout->Play();
263
 
              Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
 
246
              // TODO: big yellow ping
264
247
              noiseTime = 0.0f;
265
248
            }
266
249
          }
271
254
            //alert->Play();
272
255
            direction = Vector2::zero;
273
256
            aiTime = 0.0f;
274
 
            noiseTime = 0.0f;
275
 
            graceTime = 0.0f;
276
257
        }
277
258
 
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?
281
 
          chomp->Play();
282
 
          DarkScene *scene = (DarkScene *) GetScene();
283
 
          Entity* playersp = scene->GetFirstEntityWithTag("playerspawner");
284
 
          scene->player->position = playersp->position;
285
 
        }
 
259
        // if we collide with you... game over?
286
260
      }
287
261
 
288
262
    velocity += direction * ACCELERATION * Monocle::deltaTime;
297
271
    bool ycol = false;
298
272
 
299
273
    position.x += velocity.x * Monocle::deltaTime;
300
 
    while (Collide("Solid") || Collide("creaturewall"))
 
274
    while (Collide("Solid"))
301
275
      {
302
276
        xcol = true;
303
277
        if (velocity.x == 0) { break; }
307
281
    if (xcol) {velocity.x = 0;}
308
282
 
309
283
    position.y += velocity.y * Monocle::deltaTime;
310
 
    while (Collide("Solid") || Collide("creaturewall"))
 
284
    while (Collide("Solid"))
311
285
      {
312
286
        ycol = true;
313
287
        if (velocity.y == 0) { break; }
416
390
        Vector2 s = e->scale;
417
391
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
418
392
      }
419
 
 
420
 
    std::list<Entity*> *creaturewalls = GetAllTag("creaturewall");
421
 
    for (std::list<Entity*>::iterator i = creaturewalls->begin(); i != creaturewalls->end(); ++i)
422
 
      {
423
 
        Entity *e = (*i);
424
 
        Vector2 s = e->scale;
425
 
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
426
 
      }
427
393
   
428
394
    Graphics::SetBackgroundColor(Color::green * 0.2f);
429
395