/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:
95
95
                         FRICTION(800),
96
96
                         MAXSPEED(80.0f),
97
97
                         ACCELERATION(1200),
98
 
                         STALKSPEED(5.0f),
99
 
                         HUNTSPEED(80.0f)
 
98
                         STALKSPEED(5.0f)
100
99
  {
101
100
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
102
101
    sprite->Add("idle", 0, 0, 0.35f);
191
190
    else if (state == "stalk")
192
191
      {
193
192
        aiTime += Monocle::deltaTime;
194
 
        noiseTime += Monocle::deltaTime;
195
 
 
196
 
        // Go to HUNT if:
197
 
        // * it's been >1s & we hear the player
198
 
        // * we collide with the player
199
 
        Player *player = ((DarkScene *)scene)->player;
200
 
        if ((aiTime > 1.0f &&  
201
 
             (player->position - position).GetSquaredMagnitude() < 
202
 
             pow(player->noisiness, 2) )
203
 
            || Collide("player")
204
 
            )
205
 
          {
206
 
            state == "hunt";
207
 
            direction = (player->position - position).GetNormalized() * HUNTSPEED;
208
 
            // Play hunt noise (REEET!)
209
 
 
210
 
          }
211
 
          
212
 
          
 
193
 
 
194
        // if we hear the player while stalking (normal range), go to HUNT
 
195
 
213
196
        //after 6 or 7 seconds on the noiseTime clock, play sound and ping again
214
197
        // if we hit a wall, call off the search?
215
198
        //we'll want to play that sound again
216
199
        // do others go ALERT if we start stalking?
217
 
        //probably a timeout here too.
 
200
        // and if we collide with the player?
218
201
      }
219
202
 
220
203
    velocity += direction * ACCELERATION * Monocle::deltaTime;
331
314
    Level::LoadProject("project.xml");
332
315
    Level::Load("level.xml", this);
333
316
 
334
 
    HideSpawners();
335
 
    Spawn();
336
 
 
337
317
    std::list<Entity*> *walls = GetAllTag("wall");
338
318
    for (std::list<Entity*>::iterator i = walls->begin(); i != walls->end(); ++i)
339
319
      {
342
322
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
343
323
      }
344
324
   
345
 
    Graphics::SetBackgroundColor(Color::green * 0.2f);
346
 
 
347
 
  }
348
 
 
349
 
  void DarkScene::HideSpawners()
350
 
  {
351
 
    std::list<Entity*> *spawners = GetAllTag("spawner");
352
 
    if (spawners == NULL) {printf("NO SPAWNERS!!!\n");}
353
 
    for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
354
 
      (*i)->isVisible = false;
355
 
  }
356
 
 
357
 
  void DarkScene::ShowSpawners()
358
 
  {
359
 
    std::list<Entity*> *spawners = GetAllTag("spawner");
360
 
    for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
361
 
      (*i)->isVisible = true;
362
 
  }
363
 
  
364
 
  void DarkScene::Spawn()
365
 
  {
366
 
    Entity* playersp = GetFirstEntityWithTag("playerspawner");
367
325
    player = new Player();
368
 
    player->position = playersp->position;;
 
326
    player->position = Graphics::GetScreenCenter();
369
327
    Add(player);
370
328
    Add(player->dark);
371
329
 
372
 
    std::list<Entity*> *spawners = GetAllTag("creaturespawner");
373
 
    // Ugh, monocle is double-entering all the tags...
374
 
    spawners->sort();
375
 
    spawners->unique();
376
 
    for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
377
 
      {
378
 
        Creature *creature = new Creature();
379
 
        creature->position = (*i)->position;
380
 
        Add(creature);
381
 
      }
 
330
    Creature *creature = new Creature;
 
331
    creature->position = Graphics::GetScreenCenter();
 
332
    Add(creature);
 
333
 
 
334
    Creature *creature2 = new Creature;
 
335
    creature2->position = Graphics::GetScreenCenter();
 
336
    Add(creature2);
 
337
 
 
338
    Graphics::SetBackgroundColor(Color::green * 0.2f);
 
339
 
382
340
  }
383
341
 
384
342
  void DarkScene::Update()
409
367
            
410
368
            if (isPaused) {
411
369
              player->dark->isVisible = false;
412
 
              ShowSpawners();
413
370
              levelEditor->Enable();
414
371
            } else {
415
 
              HideSpawners();
416
372
              levelEditor->Disable();
417
373
              player->dark->isVisible = true;
418
374
            }