/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 16:59:41 UTC
  • Revision ID: josh@9ix.org-20110918165941-waswg2xidvf0v04x
player and creature spawners in level editor

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)
 
98
                         STALKSPEED(5.0f),
 
99
                         HUNTSPEED(80.0f)
99
100
  {
100
101
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
101
102
    sprite->Add("idle", 0, 0, 0.35f);
190
191
    else if (state == "stalk")
191
192
      {
192
193
        aiTime += Monocle::deltaTime;
193
 
 
194
 
        // if we hear the player while stalking (normal range), go to HUNT
195
 
 
 
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
          
196
213
        //after 6 or 7 seconds on the noiseTime clock, play sound and ping again
197
214
        // if we hit a wall, call off the search?
198
215
        //we'll want to play that sound again
199
216
        // do others go ALERT if we start stalking?
200
 
        // and if we collide with the player?
 
217
        //probably a timeout here too.
201
218
      }
202
219
 
203
220
    velocity += direction * ACCELERATION * Monocle::deltaTime;
314
331
    Level::LoadProject("project.xml");
315
332
    Level::Load("level.xml", this);
316
333
 
 
334
    HideSpawners();
 
335
    Spawn();
 
336
 
317
337
    std::list<Entity*> *walls = GetAllTag("wall");
318
338
    for (std::list<Entity*>::iterator i = walls->begin(); i != walls->end(); ++i)
319
339
      {
322
342
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
323
343
      }
324
344
   
 
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");
325
367
    player = new Player();
326
 
    player->position = Graphics::GetScreenCenter();
 
368
    player->position = playersp->position;;
327
369
    Add(player);
328
370
    Add(player->dark);
329
371
 
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
 
 
 
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
      }
340
382
  }
341
383
 
342
384
  void DarkScene::Update()
367
409
            
368
410
            if (isPaused) {
369
411
              player->dark->isVisible = false;
 
412
              ShowSpawners();
370
413
              levelEditor->Enable();
371
414
            } else {
 
415
              HideSpawners();
372
416
              levelEditor->Disable();
373
417
              player->dark->isVisible = true;
374
418
            }