/minild29

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