/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 03:38:46 UTC
  • Revision ID: josh@9ix.org-20110918033846-f2unltomwd0ula81
alert noise

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
  Creature::Creature() : Entity(),
95
95
                         FRICTION(800),
96
96
                         MAXSPEED(80.0f),
97
 
                         ACCELERATION(1200),
98
 
                         STALKSPEED(5.0f)
 
97
                         ACCELERATION(1200)                      
99
98
  {
100
99
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
101
100
    sprite->Add("idle", 0, 0, 0.35f);
109
108
 
110
109
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
111
110
    skitter1->SetLoops(0); //loop indefinitely
 
111
 
112
112
    alert = Assets::RequestAudio("alert.ogg");
113
 
    stalk = Assets::RequestAudio("stalk.ogg");
114
113
 
115
114
    velocity = Vector2::Random() * MAXSPEED;
116
115
 
156
155
            state = "alert";
157
156
            alert->Play();
158
157
            direction = Vector2::zero;
159
 
            Ping::NewPing(position, 8.0f, 32.0f, 0.15f); // ping diameter 16-64 over .5s
 
158
            // TODO: Play pulse animation (yellow?)
160
159
            aiTime = 0.0f; // diff variable?  stateTime?
161
160
          }
162
161
      } // if idle or wander
166
165
        
167
166
        // if we've been listening past the grace period and hear
168
167
        // something, switch state again
169
 
        // We hear the player at DOUBLE noisiness distance, cuz WE'RE LISNING!
170
 
        Player *player = ((DarkScene *)scene)->player;
171
 
        if ( aiTime > 1.0f && 
172
 
             (player->position - position).GetSquaredMagnitude() < 
173
 
             pow(player->noisiness * 2, 2) )
174
 
          {
175
 
            state = "stalk";
176
 
            stalk->Play();
177
 
            Ping::NewPing(position, 8.0f, 32.0f, 0.15f);
178
 
            direction = (player->position - position).GetNormalized() * STALKSPEED;
179
 
            aiTime = 0.0f;
180
 
            noiseTime = 0.0f;
181
 
          }
182
168
 
183
169
        // if we've been listening a long time, switch back to idle
184
170
        if (aiTime > 5.0f) {
185
171
          //printf("end alert\n");
186
172
          state = "idle";
187
 
          aiTime = 0.0f;
188
173
        }
189
174
      }
190
 
    else if (state == "stalk")
191
 
      {
192
 
        aiTime += Monocle::deltaTime;
193
 
 
194
 
        // if we hear the player while stalking (normal range), go to HUNT
195
 
 
196
 
        //after 6 or 7 seconds on the noiseTime clock, play sound and ping again
197
 
        // if we hit a wall, call off the search?
198
 
        //we'll want to play that sound again
199
 
        // do others go ALERT if we start stalking?
200
 
        // and if we collide with the player?
201
 
      }
202
175
 
203
176
    velocity += direction * ACCELERATION * Monocle::deltaTime;
204
177
    
247
220
      }
248
221
  }
249
222
 
250
 
  Ping::Ping() : Entity(),
251
 
                 d1(0.0f), d2(0.0f), t(0.0f), t2(0.0f)
252
 
  {
253
 
    sprite = new Sprite("yellow.png", FILTER_LINEAR, 64, 64);
254
 
    SetGraphic(sprite);
255
 
    scale = Vector2::zero;
256
 
  }
257
 
 
258
 
  Ping *Ping::NewPing(Vector2 pos, float d1, float d2, float t2)
259
 
  {
260
 
    Ping *ping = new Ping();
261
 
    ping->d1 = d1;
262
 
    ping->d2 = d2;
263
 
    ping->t2 = t2;
264
 
    ping->position = pos;
265
 
 
266
 
    Game::GetScene()->Add(ping);
267
 
    return ping;
268
 
  }
269
 
 
270
 
  void Ping::Update()
271
 
  {
272
 
    Entity::Update();
273
 
 
274
 
    // once we're done LERPing, get gone
275
 
    if (t > t2)
276
 
      RemoveSelf();
277
 
 
278
 
    t += Monocle::deltaTime;
279
 
    float scaleFactor = LERP(d1/64, d2/64, t/t2);
280
 
    scale = Vector2(scaleFactor, scaleFactor);
281
 
  }
282
 
 
283
223
  // Scene
284
224
 
285
225
  DarkScene::DarkScene() : Scene()