/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 05:20:04 UTC
  • Revision ID: josh@9ix.org-20110918052004-h8uksv9kzu7vdh0w
beginnings of "stalk" state

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)                      
 
97
                         ACCELERATION(1200),
 
98
                         STALKSPEED(5.0f)
98
99
  {
99
100
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
100
101
    sprite->Add("idle", 0, 0, 0.35f);
108
109
 
109
110
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
110
111
    skitter1->SetLoops(0); //loop indefinitely
111
 
 
112
112
    alert = Assets::RequestAudio("alert.ogg");
 
113
    stalk = Assets::RequestAudio("stalk.ogg");
113
114
 
114
115
    velocity = Vector2::Random() * MAXSPEED;
115
116
 
155
156
            state = "alert";
156
157
            alert->Play();
157
158
            direction = Vector2::zero;
158
 
            // TODO: Play pulse animation (yellow?)
 
159
            Ping::NewPing(position, 8.0f, 32.0f, 0.15f); // ping diameter 16-64 over .5s
159
160
            aiTime = 0.0f; // diff variable?  stateTime?
160
161
          }
161
162
      } // if idle or wander
165
166
        
166
167
        // if we've been listening past the grace period and hear
167
168
        // 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
          }
168
182
 
169
183
        // if we've been listening a long time, switch back to idle
170
184
        if (aiTime > 5.0f) {
171
185
          //printf("end alert\n");
172
186
          state = "idle";
 
187
          aiTime = 0.0f;
173
188
        }
174
189
      }
 
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
      }
175
202
 
176
203
    velocity += direction * ACCELERATION * Monocle::deltaTime;
177
204
    
220
247
      }
221
248
  }
222
249
 
 
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
 
223
283
  // Scene
224
284
 
225
285
  DarkScene::DarkScene() : Scene()