/minild29

To get this branch, use:
bzr branch /bzr/minild29
1 by Josh C
initial commit
1
#include "Dark.h"
15 by Josh C
make maxspeed work. footstep volume has to do with speed. skitter
2
#include <cmath>
1 by Josh C
initial commit
3
4
namespace Dark
5
{
6
  Player::Player() : Entity(),
15 by Josh C
make maxspeed work. footstep volume has to do with speed. skitter
7
		     FRICTION(150),
8
		     MAXSPEED(150.0f),
9
		     ACCELERATION(300)
1 by Josh C
initial commit
10
  {
11
    sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
12
    sprite->Add("idle", 0, 0, 0.35f);
13
    sprite->Play("idle");
14
    SetGraphic(sprite);
9 by Josh C
creatures move less, make everything smaller
15
    scale = Vector2(0.25, 0.25);
1 by Josh C
initial commit
16
17
    AddTag("player");
7 by Josh C
footsteps
18
19
    footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
20
    footsteps->SetLoops(0); //loop indefinitely
15 by Josh C
make maxspeed work. footstep volume has to do with speed. skitter
21
    footsteps->SetVolume(0);
22
    footsteps->Play();
1 by Josh C
initial commit
23
    
9 by Josh C
creatures move less, make everything smaller
24
    SetCollider(new RectangleCollider(16, 16));
10 by Josh C
"light" in the dark
25
26
    dark = new Entity();
27
    dark->SetGraphic(new Sprite("dark.png", FILTER_NONE, 2048, 1536)); //alpha?
1 by Josh C
initial commit
28
  }
29
30
  void Player::Update()
31
  {
32
    Entity::Update();
33
3 by Josh C
square moving around the screen
34
    if (Input::IsKeyMaskHeld("left"))
35
      {
36
	velocity.x -= ACCELERATION * Monocle::deltaTime;
37
      }
38
    if (Input::IsKeyMaskHeld("right"))
39
      {
40
	velocity.x += ACCELERATION * Monocle::deltaTime;
41
      }
42
    if (Input::IsKeyMaskHeld("up"))
43
      {
44
	velocity.y -= ACCELERATION * Monocle::deltaTime;
45
      }
46
    if (Input::IsKeyMaskHeld("down"))
47
      {
48
	velocity.y += ACCELERATION * Monocle::deltaTime;
49
      }
50
    
51
    // velocity will approach 0 in steps of FRICTION * dt
52
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
53
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
54
15 by Josh C
make maxspeed work. footstep volume has to do with speed. skitter
55
    if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
56
      velocity = velocity.GetNormalized() * MAXSPEED;
57
4 by Josh C
invisible walls and code to bump into them
58
    bool xcol = false;
59
    bool ycol = false;
60
33 by Josh C
win!
61
    if (Collide("exit")) {
62
      Scene *s = GetScene();
63
      s->isPaused = true;
64
      
65
      Text *win1 = new Text("You made it safely through the dark!", 
66
			   Assets::RequestFont("LiberationSans-Regular.ttf", 50.0f));
67
      win1->position = Vector2(-350,0);
68
      s->Add(win1);
69
70
      Text *win2 = new Text("Congratulations!", 
71
			   Assets::RequestFont("LiberationSans-Regular.ttf", 50.0f));
72
      win2->position = Vector2(-150,50);
73
      s->Add(win2);
74
    }
75
32 by Josh C
chompy noise, make collisions with hunters work a little better
76
    Collider *collider = NULL;
77
4 by Josh C
invisible walls and code to bump into them
78
    position.x += velocity.x * Monocle::deltaTime;
32 by Josh C
chompy noise, make collisions with hunters work a little better
79
    while (Collide("Solid") || (collider = Collide("creature")))
4 by Josh C
invisible walls and code to bump into them
80
      {
32 by Josh C
chompy noise, make collisions with hunters work a little better
81
	// Don't colide with hunters.  We should just die.
82
	if (collider) {
83
	  Creature *c = (Creature *) collider->GetEntity();
84
	  if (c->state == "hunt") { break; }
85
	}
86
4 by Josh C
invisible walls and code to bump into them
87
	xcol = true;
88
	if (velocity.x == 0) { break; }
89
	//printf("collision1\n");
90
	position.x -= SIGN(velocity.x, 0.1);
91
      }
92
    if (xcol) {velocity.x = 0;}
93
32 by Josh C
chompy noise, make collisions with hunters work a little better
94
    collider = NULL;
4 by Josh C
invisible walls and code to bump into them
95
    position.y += velocity.y * Monocle::deltaTime;
32 by Josh C
chompy noise, make collisions with hunters work a little better
96
    while (Collide("Solid") || (collider = Collide("creature")))
4 by Josh C
invisible walls and code to bump into them
97
      {
32 by Josh C
chompy noise, make collisions with hunters work a little better
98
	// Don't colide with hunters.  We should just die.
99
	if (collider) {
100
	  Creature *c = (Creature *) collider->GetEntity();
101
	  if (c->state == "hunt") { break; }
102
	}
103
4 by Josh C
invisible walls and code to bump into them
104
	ycol = true;
105
	if (velocity.y == 0) { break; }
106
	//printf("collision2\n");
107
	position.y -= SIGN(velocity.y, 0.1);
108
      }
109
    if (ycol) {velocity.y = 0;}
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
110
    
111
    float magnitude = velocity.GetMagnitude();
112
113
    footsteps->SetVolume(magnitude / MAXSPEED);
114
115
    // How far away can they hear your footsteps?
116
    // The circle is diameter 300 at MAXSPEED, 32 (2x your size) at 0 speed
27 by Josh C
they hear you more + fixed a bug if they're right on top of you
117
    noisiness = ((magnitude / MAXSPEED *(400-64)) + 64) /2;
3 by Josh C
square moving around the screen
118
10 by Josh C
"light" in the dark
119
    dark->position = position;
120
1 by Josh C
initial commit
121
    //Scene::GetCamera()->position = position;
122
  }
123
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
124
  Creature::Creature() : Entity(),
6 by Josh C
skittering blue square
125
			 FRICTION(800),
19 by Josh C
beginnings of "stalk" state
126
			 ACCELERATION(1200),
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
127
			 DEFAULT_MAXSPEED(80.0f),
128
			 STALKSPEED(20.0f)
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
129
  {
130
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
131
    sprite->Add("idle", 0, 0, 0.35f);
8 by Josh C
harder to see creatures
132
    sprite->Add("move", 1, 2, 4.0f);
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
133
    sprite->Add("slowmove", 1, 2, 2.0f);
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
134
    sprite->Play("idle");
135
    SetGraphic(sprite);
9 by Josh C
creatures move less, make everything smaller
136
    scale = Vector2(0.25, 0.25);
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
137
138
    AddTag("creature");
9 by Josh C
creatures move less, make everything smaller
139
    SetCollider(new RectangleCollider(16, 16));
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
140
26 by Josh C
now they chase you (hunt)
141
    alert = Assets::RequestAudio("alert.ogg");
142
    freakout = Assets::RequestAudio("freakout.ogg");
32 by Josh C
chompy noise, make collisions with hunters work a little better
143
    chomp = Assets::RequestAudio("chomp.ogg");
6 by Josh C
skittering blue square
144
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
145
    skitter1->SetLoops(0); //loop indefinitely
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
146
    sniff = Audio::NewDeck(Assets::RequestAudio("sniff.ogg"));
147
    sniff->SetLoops(0);
17 by Josh C
alert noise
148
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
149
    maxspeed = DEFAULT_MAXSPEED;
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
150
151
    //set aiTime to random so creatures tick at different times
6 by Josh C
skittering blue square
152
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
17 by Josh C
alert noise
153
154
    state = "idle";
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
155
  }
156
157
  void Creature::Update()
158
  {
159
    Entity::Update();
160
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
161
    if (state == "idle" || state == "wander") 
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
162
      {
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
163
	aiTime += Monocle::deltaTime;
164
	if (aiTime > 1.0f)
165
	  {
166
	    switch (rand() % 3)
167
	      {
168
	      case 0: // idle
169
		//printf("idle\n");
170
		direction = Vector2::zero;
171
		state = "idle";
172
		break;
173
	      case 1: // move
174
		if (state != "wander") {
175
		  //printf("wander\n");
176
		  direction = Vector2::Random();
177
		  state = "wander";
178
		  break;
179
		}
180
	      }
181
	    
182
	    aiTime = 0.0f;
183
	  }
184
	
185
	Player *player = ((DarkScene *)scene)->player;
186
	if ( (player->position - position).GetSquaredMagnitude() < 
187
	     pow(player->noisiness, 2) )
188
	  {
17 by Josh C
alert noise
189
	    //printf("alert\n");
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
190
	    state = "alert";
17 by Josh C
alert noise
191
	    alert->Play();
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
192
	    direction = Vector2::zero;
18 by Josh C
ping!
193
	    Ping::NewPing(position, 8.0f, 32.0f, 0.15f); // ping diameter 16-64 over .5s
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
194
	    aiTime = 0.0f; // diff variable?  stateTime?
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
195
	  }
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
196
      } // if idle or wander
197
    else if (state == "alert")
198
      {
199
	aiTime += Monocle::deltaTime;
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
200
	
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
201
	// if we've been listening past the grace period and hear
202
	// something, switch state again
19 by Josh C
beginnings of "stalk" state
203
	// We hear the player at DOUBLE noisiness distance, cuz WE'RE LISNING!
204
	Player *player = ((DarkScene *)scene)->player;
205
	if ( aiTime > 1.0f && 
206
	     (player->position - position).GetSquaredMagnitude() < 
207
	     pow(player->noisiness * 2, 2) )
208
	  {
209
	    state = "stalk";
210
	    Ping::NewPing(position, 8.0f, 32.0f, 0.15f);
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
211
	    direction = (player->position - position).GetNormalized();
212
	    maxspeed = STALKSPEED;
19 by Josh C
beginnings of "stalk" state
213
	    aiTime = 0.0f;
214
	  }
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
215
216
	// if we've been listening a long time, switch back to idle
17 by Josh C
alert noise
217
	if (aiTime > 5.0f) {
218
	  //printf("end alert\n");
219
	  state = "idle";
19 by Josh C
beginnings of "stalk" state
220
	  aiTime = 0.0f;
17 by Josh C
alert noise
221
	}
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
222
      }
19 by Josh C
beginnings of "stalk" state
223
    else if (state == "stalk")
224
      {
225
	aiTime += Monocle::deltaTime;
20 by Josh C
some more stalk logic
226
227
	// Go to HUNT if:
228
	// * it's been >1s & we hear the player
229
	// * we collide with the player
230
	Player *player = ((DarkScene *)scene)->player;
231
	if ((aiTime > 1.0f &&  
232
	     (player->position - position).GetSquaredMagnitude() < 
233
	     pow(player->noisiness, 2) )
234
	    || Collide("player")
235
	    )
236
	  {
26 by Josh C
now they chase you (hunt)
237
	    state = "hunt";
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
238
	    direction = (player->position - position).GetNormalized();
26 by Josh C
now they chase you (hunt)
239
	    maxspeed = 0; // give them a running start
240
	    sniff->Stop();
241
	    freakout->Play();
28 by Josh C
big yellow ping
242
	    Ping::NewPing(position, 8.0f, 64.0f, 0.15f); 
26 by Josh C
now they chase you (hunt)
243
	    aiTime = 0.0f;
244
	    noiseTime = 0.0f;
24 by Josh C
continue to work on stalk.
245
	  }
20 by Josh C
some more stalk logic
246
24 by Josh C
continue to work on stalk.
247
	// Go back to IDLE if:
248
	// * we hit a wall
26 by Josh C
now they chase you (hunt)
249
	// * we stalk for more than 10-15s
31 by Josh C
harder maze, safe zone, they kill you
250
	if ((aiTime > 15.0f) || Collide("wall") || Collide("creaturewall"))
24 by Josh C
continue to work on stalk.
251
	  {
252
	    // play frustrated noise?
253
	    state = "idle";
254
	    aiTime = 0.0f;
255
	    sniff->Stop();
256
	    maxspeed = DEFAULT_MAXSPEED;
257
	    direction = Vector2::zero;
20 by Josh C
some more stalk logic
258
	  }
19 by Josh C
beginnings of "stalk" state
259
      }
26 by Josh C
now they chase you (hunt)
260
    else if (state == "hunt")
261
      {
262
	aiTime += Monocle::deltaTime;
263
	noiseTime += Monocle::deltaTime;
27 by Josh C
they hear you more + fixed a bug if they're right on top of you
264
	graceTime += Monocle::deltaTime;
26 by Josh C
now they chase you (hunt)
265
27 by Josh C
they hear you more + fixed a bug if they're right on top of you
266
	if ((graceTime > 1.0f) && (maxspeed != DEFAULT_MAXSPEED))
26 by Josh C
now they chase you (hunt)
267
	  maxspeed = DEFAULT_MAXSPEED;
268
269
	// if we hear the player (
270
	Player *player = ((DarkScene *)scene)->player;
271
	if ( (player->position - position).GetSquaredMagnitude() < 
272
	     pow(player->noisiness, 2) )
273
	  {
274
	    direction = (player->position - position).GetNormalized();
275
	    aiTime = 0.0f;
27 by Josh C
they hear you more + fixed a bug if they're right on top of you
276
	    if (noiseTime > 2.0f) {
26 by Josh C
now they chase you (hunt)
277
	      freakout->Play();
28 by Josh C
big yellow ping
278
	      Ping::NewPing(position, 8.0f, 64.0f, 0.15f);
26 by Josh C
now they chase you (hunt)
279
	      noiseTime = 0.0f;
280
	    }
281
	  }
282
283
	// I guess chill out if it's been a while
284
	if (aiTime > 15.0f) {
285
	    state = "alert";
286
	    //alert->Play();
287
	    direction = Vector2::zero;
288
	    aiTime = 0.0f;
27 by Josh C
they hear you more + fixed a bug if they're right on top of you
289
	    noiseTime = 0.0f;
290
	    graceTime = 0.0f;
26 by Josh C
now they chase you (hunt)
291
	}
292
31 by Josh C
harder maze, safe zone, they kill you
293
	// if we collide with you, move you back to the starting point
294
	if (Collide("player")) {
32 by Josh C
chompy noise, make collisions with hunters work a little better
295
	  // TODO: first wait a second or 3?
296
	  chomp->Play();
31 by Josh C
harder maze, safe zone, they kill you
297
	  DarkScene *scene = (DarkScene *) GetScene();
298
	  Entity* playersp = scene->GetFirstEntityWithTag("playerspawner");
299
	  scene->player->position = playersp->position;
300
	}
26 by Josh C
now they chase you (hunt)
301
      }
16 by Josh C
track palyer noisiness, beginnings of "alert" state for creatures
302
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
303
    velocity += direction * ACCELERATION * Monocle::deltaTime;
304
    
305
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
306
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
307
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
308
    if (velocity.GetSquaredMagnitude() > pow(maxspeed, 2))
309
      velocity = velocity.GetNormalized() * maxspeed;
15 by Josh C
make maxspeed work. footstep volume has to do with speed. skitter
310
6 by Josh C
skittering blue square
311
    bool xcol = false;
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
312
    bool ycol = false;
313
314
    position.x += velocity.x * Monocle::deltaTime;
31 by Josh C
harder maze, safe zone, they kill you
315
    while (Collide("Solid") || Collide("creaturewall"))
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
316
      {
317
	xcol = true;
318
	if (velocity.x == 0) { break; }
319
	//printf("collision1\n");
320
	position.x -= SIGN(velocity.x, 0.1);
321
      }
322
    if (xcol) {velocity.x = 0;}
323
324
    position.y += velocity.y * Monocle::deltaTime;
31 by Josh C
harder maze, safe zone, they kill you
325
    while (Collide("Solid") || Collide("creaturewall"))
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
326
      {
327
	ycol = true;
328
	if (velocity.y == 0) { break; }
329
	//printf("collision2\n");
330
	position.y -= SIGN(velocity.y, 0.1);
331
      }
332
    if (ycol) {velocity.y = 0;}
6 by Josh C
skittering blue square
333
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
334
    Vector2 distance = ((DarkScene *)scene)->player->position - position;
335
    if (state == "stalk")
336
      {
24 by Josh C
continue to work on stalk.
337
	float vol = (distance.GetMagnitude() / -250.0f) + 1.0f;
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
338
	sniff->SetVolume(vol);
339
	sniff->Play();
340
	sprite->Play("slowmove");
341
      }
342
    else if (velocity.GetSquaredMagnitude() > 20)
343
      {
15 by Josh C
make maxspeed work. footstep volume has to do with speed. skitter
344
	// at distance 0, vol should be 1.0.  at 800, it should be 0.
22 by Josh C
stalker moves slow and sniffs (and doesn't scuttle)
345
	float vol = (distance.GetMagnitude() / -600.0f) + 1.0f;
15 by Josh C
make maxspeed work. footstep volume has to do with speed. skitter
346
	skitter1->SetVolume(vol);
8 by Josh C
harder to see creatures
347
	skitter1->Play();
348
	sprite->Play("move");
349
      }
6 by Josh C
skittering blue square
350
    else
8 by Josh C
harder to see creatures
351
      {
352
	skitter1->Pause(); //Stop()?
353
	sprite->Play("idle");
354
      }
5 by Josh C
added a "creature" moving around w/ the same dynamics as you do
355
  }
356
18 by Josh C
ping!
357
  Ping::Ping() : Entity(),
358
		 d1(0.0f), d2(0.0f), t(0.0f), t2(0.0f)
359
  {
360
    sprite = new Sprite("yellow.png", FILTER_LINEAR, 64, 64);
361
    SetGraphic(sprite);
362
    scale = Vector2::zero;
363
  }
364
365
  Ping *Ping::NewPing(Vector2 pos, float d1, float d2, float t2)
366
  {
367
    Ping *ping = new Ping();
368
    ping->d1 = d1;
369
    ping->d2 = d2;
370
    ping->t2 = t2;
371
    ping->position = pos;
372
373
    Game::GetScene()->Add(ping);
374
    return ping;
375
  }
376
377
  void Ping::Update()
378
  {
379
    Entity::Update();
380
381
    // once we're done LERPing, get gone
382
    if (t > t2)
383
      RemoveSelf();
384
385
    t += Monocle::deltaTime;
386
    float scaleFactor = LERP(d1/64, d2/64, t/t2);
387
    scale = Vector2(scaleFactor, scaleFactor);
388
  }
389
1 by Josh C
initial commit
390
  // Scene
391
392
  DarkScene::DarkScene() : Scene()
393
  {
394
  }
395
  
396
  void DarkScene::Begin()
397
  {
398
    Scene::Begin();
399
400
    Graphics::Set2D(1024, 768);
401
33 by Josh C
win!
402
    Text *inst1 = new Text("Use arrow keys to move");
403
    inst1->position = Vector2(-492, -354);
404
    Add(inst1);
405
1 by Josh C
initial commit
406
    Text *inst2 = new Text("Press ESC to quit");
33 by Josh C
win!
407
    inst2->position = Vector2(-492, -334); // 20px h, 30px v from U-L corner
1 by Josh C
initial commit
408
    Add(inst2);
409
410
    Input::DefineMaskKey("left", KEY_LEFT);
411
    Input::DefineMaskKey("right", KEY_RIGHT);
412
    Input::DefineMaskKey("up", KEY_UP);
413
    Input::DefineMaskKey("down", KEY_DOWN);
414
415
    Input::DefineMaskKey("up", KEY_W);
416
    Input::DefineMaskKey("left", KEY_A);
417
    Input::DefineMaskKey("down", KEY_S);
418
    Input::DefineMaskKey("right", KEY_D);
419
420
    // level editor
421
    Add( levelEditor = new LevelEditor() );
422
    levelEditor->Disable();
423
424
    // load level from files
425
    Level::LoadProject("project.xml");
426
    Level::Load("level.xml", this);
4 by Josh C
invisible walls and code to bump into them
427
21 by Josh C
player and creature spawners in level editor
428
    HideSpawners();
429
    Spawn();
430
13 by Josh C
visible walls
431
    std::list<Entity*> *walls = GetAllTag("wall");
432
    for (std::list<Entity*>::iterator i = walls->begin(); i != walls->end(); ++i)
4 by Josh C
invisible walls and code to bump into them
433
      {
434
        Entity *e = (*i);
435
        Vector2 s = e->scale;
436
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
437
      }
31 by Josh C
harder maze, safe zone, they kill you
438
439
    std::list<Entity*> *creaturewalls = GetAllTag("creaturewall");
440
    for (std::list<Entity*>::iterator i = creaturewalls->begin(); i != creaturewalls->end(); ++i)
441
      {
442
        Entity *e = (*i);
443
        Vector2 s = e->scale;
444
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
445
      }
33 by Josh C
win!
446
447
    Entity* exit = GetFirstEntityWithTag("exit");
448
    Vector2 s = exit->scale;
449
    exit->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
450
 
1 by Josh C
initial commit
451
   
21 by Josh C
player and creature spawners in level editor
452
    Graphics::SetBackgroundColor(Color::green * 0.2f);
453
454
  }
455
456
  void DarkScene::HideSpawners()
457
  {
458
    std::list<Entity*> *spawners = GetAllTag("spawner");
459
    if (spawners == NULL) {printf("NO SPAWNERS!!!\n");}
460
    for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
461
      (*i)->isVisible = false;
462
  }
463
464
  void DarkScene::ShowSpawners()
465
  {
466
    std::list<Entity*> *spawners = GetAllTag("spawner");
467
    for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
468
      (*i)->isVisible = true;
469
  }
470
  
471
  void DarkScene::Spawn()
472
  {
473
    Entity* playersp = GetFirstEntityWithTag("playerspawner");
11 by Josh C
disappear darkness mask in editor mode
474
    player = new Player();
21 by Josh C
player and creature spawners in level editor
475
    player->position = playersp->position;;
1 by Josh C
initial commit
476
    Add(player);
10 by Josh C
"light" in the dark
477
    Add(player->dark);
1 by Josh C
initial commit
478
21 by Josh C
player and creature spawners in level editor
479
    std::list<Entity*> *spawners = GetAllTag("creaturespawner");
480
    // Ugh, monocle is double-entering all the tags...
481
    spawners->sort();
482
    spawners->unique();
483
    for (std::list<Entity*>::iterator i = spawners->begin(); i != spawners->end(); ++i)
484
      {
485
	Creature *creature = new Creature();
486
	creature->position = (*i)->position;
487
	Add(creature);
488
      }
1 by Josh C
initial commit
489
  }
490
491
  void DarkScene::Update()
492
  {
493
    Scene::Update();
494
495
    if (Input::IsKeyPressed(KEY_ESCAPE))
496
      Game::Quit();
497
498
    if (isPaused)
499
      {
500
	if (Input::IsKeyPressed(KEY_S) && Input::IsKeyHeld(KEY_LCTRL))
501
	  Level::Save();
502
503
	if (Input::IsKeyPressed(KEY_A))
504
	  Scene::GetCamera()->position.x -= 600;
505
506
	if (Input::IsKeyPressed(KEY_D))
507
	  Scene::GetCamera()->position.x += 600;
508
      }
509
510
    if (Input::IsKeyPressed(KEY_TAB))
511
      {
512
        // if we're not doing anything in the levelEditor...
513
        if (levelEditor->GetState() == FTES_NONE)
514
          {
515
            isPaused = !isPaused;
516
            
11 by Josh C
disappear darkness mask in editor mode
517
            if (isPaused) {
12 by Josh C
drastically less hacky way to hide the darkness
518
	      player->dark->isVisible = false;
21 by Josh C
player and creature spawners in level editor
519
	      ShowSpawners();
1 by Josh C
initial commit
520
	      levelEditor->Enable();
11 by Josh C
disappear darkness mask in editor mode
521
	    } else {
21 by Josh C
player and creature spawners in level editor
522
	      HideSpawners();
1 by Josh C
initial commit
523
	      levelEditor->Disable();
12 by Josh C
drastically less hacky way to hide the darkness
524
	      player->dark->isVisible = true;
11 by Josh C
disappear darkness mask in editor mode
525
	    }
1 by Josh C
initial commit
526
          }
527
      }
528
529
  }// DarkScene::Update
530
531
  Text::Text(const std::string& text, FontAsset* font)
532
    : Entity(), text(text)
533
  {
534
    if (font == NULL)
535
      this->font = Assets::RequestFont("LiberationSans-Regular.ttf", 18.0f);
536
    else
537
      this->font = font;
11 by Josh C
disappear darkness mask in editor mode
538
539
    SetLayer(-2);
1 by Josh C
initial commit
540
  }
541
542
  void Text::Render()
543
  {
544
    Graphics::PushMatrix();
545
546
    // place text directly relative to camera
547
    Graphics::Translate(scene->GetCamera()->position + position);
548
549
    Graphics::SetBlend(BLEND_ALPHA);
550
    Graphics::SetColor(Color::white);
551
    Graphics::BindFont(font);
552
    
553
    Graphics::RenderText(*font, text, 0, 0);
554
    Graphics::PopMatrix();
555
  }
556
557
}