/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:21:36 UTC
  • Revision ID: josh@9ix.org-20110918032136-bprcfnl3jg5xmjsx
track palyer noisiness, beginnings of "alert" state for creatures

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
110
110
    skitter1->SetLoops(0); //loop indefinitely
111
111
 
112
 
    alert = Assets::RequestAudio("alert.ogg");
113
 
 
114
112
    velocity = Vector2::Random() * MAXSPEED;
115
113
 
116
114
    //set aiTime to random so creatures tick at different times
117
115
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
118
 
 
119
 
    state = "idle";
120
116
  }
121
117
 
122
118
  void Creature::Update()
151
147
        if ( (player->position - position).GetSquaredMagnitude() < 
152
148
             pow(player->noisiness, 2) )
153
149
          {
154
 
            //printf("alert\n");
155
150
            state = "alert";
156
 
            alert->Play();
 
151
            // TODO: Play startled noise
157
152
            direction = Vector2::zero;
158
 
            Ping::NewPing(position, 8.0f, 32.0f, 0.15f); // ping diameter 16-64 over .5s
 
153
            // TODO: Play pulse animation (yellow?)
159
154
            aiTime = 0.0f; // diff variable?  stateTime?
160
155
          }
161
156
      } // if idle or wander
167
162
        // something, switch state again
168
163
 
169
164
        // if we've been listening a long time, switch back to idle
170
 
        if (aiTime > 5.0f) {
171
 
          //printf("end alert\n");
172
 
          state = "idle";
173
 
        }
174
165
      }
175
166
 
176
167
    velocity += direction * ACCELERATION * Monocle::deltaTime;
220
211
      }
221
212
  }
222
213
 
223
 
  Ping::Ping() : Entity(),
224
 
                 d1(0.0f), d2(0.0f), t(0.0f), t2(0.0f)
225
 
  {
226
 
    sprite = new Sprite("yellow.png", FILTER_LINEAR, 64, 64);
227
 
    SetGraphic(sprite);
228
 
    scale = Vector2::zero;
229
 
  }
230
 
 
231
 
  Ping *Ping::NewPing(Vector2 pos, float d1, float d2, float t2)
232
 
  {
233
 
    Ping *ping = new Ping();
234
 
    ping->d1 = d1;
235
 
    ping->d2 = d2;
236
 
    ping->t2 = t2;
237
 
    ping->position = pos;
238
 
 
239
 
    Game::GetScene()->Add(ping);
240
 
    return ping;
241
 
  }
242
 
 
243
 
  void Ping::Update()
244
 
  {
245
 
    Entity::Update();
246
 
 
247
 
    // once we're done LERPing, get gone
248
 
    if (t > t2)
249
 
      RemoveSelf();
250
 
 
251
 
    t += Monocle::deltaTime;
252
 
    float scaleFactor = LERP(d1/64, d2/64, t/t2);
253
 
    scale = Vector2(scaleFactor, scaleFactor);
254
 
  }
255
 
 
256
214
  // Scene
257
215
 
258
216
  DarkScene::DarkScene() : Scene()