/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 21:57:43 UTC
  • Revision ID: josh@9ix.org-20110918215743-5vlccbqee5hqqk9b
I really don't need the source AUPs.  There's enough crap in here 
already.

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
 
    if (Collide("exit")) {
62
 
      Scene *s = GetScene();
63
 
      s->isPaused = true;
64
 
      
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);
68
 
      s->Add(win1);
69
 
 
70
 
      Text *win2 = new Text("Congratulations!", 
71
 
                           Assets::RequestFont("LiberationSans-Regular.ttf", 50.0f));
72
 
      win2->position = Vector2(-150,50);
73
 
      s->Add(win2);
74
 
    }
75
 
 
76
 
    Collider *collider = NULL;
77
 
 
78
61
    position.x += velocity.x * Monocle::deltaTime;
79
 
    while (Collide("Solid") || (collider = Collide("creature")))
 
62
    while (Collide("Solid"))
80
63
      {
81
 
        // Don't colide with hunters.  We should just die.
82
 
        if (collider) {
83
 
          Creature *c = (Creature *) collider->GetEntity();
84
 
          if (c->state == "hunt") { break; }
85
 
        }
86
 
 
87
64
        xcol = true;
88
65
        if (velocity.x == 0) { break; }
89
66
        //printf("collision1\n");
91
68
      }
92
69
    if (xcol) {velocity.x = 0;}
93
70
 
94
 
    collider = NULL;
95
71
    position.y += velocity.y * Monocle::deltaTime;
96
 
    while (Collide("Solid") || (collider = Collide("creature")))
 
72
    while (Collide("Solid"))
97
73
      {
98
 
        // Don't colide with hunters.  We should just die.
99
 
        if (collider) {
100
 
          Creature *c = (Creature *) collider->GetEntity();
101
 
          if (c->state == "hunt") { break; }
102
 
        }
103
 
 
104
74
        ycol = true;
105
75
        if (velocity.y == 0) { break; }
106
76
        //printf("collision2\n");
114
84
 
115
85
    // How far away can they hear your footsteps?
116
86
    // The circle is diameter 300 at MAXSPEED, 32 (2x your size) at 0 speed
117
 
    noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
 
87
    noisiness = ((magnitude / MAXSPEED *(300-32)) + 32) /2;
118
88
 
119
89
    dark->position = position;
120
90
 
138
108
    AddTag("creature");
139
109
    SetCollider(new RectangleCollider(16, 16));
140
110
 
141
 
    alert = Assets::RequestAudio("alert.ogg");
142
 
    freakout = Assets::RequestAudio("freakout.ogg");
143
 
    chomp = Assets::RequestAudio("chomp.ogg");
144
111
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
145
112
    skitter1->SetLoops(0); //loop indefinitely
 
113
    alert = Assets::RequestAudio("alert.ogg");
146
114
    sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
147
115
    sniff->SetLoops(0);
148
116
 
234
202
            || Collide("player")
235
203
            )
236
204
          {
237
 
            state = "hunt";
 
205
            //state = "hunt";
238
206
            direction = (player->position - position).GetNormalized();
239
 
            maxspeed = 0; // give them a running start
240
 
            sniff->Stop();
241
 
            freakout->Play();
242
 
            Ping::NewPing(position, 8.0f, 64.0f, 0.15f); 
243
 
            aiTime = 0.0f;
244
 
            noiseTime = 0.0f;
 
207
            //maxspeed = DEFAULT_MAXSPEED;
 
208
            // Play hunt noise (REEET!)
 
209
            //aiTime = 0.0f;
245
210
          }
246
211
 
247
212
        // Go back to IDLE if:
248
213
        // * we hit a wall
249
 
        // * we stalk for more than 10-15s
250
 
        if ((aiTime > 15.0f) || Collide("wall") || Collide("creaturewall"))
 
214
        // * we hunt for more than 10-15s
 
215
        if ((aiTime > 15.0f) || Collide("wall"))
251
216
          {
252
217
            // play frustrated noise?
253
218
            state = "idle";
257
222
            direction = Vector2::zero;
258
223
          }
259
224
      }
260
 
    else if (state == "hunt")
261
 
      {
262
 
        aiTime += Monocle::deltaTime;
263
 
        noiseTime += Monocle::deltaTime;
264
 
        graceTime += Monocle::deltaTime;
265
 
 
266
 
        if ((graceTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
267
 
          maxspeed = DEFAULT_MAXSPEED;
268
 
 
269
 
        // if we hear the player (
270
 
        Player *player = ((DarkScene *)scene)->player;
271
 
        if ( (player->position - position).GetSquaredMagnitude() < 
272
 
             pow(player->noisiness, 2) )
273
 
          {
274
 
            direction = (player->position - position).GetNormalized();
275
 
            aiTime = 0.0f;
276
 
            if (noiseTime > 2.0f) {
277
 
              freakout->Play();
278
 
              Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
279
 
              noiseTime = 0.0f;
280
 
            }
281
 
          }
282
 
 
283
 
        // I guess chill out if it's been a while
284
 
        if (aiTime > 15.0f) {
285
 
            state = "alert";
286
 
            //alert->Play();
287
 
            direction = Vector2::zero;
288
 
            aiTime = 0.0f;
289
 
            noiseTime = 0.0f;
290
 
            graceTime = 0.0f;
291
 
        }
292
 
 
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?
296
 
          chomp->Play();
297
 
          DarkScene *scene = (DarkScene *) GetScene();
298
 
          Entity* playersp = scene->GetFirstEntityWithTag("playerspawner");
299
 
          scene->player->position = playersp->position;
300
 
        }
301
 
      }
302
225
 
303
226
    velocity += direction * ACCELERATION * Monocle::deltaTime;
304
227
    
312
235
    bool ycol = false;
313
236
 
314
237
    position.x += velocity.x * Monocle::deltaTime;
315
 
    while (Collide("Solid") || Collide("creaturewall"))
 
238
    while (Collide("Solid"))
316
239
      {
317
240
        xcol = true;
318
241
        if (velocity.x == 0) { break; }
322
245
    if (xcol) {velocity.x = 0;}
323
246
 
324
247
    position.y += velocity.y * Monocle::deltaTime;
325
 
    while (Collide("Solid") || Collide("creaturewall"))
 
248
    while (Collide("Solid"))
326
249
      {
327
250
        ycol = true;
328
251
        if (velocity.y == 0) { break; }
399
322
 
400
323
    Graphics::Set2D(1024, 768);
401
324
 
402
 
    Text *inst1 = new Text("Use arrow keys to move");
403
 
    inst1->position = Vector2(-492, -354);
404
 
    Add(inst1);
405
 
 
406
325
    Text *inst2 = new Text("Press ESC to quit");
407
 
    inst2->position = Vector2(-492, -334); // 20px h, 30px v from U-L corner
 
326
    inst2->position = Vector2(-492, -354); // 20px h, 30px v from U-L corner
408
327
    Add(inst2);
409
328
 
410
329
    Input::DefineMaskKey("left", KEY_LEFT);
435
354
        Vector2 s = e->scale;
436
355
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
437
356
      }
438
 
 
439
 
    std::list<Entity*> *creaturewalls = GetAllTag("creaturewall");
440
 
    for (std::list<Entity*>::iterator i = creaturewalls->begin(); i != creaturewalls->end(); ++i)
441
 
      {
442
 
        Entity *e = (*i);
443
 
        Vector2 s = e->scale;
444
 
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
445
 
      }
446
 
 
447
 
    Entity* exit = GetFirstEntityWithTag("exit");
448
 
    Vector2 s = exit->scale;
449
 
    exit->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
450
 
 
451
357
   
452
358
    Graphics::SetBackgroundColor(Color::green * 0.2f);
453
359