/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:42:59 UTC
  • Revision ID: josh@9ix.org-20110918224259-0yxyd99mvuadfarf
they hear you more + fixed a bug if they're right on top of you

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 *(300-32)) + 32) /2;
 
87
    noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
88
88
 
89
89
    dark->position = position;
90
90
 
108
108
    AddTag("creature");
109
109
    SetCollider(new RectangleCollider(16, 16));
110
110
 
 
111
    alert = Assets::RequestAudio("alert.ogg");
 
112
    freakout = Assets::RequestAudio("freakout.ogg");
111
113
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
112
114
    skitter1->SetLoops(0); //loop indefinitely
113
 
    alert = Assets::RequestAudio("alert.ogg");
114
115
    sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
115
116
    sniff->SetLoops(0);
116
117
 
202
203
            || Collide("player")
203
204
            )
204
205
          {
205
 
            //state = "hunt";
 
206
            state = "hunt";
206
207
            direction = (player->position - position).GetNormalized();
207
 
            //maxspeed = DEFAULT_MAXSPEED;
208
 
            // Play hunt noise (REEET!)
209
 
            //aiTime = 0.0f;
 
208
            maxspeed = 0; // give them a running start
 
209
            sniff->Stop();
 
210
            freakout->Play();
 
211
            // TODO: big yellow ping
 
212
            aiTime = 0.0f;
 
213
            noiseTime = 0.0f;
210
214
          }
211
215
 
212
216
        // Go back to IDLE if:
213
217
        // * we hit a wall
214
 
        // * we hunt for more than 10-15s
 
218
        // * we stalk for more than 10-15s
215
219
        if ((aiTime > 15.0f) || Collide("wall"))
216
220
          {
217
221
            // play frustrated noise?
222
226
            direction = Vector2::zero;
223
227
          }
224
228
      }
 
229
    else if (state == "hunt")
 
230
      {
 
231
        aiTime += Monocle::deltaTime;
 
232
        noiseTime += Monocle::deltaTime;
 
233
        graceTime += Monocle::deltaTime;
 
234
 
 
235
        if ((graceTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
 
236
          maxspeed = DEFAULT_MAXSPEED;
 
237
 
 
238
        // if we hear the player (
 
239
        Player *player = ((DarkScene *)scene)->player;
 
240
        if ( (player->position - position).GetSquaredMagnitude() < 
 
241
             pow(player->noisiness, 2) )
 
242
          {
 
243
            direction = (player->position - position).GetNormalized();
 
244
            aiTime = 0.0f;
 
245
            if (noiseTime > 2.0f) {
 
246
              freakout->Play();
 
247
              // TODO: big yellow ping
 
248
              noiseTime = 0.0f;
 
249
            }
 
250
          }
 
251
 
 
252
        // I guess chill out if it's been a while
 
253
        if (aiTime > 15.0f) {
 
254
            state = "alert";
 
255
            //alert->Play();
 
256
            direction = Vector2::zero;
 
257
            aiTime = 0.0f;
 
258
            noiseTime = 0.0f;
 
259
            graceTime = 0.0f;
 
260
        }
 
261
 
 
262
        // if we collide with you... game over?
 
263
      }
225
264
 
226
265
    velocity += direction * ACCELERATION * Monocle::deltaTime;
227
266