/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
 
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