/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 18:28:31 UTC
  • Revision ID: josh@9ix.org-20110918182831-w01844h80jb8r2y0
stalker moves slow and sniffs (and doesn't scuttle)

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
 
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");
113
111
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
114
112
    skitter1->SetLoops(0); //loop indefinitely
 
113
    alert = Assets::RequestAudio("alert.ogg");
115
114
    sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
116
115
    sniff->SetLoops(0);
117
116
 
180
179
            direction = (player->position - position).GetNormalized();
181
180
            maxspeed = STALKSPEED;
182
181
            aiTime = 0.0f;
 
182
            noiseTime = 0.0f;
183
183
          }
184
184
 
185
185
        // if we've been listening a long time, switch back to idle
192
192
    else if (state == "stalk")
193
193
      {
194
194
        aiTime += Monocle::deltaTime;
 
195
        noiseTime += Monocle::deltaTime;
195
196
 
196
197
        // Go to HUNT if:
197
198
        // * it's been >1s & we hear the player
203
204
            || Collide("player")
204
205
            )
205
206
          {
206
 
            state = "hunt";
207
 
            direction = (player->position - position).GetNormalized();
208
 
            maxspeed = 0; // give them a running start
209
 
            sniff->Stop();
210
 
            freakout->Play();
211
 
            Ping::NewPing(position, 8.0f, 64.0f, 0.15f); 
212
 
            aiTime = 0.0f;
213
 
            noiseTime = 0.0f;
214
 
          }
215
 
 
216
 
        // Go back to IDLE if:
217
 
        // * we hit a wall
218
 
        // * we stalk for more than 10-15s
219
 
        if ((aiTime > 15.0f) || Collide("wall"))
220
 
          {
221
 
            // play frustrated noise?
222
 
            state = "idle";
223
 
            aiTime = 0.0f;
224
 
            sniff->Stop();
225
 
            maxspeed = DEFAULT_MAXSPEED;
226
 
            direction = Vector2::zero;
227
 
          }
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
 
              Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
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?
 
207
            //state = "hunt";
 
208
            direction = (player->position - position).GetNormalized();
 
209
            //maxspeed = DEFAULT_MAXSPEED;
 
210
            // Play hunt noise (REEET!)
 
211
 
 
212
          }
 
213
          
 
214
          
 
215
        //after 6 or 7 seconds on the noiseTime clock, play sound and ping again
 
216
        // if we hit a wall, call off the search?
 
217
        //we'll want to play that sound again
 
218
        // do others go ALERT if we start stalking?
 
219
        //probably a timeout here too.
263
220
      }
264
221
 
265
222
    velocity += direction * ACCELERATION * Monocle::deltaTime;
296
253
    Vector2 distance = ((DarkScene *)scene)->player->position - position;
297
254
    if (state == "stalk")
298
255
      {
299
 
        float vol = (distance.GetMagnitude() / -250.0f) + 1.0f;
 
256
        float vol = (distance.GetMagnitude() / 250.0f) + 1.0f;
300
257
        sniff->SetVolume(vol);
301
258
        sniff->Play();
302
259
        sprite->Play("slowmove");