Add Saiki & Carlos afternoon dialogue
[wgj58.git] / wgj58.js
1 var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: function() { this.state.add('GamePlay', GamePlay, true); } });
2 var logic;
3 var cursors;
4
5 const PLAYER_SPEED = 200;
6 const WAIT_MENUSTEP = 100;
7 const WAIT_TALK = 250;
8
9 const MENUITEM_TALK = 0;
10 const MENUITEM_LEAVE = 1;
11 const MENUITEM_TAKE = 2;
12
13 const GUI_MENUITEM_DISTANCE = 20;
14
15 window.addEventListener("keydown", function(e) {
16 // Prevent default browser action for arrows and spacebar
17 if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
18 e.preventDefault();
19 }
20 }, false);
21
22 function hasTimePassed(time, delay) {
23 return (game.time.now - time) > delay;
24 }
25
26 class Dialogue {
27 // dialogue is array of {actor, text} records.
28 constructor(dialogue) {
29 this.dialogue = dialogue;
30 this.state = 0;
31 }
32
33 actual() {
34 return this.dialogue[this.state];
35 }
36
37 advance() {
38 this.state++;
39 }
40 }
41
42 class Door extends Phaser.TileSprite {
43 constructor(x, y, name, rotation, vector, longpanel) {
44 super(game, x, y, 64, 64, 'objects');
45 this.name = name;
46 this.longpanel = longpanel;
47 if (!longpanel) {
48 this.anchor = new Phaser.Point(0.5, 0.5);
49 this.tilePosition = new Phaser.Point(-64, -64);
50 this.openvector = Phaser.Point.multiply(vector, new Phaser.Point(56, 56));
51 }
52 else {
53 this.width *= 2;
54 this.anchor = new Phaser.Point(0.75, 0.5);
55 this.tilePosition = new Phaser.Point(0, -64);
56 this.openvector = Phaser.Point.multiply(vector, new Phaser.Point(116, 116));
57 }
58 if (rotation === undefined) rotation = 0;
59 this.rotation = rotation * (Math.PI / 180);
60 this.closetween = game.add.tween(this).to({ x: this.position.x, y: this.position.y }, 1000, Phaser.Easing.Sinusoidal.InOut, false, 0, 0, false);
61 this.openposition = Phaser.Point.add(this.position, this.openvector);
62 this.opentween = game.add.tween(this).to({ x: this.openposition.x, y: this.openposition.y }, 1000, Phaser.Easing.Sinusoidal.InOut, false, 0, 0, false);
63 this.isOpen = false;
64 game.physics.arcade.enable(this);
65 this.body.immovable = true;
66 this.setBody(rotation);
67 }
68
69 setBody(rotation) {
70 switch(rotation) {
71 case 0:
72 case 180:
73 this.body.setSize(this.width, 10, this.longpanel * (rotation / 180) * 64, 27);
74 break;
75 case 90:
76 case 270:
77 this.body.setSize(10, this.width, 27 + (this.longpanel * 64), this.longpanel * ((rotation - 270) / 180) * 64);
78 break;
79 default:
80 console.log("Unable to set body due to unknown rotation:", rotation);
81 }
82 }
83
84 open() {
85 if (!this.isOpen) {
86 this.opentween.start();
87 this.isOpen = true;
88 }
89 }
90
91 close() {
92 if (this.isOpen) {
93 this.closetween.start();
94 this.isOpen = false;
95 }
96 }
97
98 update() {
99 game.debug.body(this);
100 }
101 }
102
103 class Player extends Phaser.Sprite {
104 constructor(x, y) {
105 super(game, x, y, 'player');
106 this.y -= this.height;
107 this.shortname = "John";
108 this.fullname = "John Evals";
109 this.offerInteraction(null);
110 this.unfreeze();
111 }
112
113 enablePhysics() {
114 game.physics.arcade.enable(this);
115 this.body.bounce.y = 0.2;
116 this.body.bounce.x = 0.2;
117 this.body.collideWorldBounds = true;
118 }
119
120 control() {
121 if ((this.alive) && (!this.freezed))
122 {
123 if (cursors.left.isDown)
124 {
125 this.body.velocity.x = -PLAYER_SPEED;
126 }
127 else if (cursors.right.isDown)
128 {
129 this.body.velocity.x = PLAYER_SPEED;
130 }
131 if (cursors.up.isDown)
132 {
133 this.body.velocity.y = -PLAYER_SPEED;
134 }
135 else if (cursors.down.isDown)
136 {
137 this.body.velocity.y = PLAYER_SPEED;
138 }
139 }
140 }
141
142 update() {
143 this.body.velocity.x = this.body.velocity.y = 0;
144 this.control();
145 }
146
147 freeze() {
148 this.freezed = true;
149 }
150
151 unfreeze() {
152 this.freezed = false;
153 }
154
155 offerInteraction(npc) {
156 this.interactablenpc = npc;
157 }
158
159 takeMe(npc) {
160 this.loadTexture(npc.key);
161 npc.kill();
162 this.disguise = npc;
163 logic.gameinterface.dropNoticeTimeout(Phaser.Timer.SECOND * 5, "You are now identified as " + npc.fullname + "!");
164 }
165 }
166
167 class GameNPC extends Phaser.Sprite {
168 constructor(x, y, key, shortname, fullname, interaction_distance) {
169 super(game, x, y, key);
170 this.y -= this.height;
171 this.shortname = shortname;
172 this.fullname = fullname;
173 this.interaction_distance = interaction_distance;
174 this.interactable = false;
175 this.resetTalk();
176 this.happy = false;
177 }
178
179 kill() {
180 super.kill();
181 this.exists = false;
182 this.happy = false; // Dead people are not happy.
183 }
184
185 update() {
186 super.update();
187 if ((!this.interactable) && (game.physics.arcade.distanceBetween(this, logic.player) < this.interaction_distance)) {
188 logic.gameinterface.dropNotice("(ENTER) Interact with " + this.shortname + "!");
189 logic.player.offerInteraction(this);
190 this.interactable = true;
191 }
192 else if ((this.interactable) && (game.physics.arcade.distanceBetween(this, logic.player) > this.interaction_distance)) {
193 logic.gameinterface.clearNotice();
194 logic.player.offerInteraction(null);
195 this.interactable = false;
196 }
197 if ((this.teleport_instructions) && (game.physics.arcade.distanceBetween(this, logic.player) > (game.width + 200))) {
198 this.position = this.teleport_instructions.newPosition;
199 this.teleport_instructions.callback(this.teleport_instructions.callbackValue);
200 this.teleport_instructions = null;
201 }
202 }
203
204 actionTalk() {
205 this.talkcount++;
206 }
207
208 actionLeave() {
209 }
210
211 actionTake() {
212 logic.player.offerInteraction(null);
213 logic.player.takeMe(this);
214 return true;
215 }
216
217 endTalk() {
218 return true;
219 }
220
221 resetTalk() {
222 this.talkcount = 0;
223 }
224
225 makeHappy() {
226 this.happy = true;
227 console.log(this.shortname, "is happy!");
228 }
229
230 offscreenTeleportation(newPosition, callback, callbackValue) {
231 this.teleport_instructions = { newPosition: newPosition, callback: callback, callbackValue: callbackValue };
232 console.log("Offscreen teleport request registered:", this.teleport_instructions);
233 }
234 }
235
236 class NPC_Clara extends GameNPC {
237 actionTalk() {
238 switch (this.talkcount) {
239 case 0:
240 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "What a morning..." },
241 { actor: logic.player, text: "Hi Clara! What happened?" },
242 { actor: this, text: "No one cares to tell. I just know that I have to log on people manually, as the access control system doesn't work properly." },
243 { actor: logic.player, text: "Hmm... I'll look into it. Maybe it's just that everyone is fired." },
244 { actor: this, text: "Haha! Wouldn't joke about this, though, due to the recent layoffs." },
245 { actor: logic.player, text: "Well, maybe if we dare to joke about it, it won't happen to us..." },
246 { actor: this, text: "Wish it worked like that... Is it some superstition like the belief that having an umbrella with you prevents rain?" },
247 { actor: logic.player, text: "Nah, that actually works; it's not a superstition, but Murphy's Law!" },
248 { actor: this, text: "If you say so..." },
249 { actor: this, text: "Anyway, I logged you in and opened the door for you." } ] ));
250 logic.openDoor("cutedoor");
251 break;
252 case 1:
253 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "John, have you ever thought about losing your employee card?" },
254 { actor: logic.player, text: "Yeah, you'd just get a new one." },
255 { actor: this, text: "You don't understand me, John!" },
256 { actor: this, text: "..." },
257 { actor: this, text: "I mean... Losing it for real..." },
258 { actor: this, text: "Doesn't it feel like it's the culmination of your being?" },
259 { actor: this, text: "If I had no card, would I still exist?" },
260 { actor: logic.player, text: "..." },
261 { actor: logic.player, text: "You sound very philosophical today." } ] ));
262 break;
263 case 2:
264 case 3:
265 case 4:
266 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Would you like to hear a random fun fact?" },
267 { actor: logic.player, text: "Of course!" },
268 { actor: this, text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s," },
269 { actor: this, text: "when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap" },
270 { actor: this, text: "into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem" },
271 { actor: this, text: "Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." },
272 { actor: logic.player, text: "That's very interesting, I didn't know that!" },
273 { actor: logic.player, text: "Thanks for sharing, Clara!" } ] ));
274 break;
275 case 5:
276 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Would you like to hear a random fun fact?" },
277 { actor: logic.player, text: "Of course!..." },
278 { actor: logic.player, text: "But first..." },
279 { actor: this, text: "What is it?" },
280 { actor: logic.player, text: "..." },
281 { actor: logic.player, text: "Never mind, go on with what you wanted to say." },
282 { actor: this, text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry..." },
283 { actor: logic.player, text: "I knew that already..." },
284 { actor: logic.player, text: "But..." },
285 { actor: logic.player, text: "Would you go out on a date with me?" },
286 { actor: this, text: "..." },
287 { actor: this, text: "No." } ] ));
288 break;
289 default:
290 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "..." } ] ));
291 }
292 super.actionTalk();
293 }
294
295 actionLeave() {
296 logic.gameinterface.dropNotice(this.shortname + ": Have a great day, John!");
297 }
298
299 actionTake() {
300 logic.openDoor("cutedoor");
301 return super.actionTake();
302 }
303
304 endTalk() {
305 return (this.talkcount < 6);
306 }
307 }
308
309 class NPC_Carlos extends GameNPC {
310 actionTalk() {
311 if (logic.clara.alive) {
312 if (logic.saiki.talkcount == 0) {
313 switch (this.talkcount) {
314 case 0:
315 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Good morning, Carlos! What's up?" },
316 { actor: this, text: "Hey, John! Not too much, I'm just trying to sell some shit to this new client." },
317 { actor: logic.player, text: "And so? Is it hard to convince them?" },
318 { actor: this, text: "Of course, they don't want to buy. It's shit." },
319 { actor: this, text: "I mean, who would want to buy shit?" },
320 { actor: logic.player, text: "Yeah. Relatable... But why are you trying to sell shit? I mean, why not one of our cutting edge technologies?" },
321 { actor: this, text: "They couldn't afford it." },
322 { actor: logic.player, text: "Then why are you trying to sell them... anything at all? They'd better off with a cheaper company." },
323 { actor: this, text: "Company policies. Plus the management instructed me to sell to them, no matter what." },
324 { actor: logic.player, text: "That sucks... Well... good luck!" },
325 { actor: this, text: "Thanks..." } ] ));
326 logic.closeDoor("cutedoor");
327 logic.openDoor("carlosdoor");
328 break;
329 case 1:
330 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "*Sigh.* I'll probably not work here for long, if I can't sell this shit to the customer." },
331 { actor: this, text: "These layoffs are terrifying. They let go of anyone for even the slightest mistake." },
332 { actor: logic.player, text: "But it's not a mistake when our client doesn't buy something they don't need." },
333 { actor: this, text: "Tell this to my boss..." } ] ));
334 break;
335 case 2:
336 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "You know, generally, I think it sucks being a child. One thing I miss though, if you're a child, you're allowed to be silly." },
337 { actor: this, text: "..." },
338 { actor: this, text: "For example, when my Dad told me that semen is the seed of animals, I theoretized, if I'd bury some pig semen in the garden, a pig would grow out of it..." },
339 { actor: this, text: "I was totally fascinated by the thought, because I really wanted to have a pet pig, but Dad wouldn't let me have one." },
340 { actor: this, text: "So I thought I could grow my own pig in the garden from pig seeds!" },
341 { actor: logic.player, text: "Interesting. Where are you going with this?" },
342 { actor: this, text: "I don't know... sometimes I feel like I'd rather sell pig semen to our clients, heh!" },
343 { actor: this, text: "Uhm..." },
344 { actor: this, text: "Totally don't tell this to Saiki!" } ] ));
345 this.pigsemen = true;
346 break;
347 case 3:
348 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Weren't you heading to the IT department to the right?" },
349 { actor: this, text: "You know... the green department which looks way better than blue!" },
350 { actor: this, text: "..." },
351 { actor: this, text: "Damn, why do I have to work in blue? I just feel... so blue about it." } ] ));
352 break;
353 case 4:
354 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Weren't you heading to the conveniently green department to the right? I guess Saiki is waiting for you." },
355 { actor: this, text: "You're so lucky that you can work with her every day!" } ] ));
356 break;
357 default:
358 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Guess you'll stay here then. It's cool, you're great company anyway." } ] ));
359 }
360 }
361 else {
362 switch (this.talkcount) {
363 case 0:
364 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Phew... long shift, I gotta go!" },
365 { actor: this, text: "Why are you still here? I mean, you engineers stay here 'til late at night. Why don't you just go home at 4 pm?" },
366 { actor: this, text: "This is why I can never ask out Saiki... She always works for so long..." },
367 { actor: logic.player, text: "We tend to have lots of work with impossible deadlines..." },
368 { actor: this, text: "I bet you get lots of money for the overtimes!" },
369 { actor: logic.player, text: "No, we don't get paid for overtimes." },
370 { actor: this, text: "... Then why do you stay beyond the office hours?" },
371 { actor: logic.player, text: "Otherwise we're fired. That's the deal. Either we work 2 extra hours or we get replaced." },
372 { actor: this, text: "Wow... and I thought we have a shortage on engineers..." } ] ));
373 break;
374 case 1:
375 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "And how's the business going? Did you manage to shell the shit?" },
376 { actor: this, text: "In a heartbeat! Now they're buying so much shit that I'm afraid we don't have enough assholes to produce that quantity." },
377 { actor: this, text: "Be prepared for another month of overtimes. This deal will be huge!" },
378 { actor: logic.player, text: "Well done, man!" } ] ));
379 break;
380 default:
381 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "I really want to leave now." } ] ));
382 this.offscreenTeleportation(new Phaser.Point(0, 0), this.tpDone, this);
383 }
384 }
385 }
386 else {
387 switch (this.talkcount) {
388 case 0:
389 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Good morning, Carlos!" },
390 { actor: this, text: "Whoa, Clara! You have changed so much! I barely recognize you. What's up?" },
391 { actor: logic.player, text: "I need to talk to Saiki at the IT department, but... my card doesn't allow me to enter there." },
392 { actor: this, text: "Well... I can certainly help you with that..." },
393 { actor: this, text: "..." } ] ));
394 break;
395 case 1:
396 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Carlos. You promised to help me." },
397 { actor: this, text: "Uhm... It's just... Please give me 5 mins to finish this e-mail." },
398 { actor: logic.player, text: "I don't have much time, Carlos." },
399 { actor: this, text: "See, it's just 5 mins, please be patient. I have a chocolate bar in the fridge. I give it to you. Feel free to have it meanwhile." },
400 { actor: logic.player, text: "..." } ] ));
401 break;
402 case 2:
403 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Time is up, Carlos!" },
404 { actor: this, text: "Please give me just another min." },
405 { actor: logic.player, text: "Fine. Please just give me your card and I'll help myself!" },
406 { actor: this, text: "But... you know that company policies forbid that, Clara! Please just be a little more patient!" },
407 { actor: logic.player, text: "You will give me your card now or you will regret!" },
408 { actor: this, text: "...?" },
409 { actor: this, text: "You're not gonna treat me like this. Forget it!" },
410 { actor: logic.player, text: "You'll not work here tomorrow." } ] ));
411 break;
412 default:
413 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "..." } ] ));
414 }
415 }
416 super.actionTalk();
417 }
418
419 actionLeave() {
420 if ((logic.clara.alive) && (logic.saiki.talkcount == 0)) {
421 logic.gameinterface.dropNotice(this.shortname + ": Bye, John! Pass on my greetings to Saiki!");
422 }
423 }
424
425 actionTake() {
426 logic.closeDoor("cutedoor");
427 logic.openDoor("carlosdoor");
428 return super.actionTake();
429 }
430
431 endTalk() {
432 return ((logic.clara.alive) && (logic.saiki.talkcount == 0)) || (this.talkcount < 3);
433 }
434
435 tpDone(value) {
436 console.log("Woot-woot! Teleport complete:", value);
437 value.visible = false;
438 }
439 }
440
441 class NPC_Saiki extends GameNPC {
442 actionTalk() {
443 /* If Saiki is happy, she's already teleported to Carlos. */
444 if (!this.happy)
445 this.actionTalk_morning();
446 else
447 this.actionTalk_afternoon();
448 }
449
450 actionTalk_morning() {
451 if (logic.carlos.alive) {
452 switch (this.talkcount) {
453 case 0:
454 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Hi Saiki!" },
455 { actor: this, text: "Hi John! Glad you arrived, here's some work for you!" },
456 { actor: logic.player, text: "Awesome! What is it?" },
457 { actor: this, text: "Haha, joking! Actually, our queue is suspiciously empty for today." },
458 { actor: logic.player, text: "Yeah... That's really suspicious!" },
459 { actor: logic.player, text: "Maybe I can get home today in time?" },
460 { actor: this, text: "You mean, you wouldn't spend the mandatory free extra working hours?" },
461 { actor: this, text: "You steal from the company! The company needs your unpaid hours of work! Otherwise, how would we finance the trash can I ordered for the department?" },
462 { actor: this, text: "*Whispers with wink.* I hope you get my sarcasm." },
463 { actor: logic.player, text: "Haha! I always get it, Saiki!" } ] ));
464 logic.closeDoor("carlosdoor");
465 logic.openDoor("saikidoor");
466 logic.openDoor("peterdoor");
467 logic.carlos.resetTalk();
468 break;
469 case 1:
470 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Now that I think about it, there's still one thing. You could look into why the access control system is acting so funny today." },
471 { actor: this, text: "Clara has to enter people manually." },
472 { actor: logic.player, text: "Yeah, I'll definitely check that." } ] ));
473 break;
474 case 2:
475 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "So... what's up with the trash can?" },
476 { actor: this, text: "I'm always up for such deep conversation" },
477 { actor: this, text: "about trash cans." },
478 { actor: this, text: "While we only have one trash can, other departments seem to be abundant of them. And ours is always filled. So I requested an additional trash can." },
479 { actor: this, text: "Now the ticket is in PENDING status. The latest work note is from two months ago, telling there is no budget at the moment." },
480 { actor: logic.player, text: "Hmm... Maybe it's too much to ask. Can we take one from another department?" },
481 { actor: this, text: "No, everyone holds on to their trash cans." },
482 { actor: logic.player, text: "You certainly did your research." },
483 { actor: this, text: "Of course. It's an important subject." } ] ));
484 break;
485 case 3:
486 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "My parents named me after a Japanese rock singer." },
487 { actor: logic.player, text: "Cool! Which band?" },
488 { actor: this, text: "I don't remember the band name. But the particular singer has a blue rose in her hair most of the time." } ] ));
489 break;
490 default:
491 if ((logic.carlos.pigsemen) && (this.talkcount == 4)) {
492 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Did you know that Carlos thought he can grow a pig by burying pig semen in the ground? What do you think about this?" },
493 { actor: this, text: "Hmm..." },
494 { actor: this, text: "I guess it didn't work." },
495 { actor: this, text: "So do you want to know what I think about this?" },
496 { actor: this, text: "..." },
497 { actor: this, text: "IT'S BRILLIANT!!!" },
498 { actor: this, text: "You know, it really sparkled my artistic vision! Now I must draw a pig with its legs rooted into the ground!" },
499 { actor: logic.player, text: "That's gross. Poor pig." },
500 { actor: this, text: "Indeed. But this is the point. He's stuck in one place, cannot move. Like you in life. So you feel sympathy for him." },
501 { actor: logic.player, text: "You have a point." },
502 { actor: this, text: "I think I'll catch Carlos and talk to him. I always liked that guy but I didn't know he's such imaginative." } ] ));
503 this.offscreenTeleportation(new Phaser.Point(logic.carlos.x, logic.carlos.y + 64), this.tpDone, this);
504 }
505 else {
506 if (Phaser.Math.random() < 0.5) {
507 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "I've found an orchestrated rendition of „Potential for Anything”. You'll have to check it out, it's breathtaking!" } ] ));
508 }
509 else {
510 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "I don't like that our department is green. The blue one, where Carlos works, looks much better." } ] ));
511 }
512 }
513 }
514 }
515 else {
516 switch (this.talkcount) {
517 case 0:
518 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "I love you, Saiki!" },
519 { actor: this, text: "Hi Carlos..." },
520 { actor: logic.player, text: "I'm infatuated by the mere thought of you." },
521 { actor: this, text: "Well... it sounds pretty much creepy." },
522 { actor: logic.player, text: "Will you go out on a date with me?" },
523 { actor: this, text: "..." },
524 { actor: this, text: "Sorry to hurt your feelings, but... even though I like you... Your sudden, unprecedented confession makes me scared." },
525 { actor: this, text: "Especially with that facial expression." },
526 { actor: this, text: "I mean... you're not even joking." },
527 { actor: this, text: "So sorry... I won't date you." } ] ));
528 break;
529 case 1:
530 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "I thought I could impress you." },
531 { actor: this, text: "I'm sorry." } ] ));
532 break;
533 case 2:
534 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "You will give me your card." },
535 { actor: this, text: "Geez, what for? Go back to your department and work!" },
536 { actor: logic.player, text: "I need it." },
537 { actor: this, text: "..." } ] ));
538 break;
539 default:
540 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Don't you have anything better to do, Carlos?" } ] ));
541 }
542 }
543 super.actionTalk();
544 }
545
546 actionTalk_afternoon() {
547 if (logic.peter.alive) {
548 switch (this.talkcount) {
549 case 0:
550 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Oh, hi John!" },
551 { actor: logic.carlos, text: "Hey John! Thanks for telling my secret to Saiki..." },
552 { actor: logic.player, text: "Really sorry man, but it was so funny!" },
553 { actor: logic.carlos, text: "Are you kidding me? It's the best thing you could have ever done!" },
554 { actor: this, text: "Yeah, I couldn't resist to come over here to talk about it, haha!" },
555 { actor: logic.carlos, text: "And we talked about lots of other stuff too..." },
556 { actor: this, text: "WE ASKED EACH OTHER OUT ON A DATE!!!" },
557 { actor: logic.carlos, text: "Yeah, Saiki finds gender equality so important that she had to take the role of the initiator, just in the right moment when I asked her out." },
558 { actor: this, text: "Oh, shut up! xD" },
559 { actor: logic.player, text: "Awesome, I'm so happy for you guys!" },
560 { actor: logic.player, text: "... Don't mean to ruin the fun, but have you finished with your work?" },
561 { actor: logic.carlos, text: "Who cares? It waits. I can totally sell the shit tomorrow." },
562 { actor: this, text: "Yeah, I'll commit my patch tomorrow morning. We definitely deserve some fun!" },
563 { actor: logic.player, text: "You say it right! Bye then." } ] ));
564 break;
565 default:
566 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Have a great evening, guys!" } ] ));
567 }
568 }
569 else {
570 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Oh... hi Peter!..." },
571 { actor: this, text: "I wanted to talk to Carlos..." },
572 { actor: this, text: "Where is he? I mean, he often leaves early, but..." },
573 { actor: this, text: "I can't explain why, but somehow I have a very bad feeling about this. " },
574 { actor: logic.player, text: "..." } ] ));
575 }
576 super.actionTalk();
577 }
578
579 actionLeave() {
580 if (logic.carlos.alive) {
581 logic.gameinterface.dropNotice(this.shortname + ": It was nice talking to you!");
582 }
583 }
584
585 actionTake() {
586 logic.closeDoor("carlosdoor");
587 logic.openDoor("saikidoor");
588 logic.openDoor("peterdoor");
589 logic.carlos.kill();
590 return super.actionTake();
591 }
592
593 endTalk() {
594 return (logic.carlos.alive) && (!this.happy);
595 }
596
597 tpDone(value) {
598 console.log("Woot-woot! Teleport complete:", value);
599 value.makeHappy();
600 value.resetTalk();
601 logic.carlos.makeHappy();
602 // FIXME: Need to find a prettier way than this.
603 logic.carlos.update = function() { }; // Disable Carlos' interaction. (Saiki will talk for him.)
604 }
605 }
606
607 class NPC_Peter extends GameNPC {
608 actionTalk() {
609 if (logic.saiki.alive) {
610 switch (this.talkcount) {
611 case 0:
612 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Hi Peter! What's up?" },
613 { actor: this, text: "Hi John! Bianca has locked herself in the large meeting room." },
614 { actor: logic.player, text: "Why would she do that?" },
615 { actor: this, text: "I have no idea." },
616 { actor: this, text: "Normally, I would give a fuck about what she's doing and her problems, but I want to hold a meeting in an hour." },
617 { actor: logic.player, text: "That was rude. I think you should care more about your colleagues." },
618 { actor: this, text: "Ahh... You're right. I didn't mean it. I'm just so frustrated about all the shit going on here." } ] ));
619 logic.closeDoor("saikidoor");
620 logic.openDoor("peterdoor");
621 logic.openDoor("biancadoor");
622 break;
623 case 1:
624 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "See... Would you talk to Bianca? We don't understand each other pretty well. That's why I'd rather wouldn't make a shot." } ] ));
625 break;
626 default:
627 if ((logic.clara.talkcount >= 5) && (this.talkcount == 2)) {
628 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Do you know Clara from the Reception?" },
629 { actor: this, text: "Of course I do." },
630 { actor: logic.player, text: "I think she's mad at me..." },
631 { actor: this, text: "Why would she?" },
632 { actor: logic.player, text: "I kind of... asked her out." },
633 { actor: logic.player, text: "She said no." },
634 { actor: this, text: "What the heck, dude?" },
635 { actor: this, text: "..." },
636 { actor: this, text: "You should know it's against the company etiquette..." },
637 { actor: this, text: "Regardless, I don't think she's really mad. You're a cool guy." },
638 { actor: logic.player, text: "I hope this will be sorted out... I totally accept her answer, but I wouldn't like her to have negative feelings towards me." } ] ));
639 this.offscreenTeleportation(new Phaser.Point(logic.clara.x - 160, logic.clara.y), this.tpDone, this);
640 }
641 else {
642 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "I'm kind of busy, man." } ] ));
643 }
644 }
645 }
646 else {
647 switch (this.talkcount) {
648 case 0:
649 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "What a wonderful day, Peter!" },
650 { actor: this, text: "Yikes! Saiki! You scared me!" },
651 { actor: logic.player, text: "I didn't even say \"boo\"." },
652 { actor: this, text: "Are you OK? You look horrible! You should really see a doctor." },
653 { actor: logic.player, text: "I'm fine, Peter. And you?" },
654 { actor: this, text: "No... Not at all." },
655 { actor: logic.player, text: "I'm sorry to hear that..." } ] ));
656 break;
657 case 1:
658 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Don't come closer to me!" },
659 { actor: logic.player, text: "Why?" },
660 { actor: this, text: "I don't mean to offend you, but... you really creep me out..." },
661 { actor: logic.player, text: "Why do you say that?" },
662 { actor: this, text: "I honestly can't tell what's wrong with you, but... you look like that ghost girl from The Ring!" } ] ));
663 break;
664 case 2:
665 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Now that was pretty much racist..." },
666 { actor: logic.player, text: "Just because I have a Japanese name and long black hair, that makes me immediately look like the Japanese girl from Ring when I'm sick?" },
667 { actor: this, text: "Geez... that's not even a Japanese movie! And the actress is American..." },
668 { actor: logic.player, text: "The original movie is Japanese." },
669 { actor: this, text: "I don't care... Just... keep distance, please!" } ] ));
670 break;
671 default:
672 if (Phaser.Math.random() < 0.5) {
673 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "STAY AWAY FROM ME!" } ] ));
674 }
675 else {
676 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "DON'T COME ANY CLOSER!" } ] ));
677 }
678 }
679 }
680 super.actionTalk();
681 }
682
683 actionTake() {
684 logic.closeDoor("saikidoor");
685 logic.openDoor("peterdoor");
686 logic.openDoor("biancadoor");
687 logic.carlos.kill();
688 if (logic.saiki.talkcount > 0) logic.saiki.kill();
689 return super.actionTake();
690 }
691
692 endTalk() {
693 return (logic.saiki.alive) && (this.talkcount < 3);
694 }
695
696 tpDone(value) {
697 console.log("Woot-woot! Teleport complete:", value);
698 value.makeHappy();
699 logic.clara.makeHappy();
700 // FIXME: Need to find a prettier way than this.
701 logic.clara.update = function() { }; // Disable Clara's interaction. (Peter will talk for him.)
702 }
703 }
704
705 class NPC_Bianca extends GameNPC {
706 actionTalk() {
707 if (logic.peter.alive) {
708 switch (this.talkcount) {
709 case 0:
710 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "... Hi Bianca!" },
711 { actor: this, text: "... Hello John!" },
712 { actor: logic.player, text: "So I've been told, you've been spending most of the day in this meeting room..." },
713 { actor: this, text: "Yeah?" },
714 { actor: logic.player, text: "... Your colleagues want to hold a meeting in this room and you're blocking it." },
715 { actor: this, text: "Hmm... Kind of that's the point... There is no need for that meeting." },
716 { actor: logic.player, text: "May I know why?" },
717 { actor: this, text: "You must have heard about the layoffs. We weren't happy with that, but it was inevitable to meet the productivity requirements." },
718 { actor: this, text: "But today morning, I received a list with about 50% of the employees... Many of them are great friends of mine..." },
719 { actor: this, text: "We were like a big family here and we're torn apart like this... The worst is that I have to tell the news to all of them." },
720 { actor: logic.player, text: "That's rough. Does this company even need people?" },
721 { actor: this, text: "..." } ] ));
722 logic.openDoor("cutedoor");
723 logic.closeDoor("peterdoor");
724 break;
725 case 1:
726 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "Bianca... Am I on that list?" },
727 { actor: this, text: "Yes, John." },
728 { actor: this, text: "Well, I'll try to convince them to keep you and many other great folks from the list." },
729 { actor: this, text: "But... I can't promise anything. Also, it would help your case a lot if you made some notable work today, so I could mention it as your recent achievement." },
730 { actor: logic.player, text: "Thank you very much... I'll see what I can do." } ] ));
731 break;
732 case 2:
733 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "You seem to be somehow blaming yourself. It's not your fault. You're just doing your job." },
734 { actor: this, text: "I know. It's just part of my work..." },
735 { actor: this, text: "But if you have to sweep out such a great volume of people within such a short time... It does take its toll on the person." },
736 { actor: this, text: "... I feel like I'm growing distant from the company." },
737 { actor: this, text: "I mean... probably it's heresy to say that, but I feel I can less and less identify with the company's values." },
738 { actor: logic.player, text: "Yeah, you should definitely not talk about it to others... I mean, maybe only those you deeply trust." },
739 { actor: this, text: "I don't care anymore..." },
740 { actor: logic.player, text: "Fine." },
741 { actor: logic.player, text: "See... probably there is no need for such drama. Maybe it's for the best for everyone." },
742 { actor: logic.player, text: "... After all, there IS life beyond the company..." },
743 { actor: this, text: "You think so?..." },
744 { actor: this, text: "Hmm..." },
745 { actor: this, text: "I never thought about it for a long time..." },
746 { actor: logic.player, text: "There are plenty of other opportunities for us! Everything will be fine!" },
747 { actor: this, text: "..." },
748 { actor: this, text: "Thank you. This helped me to regain a bit of my composure..." },
749 { actor: logic.player, text: "You're welcome." } ] ));
750 this.makeHappy();
751 break;
752 default:
753 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "Thank you. I'll go back to work soon. Just give some more minutes of alone time." } ] ));
754 }
755 }
756 else {
757 switch (this.talkcount) {
758 case 0:
759 logic.gameinterface.talk(new Dialogue( [ { actor: logic.player, text: "..." },
760 { actor: this, text: "... So you came for me too." },
761 { actor: this, text: "..." },
762 { actor: this, text: "I know what you are..." },
763 { actor: this, text: "..." },
764 { actor: this, text: "Let's get over with." },
765 { actor: logic.player, text: "..." } ] ));
766 break;
767 default:
768 logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "What are you waiting for?" } ] ));
769 }
770 }
771 super.actionTalk();
772 }
773
774 actionLeave() {
775 if (this.happy) {
776 logic.gameinterface.dropNotice(this.shortname + ": Thank you. I'll go back to work soon.");
777 }
778 }
779
780 actionTake() {
781 // All doors open for you if you have all the cards.
782 logic.openDoor("cutedoor");
783 logic.openDoor("carlosdoor");
784 logic.openDoor("saikidoor");
785 return super.actionTake();
786 }
787 }
788
789
790 class GameInterface extends Phaser.Group {
791 constructor(game, parent) {
792 super(game, parent, 'GUI', false, false, 0);
793 this.back_notice = new Phaser.Graphics(game, 0, game.height - 50);
794 this.back_notice.beginFill(0x000000);
795 this.back_notice.drawRect(0, 0, game.width, 30);
796 this.back_notice.endFill();
797 this.add(this.back_notice);
798 this.text_notice = new Phaser.Text(game, 125, this.back_notice.y + 5, null, { align: 'left', fill: 'white', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' });
799 this.add(this.text_notice);
800 this.clearNotice();
801
802 this.back_menu = new Phaser.Graphics(game, 150, (game.height / 2) + 40);
803 this.back_menu.beginFill(0x000000);
804 this.back_menu.drawRect(0, 0, 155, 105);
805 this.back_menu.endFill();
806 this.back_menu.lineStyle(3, Phaser.Color.YELLOW, 1);
807 this.back_menu.moveTo(10, 35);
808 this.back_menu.lineTo(this.back_menu.width - 10, 35);
809 this.add(this.back_menu);
810 var style = { align: 'left', fill: 'yellow', font: 'Ubuntu Mono', fontSize: 22, fontWeight: 'bold' };
811 this.text_menutitle = new Phaser.Text(game, this.back_menu.x, this.back_menu.y, null, style);
812 this.text_menutitle.anchor.setTo(-0.2, -0.2);
813 style = { align: 'left', fill: 'white', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' };
814 this.text_menuitem_Talk = new Phaser.Text(game, this.back_menu.x + 35, this.back_menu.y + 40, "Talk", style);
815 this.text_menuitem_Leave = new Phaser.Text(game, this.back_menu.x + 35, this.text_menuitem_Talk.y + GUI_MENUITEM_DISTANCE, "Leave", style);
816 this.text_menuitem_Take = new Phaser.Text(game, this.back_menu.x + 35, this.text_menuitem_Leave.y + GUI_MENUITEM_DISTANCE, "Take ID", style);
817 style.fill = 'yellow';
818 this.text_menucursor = new Phaser.Text(game, this.back_menu.x + 15, this.text_menuitem_Talk.y, "→", style);
819 this.add(this.text_menutitle);
820 this.add(this.text_menuitem_Talk);
821 this.add(this.text_menuitem_Leave);
822 this.add(this.text_menuitem_Take);
823 this.add(this.text_menucursor);
824 this.leaveMenu();
825 this.last_menustep = 0;
826
827 this.back_talk = new Phaser.Graphics(game, 100, game.height - 120);
828 this.back_talk.beginFill(0x000000);
829 this.back_talk.drawRect(0, 0, game.width - 200, 105);
830 this.back_talk.endFill();
831 this.back_talk.lineStyle(3, Phaser.Color.YELLOW, 1);
832 this.back_talk.moveTo(10, 35);
833 this.back_talk.lineTo(this.back_talk.width - 10, 35);
834 this.add(this.back_talk);
835 style = { align: 'left', fill: 'yellow', font: 'Ubuntu Mono', fontSize: 22, fontWeight: 'bold' };
836 this.text_talktitle = new Phaser.Text(game, this.back_talk.x + 15, this.back_talk.y + 6, null, style);
837 //this.text_talktitle.anchor.setTo(-0.2, -0.2);
838 this.add(this.text_talktitle);
839 this.strikethrough_talktitle = new Phaser.Graphics(game, this.back_talk.x, this.back_talk.y);
840 this.strikethrough_talktitle.lineStyle(3, Phaser.Color.RED, 1);
841 this.strikethrough_talktitle.moveTo(12, 20);
842 this.strikethrough_talktitle.lineTo(67, 20);
843 this.add(this.strikethrough_talktitle);
844 style = { align: 'left', fill: 'white', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' };
845 this.text_talk = new Phaser.Text(game, this.back_talk.x + 35, this.back_talk.y + 40, null, style);
846 this.text_talk.wordWrap = true;
847 this.text_talk.wordWrapWidth = this.back_talk.width - 70;
848 this.text_talk.lineSpacing = -5;
849 this.add(this.text_talk);
850 this.leaveTalk();
851 this.last_talk = 0;
852 }
853
854 dropNotice(text) {
855 this.text_notice.text = text;
856 this.back_notice.visible = true;
857 this.text_notice.visible = true;
858 }
859
860 dropNoticeTimeout(timeout, text) {
861 this.dropNotice(text);
862 game.time.events.add(timeout, this.clearNotice, this);
863 }
864
865 clearNotice() {
866 this.back_notice.visible = false;
867 this.text_notice.visible = false;
868 }
869
870 npcMenu(npc) {
871 if (!this.inMenu) {
872 this.inMenu = true;
873 this.clearNotice();
874 this.text_menutitle.text = npc.shortname;
875 this.back_menu.visible = true;
876 this.text_menutitle.visible = true;
877 this.text_menuitem_Talk.visible = true;
878 this.text_menuitem_Leave.visible = true;
879 this.text_menuitem_Take.visible = true;
880 this.currentmenuitem = MENUITEM_TALK;
881 this.actualizeCursorPosition();
882 this.text_menucursor.visible = true;
883 this.last_menustep = game.time.now;
884 }
885 }
886
887 leaveMenu() {
888 this.back_menu.visible = false;
889 this.text_menutitle.visible = false;
890 this.text_menuitem_Talk.visible = false;
891 this.text_menuitem_Leave.visible = false;
892 this.text_menuitem_Take.visible = false;
893 this.text_menucursor.visible = false;
894 this.inMenu = false;
895 }
896
897 talk(dialogue) {
898 this.inTalk = true;
899 this.dialogue = dialogue;
900 this.advanceTalk();
901 this.back_talk.visible = true;
902 this.text_talktitle.visible = true;
903 this.text_talk.visible = true;
904 }
905
906 leaveTalk() {
907 this.inTalk = false;
908 this.dialogue = null;
909 this.back_talk.visible = false;
910 this.text_talktitle.visible = false;
911 this.strikethrough_talktitle.visible = false;
912 this.text_talk.visible = false;
913 }
914
915 advanceTalk() {
916 console.log(this.dialogue);
917 console.log(this.dialogue.actual());
918 var actualdialogue = this.dialogue.actual();
919 if (actualdialogue) {
920 if (actualdialogue.actor.disguise) {
921 this.text_talktitle.text = actualdialogue.actor.shortname + " " + actualdialogue.actor.disguise.shortname;
922 this.strikethrough_talktitle.visible = true;
923 }
924 else {
925 this.text_talktitle.text = actualdialogue.actor.shortname;
926 this.strikethrough_talktitle.visible = false;
927 }
928 this.text_talk.text = actualdialogue.text;
929 this.dialogue.advance();
930 }
931 else {
932 this.leaveTalk();
933 logic.endTalk();
934 }
935 this.last_talk = game.time.now;
936 }
937
938 actualizeCursorPosition() {
939 this.text_menucursor.y = this.text_menuitem_Talk.y + (this.currentmenuitem * GUI_MENUITEM_DISTANCE);
940 }
941
942 update() {
943 if ((this.inMenu) && (hasTimePassed(this.last_menustep, WAIT_MENUSTEP))) {
944 if (cursors.up.isDown)
945 {
946 this.currentmenuitem--;
947 if (this.currentmenuitem < MENUITEM_TALK) this.currentmenuitem = MENUITEM_TAKE;
948 this.actualizeCursorPosition();
949 }
950 else if (cursors.down.isDown)
951 {
952 this.currentmenuitem++;
953 if (this.currentmenuitem > MENUITEM_TAKE) this.currentmenuitem = MENUITEM_TALK;
954 this.actualizeCursorPosition();
955 }
956 if (game.input.keyboard.isDown(Phaser.Keyboard.ENTER)) {
957 logic.callMenu(this.currentmenuitem);
958 }
959 this.last_menustep = game.time.now;
960 }
961 if ((this.inTalk) && (game.input.keyboard.isDown(Phaser.Keyboard.ENTER)) && (hasTimePassed(this.last_talk, WAIT_TALK))) {
962 this.advanceTalk();
963 }
964 }
965 }
966
967 class GameLogic {
968
969 constructor() {
970 this.player = this.clara = this.carlos = this.saiki = this.peter = this.bianca = null;
971 this.gameinterface = new GameInterface(game, game.stage);
972 //this.doors = game.add.group(game.world, "doors");
973 this.last_menuselect = 0;
974 }
975
976 createObject(object) {
977 switch (object.type) {
978 case 'spawnpoint': this.createCharacter(object); break;
979 case 'door': this.createDoor(object); break;
980 case '': console.error("Object type is empty:", object); break;
981 default: console.error("Unknown object type:", object);
982 }
983 }
984
985 createCharacter(object) {
986 var newChar;
987 switch (object.name) {
988 case 'john':
989 newChar = new Player(object.x, object.y, 'player');
990 this.player = newChar;
991 this.player.enablePhysics();
992 game.camera.follow(this.player);
993 break;
994 case 'clara':
995 newChar = new NPC_Clara(object.x, object.y, 'clara', "Clara", "Clara Tnavelerri", 200);
996 this.clara = newChar;
997 break;
998 case 'carlos':
999 newChar = new NPC_Carlos(object.x, object.y, 'carlos', "Carlos", "Carlos Elbacalper", 150);
1000 this.carlos = newChar;
1001 break;
1002 case 'saiki':
1003 newChar = new NPC_Saiki(object.x, object.y, 'saiki', "Saiki", "Saiki Ytpme", 150);
1004 this.saiki = newChar;
1005 break;
1006 case 'peter':
1007 newChar = new NPC_Peter(object.x, object.y, 'peter', "Peter", "Peter Tluaf", 225);
1008 this.peter = newChar;
1009 break;
1010 case 'bianca':
1011 newChar = new NPC_Bianca(object.x, object.y, 'bianca', "Bianca", "Bianca Gnihton", 150);
1012 this.bianca = newChar;
1013 break;
1014 default:
1015 console.error("Unknown character:", object);
1016 }
1017 newChar.name = object.name;
1018 game.add.existing(newChar);
1019 console.log(newChar);
1020 }
1021
1022 createDoor(object) {
1023 /* Calculate movement vector and correct position (32 = half tile width/height). */
1024 var vector;
1025 switch (object.rotation) {
1026 case undefined:
1027 case 0: vector = new Phaser.Point( -1, 0); object.x += 32; object.y -= 32; break;
1028 case 90: vector = new Phaser.Point( 0, -1); object.x += 32; object.y += 32; break;
1029 case 180: vector = new Phaser.Point( 1, 0); object.x -= 32; object.y += 32; break;
1030 case 270: vector = new Phaser.Point( 0, 1); object.x -= 32; object.y -= 32; break;
1031 default: console.error("Invalid rotation:", object.rotation);
1032 }
1033 this.doors.add(new Door(object.x, object.y, object.name, object.rotation, vector, object.properties.longpanel));
1034 }
1035
1036 callMenu(menuitem) {
1037 console.log("Menu callback received:", menuitem);
1038 this.last_menuselect = game.time.now;
1039 this.gameinterface.leaveMenu();
1040 switch (menuitem) {
1041 case MENUITEM_TALK:
1042 this.player.interactablenpc.actionTalk();
1043 break;
1044 case MENUITEM_LEAVE:
1045 this.player.interactablenpc.actionLeave();
1046 this.player.unfreeze();
1047 break;
1048 case MENUITEM_TAKE:
1049 if (this.player.interactablenpc.actionTake())
1050 this.player.unfreeze();
1051 break;
1052 }
1053 }
1054
1055 endTalk() {
1056 if (this.player.interactablenpc) {
1057 if (this.player.interactablenpc.endTalk()) {
1058 this.gameinterface.npcMenu(this.player.interactablenpc);
1059 }
1060 else {
1061 this.player.unfreeze();
1062 this.last_menuselect = game.time.now;
1063 }
1064 }
1065 }
1066
1067 openDoor(doorname) {
1068 this.doors.children.forEach(function(o) { if (o.name == doorname) o.open(); });
1069 }
1070
1071 closeDoor(doorname) {
1072 this.doors.children.forEach(function(o) { if (o.name == doorname) o.close(); });
1073 }
1074
1075 checkAllHappy() {
1076 return (this.clara.happy) && (this.carlos.happy) && (this.saiki.happy);
1077 }
1078
1079 update() {
1080 if ((game.input.keyboard.isDown(Phaser.Keyboard.ENTER)) && (hasTimePassed(this.last_menuselect, WAIT_MENUSTEP))) {
1081 if ((this.player.interactablenpc) && (this.player.interactablenpc.interactable) && (!this.gameinterface.inMenu) && (!this.gameinterface.inTalk)) {
1082 console.log("Starting interaction with", this.player.interactablenpc.fullname);
1083 this.player.freeze();
1084 this.gameinterface.npcMenu(this.player.interactablenpc);
1085 }
1086 }
1087 }
1088
1089 }
1090
1091 class GamePlay extends Phaser.State {
1092
1093 constructor() {
1094
1095 super();
1096 logic = new GameLogic();
1097 game.world.updateOnlyExistingChildren = true;
1098 game.state.add('GameOver', GameOver, false);
1099
1100 }
1101
1102 preload() {
1103
1104 game.load.image('player', 'john.png');
1105 game.load.image('clara', 'clara.png');
1106 game.load.image('carlos', 'carlos.png');
1107 game.load.image('saiki', 'saiki.png');
1108 game.load.image('peter', 'peter.png');
1109 game.load.image('bianca', 'bianca.png');
1110 game.load.image('tileset', 'tileset.png');
1111 game.load.image('objects', 'objects.png');
1112 game.load.tilemap('gamemap', 'tilemap.json', null, Phaser.Tilemap.TILED_JSON);
1113
1114 }
1115
1116 create() {
1117
1118 game.world.setBounds(0, 0, 800, 600);
1119 game.stage.backgroundColor = '#000000';
1120 game.physics.startSystem(Phaser.Physics.ARCADE);
1121 console.log("Debug enabled:", !game.debug.isDisabled);
1122
1123 var map = game.add.tilemap('gamemap');
1124 map.addTilesetImage('tileset', 'tileset');
1125 map.addTilesetImage('objects', 'objects');
1126 var layer_floor = map.createLayer('floor');
1127 layer_floor.resizeWorld();
1128 this.layer_walls = map.createLayer('walls');
1129 map.setCollisionBetween(1, 100, true, this.layer_walls);
1130 this.layer_furniture = map.createLayer('furniture');
1131 map.setCollisionBetween(1, 100, true, this.layer_furniture);
1132
1133 // FIXME: Don't create a group here like this, it's too ugly! Now I have it here due to the display order.
1134 logic.doors = game.add.group(game.world, "doors");
1135
1136 map.objects['objects'].forEach(function(o) { logic.createObject(o); });
1137 console.log(map.objects);
1138
1139 cursors = game.input.keyboard.createCursorKeys();
1140 console.log(logic);
1141
1142 }
1143
1144 update() {
1145
1146 game.physics.arcade.collide(logic.player, this.layer_walls);
1147 game.physics.arcade.collide(logic.player, this.layer_furniture);
1148 game.physics.arcade.collide(logic.player, logic.doors);
1149 logic.update();
1150
1151 }
1152 }
1153
1154 class GameOver extends Phaser.State {
1155
1156 create() {
1157
1158 console.log("Entered GameOver state.");
1159 game.stage.removeChildren(1);
1160 game.camera.follow(logic.player);
1161 logic.player.freeze();
1162
1163 var g = game.add.group(game.stage, "GAMEOVER");
1164 this.back_gameover = new Phaser.Graphics(game, 100, game.height / 2 - 200);
1165 this.back_gameover.beginFill(0x000000);
1166 this.back_gameover.drawRect(0, 0, game.width - 200, 400);
1167 this.back_gameover.endFill();
1168 this.back_gameover.lineStyle(3, Phaser.Color.YELLOW, 1);
1169 this.back_gameover.moveTo(10, 35);
1170 this.back_gameover.lineTo(this.back_gameover.width - 10, 35);
1171 g.add(this.back_gameover);
1172 var style = { align: 'left', fill: 'yellow', font: 'Ubuntu Mono', fontSize: 22, fontWeight: 'bold' };
1173 this.text_title = new Phaser.Text(game, this.back_gameover.x + 15, this.back_gameover.y + 6, "ABRUPT GAME OVER", style);
1174 g.add(this.text_title);
1175 style = { align: 'left', fill: 'white', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' };
1176 this.text_gameover = new Phaser.Text(game, this.back_gameover.x + 35, this.back_gameover.y + 60, null, style);
1177 this.text_gameover.wordWrap = true;
1178 this.text_gameover.wordWrapWidth = this.back_gameover.width - 70;
1179 this.text_gameover.lineSpacing = -5;
1180 g.add(this.text_gameover);
1181
1182 this.text_gameover.text = this.assess();
1183
1184 }
1185
1186 assess() {
1187 if (logic.checkAllHappy()) {
1188 return "You listened to all of your colleagues' and affected them to make their day a little better. Next day, the company fired Clara, Carlos, Saiki, and you, to comply with its productivity requirements. The company's internal code demand unconditional and illimitable loyalty from employees to maximize productivity. This includes requisites for employees not to exercise human qualities or express personal needs within and outside the corporate environment. The company has determined that neither of the mentioned people complied to these guidelines, due to the amount of socialization they pursued during the work day.\n\nIronically, the layoffs turned everyone's life for the better.";
1189 }
1190 else if (logic.player.disguise) {
1191 this.text_gameover.style.fill = 'red';
1192 return "You went on your day to accomplish your tasks without caring about anyone. Where are your colleagues now? Clara, Carlos, Saiki? You don't know. But you don't even care. You have never seen them after they served your needs.\n\nNext day, the company promoted you for your effectiveness and loyalty.";
1193 }
1194 else {
1195 return "The company is concerned that you may develop other needs (like wanting to pursue hobbies, spend time with friends and family) those compete for the time you devote for your job. The company reminds you that they demand your entire being to exclusively serve the company's interests. Socializing with your colleagues outside the dedicated team building occasions may hurt your performance. To comply with the productivity requirements, the company has terminated your employment.\n\nClara, Carlos, Saiki are still loyal employees of the company. Probably you could have done something different to find a better outcome.";
1196 }
1197 }
1198
1199 }