1 var game
= new Phaser
.Game(800, 600, Phaser
.AUTO
, '', { preload: function() { this.state
.add('GamePlay', GamePlay
, true); } });
5 const PLAYER_SPEED
= 200;
6 const WAIT_MENUSTEP
= 100;
9 const MENUITEM_TALK
= 0;
10 const MENUITEM_LEAVE
= 1;
11 const MENUITEM_TAKE
= 2;
13 const GUI_MENUITEM_DISTANCE
= 20;
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) {
22 function hasTimePassed(time
, delay
) {
23 return (game
.time
.now
- time
) > delay
;
27 // dialogue is array of {actor, text} records.
28 constructor(dialogue
) {
29 this.dialogue
= dialogue
;
34 return this.dialogue
[this.state
];
42 class Door
extends Phaser
.TileSprite
{
43 constructor(x
, y
, name
, rotation
, vector
, longpanel
) {
44 super(game
, x
, y
, 64, 64, 'objects');
46 this.longpanel
= 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));
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));
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);
64 game
.physics
.arcade
.enable(this);
65 this.body
.immovable
= true;
66 this.setBody(rotation
);
73 this.body
.setSize(this.width
, 10, this.longpanel
* (rotation
/ 180) * 64, 27);
77 this.body
.setSize(10, this.width
, 27 + (this.longpanel
* 64), this.longpanel
* ((rotation
- 270) / 180) * 64);
80 console
.log("Unable to set body due to unknown rotation:", rotation
);
86 this.opentween
.start();
93 this.closetween
.start();
99 game
.debug
.body(this);
103 class Player
extends Phaser
.Sprite
{
105 super(game
, x
, y
, 'player');
106 this.y
-= this.height
;
107 this.shortname
= "John";
108 this.fullname
= "John Evals";
109 this.offerInteraction(null);
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;
121 if ((this.alive
) && (!this.freezed
))
123 if (cursors
.left
.isDown
)
125 this.body
.velocity
.x
= -PLAYER_SPEED
;
127 else if (cursors
.right
.isDown
)
129 this.body
.velocity
.x
= PLAYER_SPEED
;
131 if (cursors
.up
.isDown
)
133 this.body
.velocity
.y
= -PLAYER_SPEED
;
135 else if (cursors
.down
.isDown
)
137 this.body
.velocity
.y
= PLAYER_SPEED
;
143 this.body
.velocity
.x
= this.body
.velocity
.y
= 0;
152 this.freezed
= false;
155 offerInteraction(npc
) {
156 this.interactablenpc
= npc
;
160 this.loadTexture(npc
.key
);
166 class GameNPC
extends Phaser
.Sprite
{
167 constructor(x
, y
, key
, shortname
, fullname
, interaction_distance
) {
168 super(game
, x
, y
, key
);
169 this.y
-= this.height
;
170 this.shortname
= shortname
;
171 this.fullname
= fullname
;
172 this.interaction_distance
= interaction_distance
;
173 this.interactable
= false;
184 if ((!this.interactable
) && (game
.physics
.arcade
.distanceBetween(this, logic
.player
) < this.interaction_distance
)) {
185 logic
.gameinterface
.dropNotice("(ENTER) Interact with " + this.shortname
+ "!");
186 logic
.player
.offerInteraction(this);
187 this.interactable
= true;
189 else if ((this.interactable
) && (game
.physics
.arcade
.distanceBetween(this, logic
.player
) > this.interaction_distance
)) {
190 logic
.gameinterface
.clearNotice();
191 logic
.player
.offerInteraction(null);
192 this.interactable
= false;
204 logic
.player
.offerInteraction(null);
205 logic
.player
.takeMe(this);
214 class NPC_Clara
extends GameNPC
{
216 switch (this.talkcount
) {
218 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "What a morning..." },
219 { actor
: logic
.player
, text
: "Hi Clara! What happened?" },
220 { 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." },
221 { actor
: logic
.player
, text
: "Hmm... I'll look into it. Maybe it's just that everyone is fired." },
222 { actor
: this, text
: "Haha! Wouldn't joke about this, though, due to the recent layoffs." },
223 { actor
: logic
.player
, text
: "Well, maybe if we dare to joke about it, it won't happen to us..." },
224 { actor
: this, text
: "Wish it worked like that... Is it some superstition like the belief that having an umbrella with you prevents rain?" },
225 { actor
: logic
.player
, text
: "Nah, that actually works; it's not a superstition, but Murphy's Law!" },
226 { actor
: this, text
: "If you say so..." },
227 { actor
: this, text
: "Anyway, I logged you in and opened the door for you." } ] ));
228 logic
.openDoor("cutedoor");
231 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "John, have you ever thought about losing your employee card?" },
232 { actor
: logic
.player
, text
: "Yeah, you'd just get a new one." },
233 { actor
: this, text
: "You don't understand me, John!" },
234 { actor
: this, text
: "..." },
235 { actor
: this, text
: "I mean... Losing it for real..." },
236 { actor
: this, text
: "Doesn't it feel like it's the culmination of your being?" },
237 { actor
: this, text
: "If I had no card, would I still exist?" },
238 { actor
: logic
.player
, text
: "..." },
239 { actor
: logic
.player
, text
: "You sound very philosophical today." } ] ));
244 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "Would you like to hear a random fun fact?" },
245 { actor
: logic
.player
, text
: "Of course!" },
246 { 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," },
247 { 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" },
248 { actor
: this, text
: "into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem" },
249 { actor
: this, text
: "Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." },
250 { actor
: logic
.player
, text
: "That's very interesting, I didn't know that!" },
251 { actor
: logic
.player
, text
: "Thanks for sharing, Clara!" } ] ));
254 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "Would you like to hear a random fun fact?" },
255 { actor
: logic
.player
, text
: "Of course!..." },
256 { actor
: logic
.player
, text
: "But first..." },
257 { actor
: this, text
: "What is it?" },
258 { actor
: logic
.player
, text
: "..." },
259 { actor
: logic
.player
, text
: "Never mind, go on with what you wanted to say." },
260 { actor
: this, text
: "Lorem Ipsum is simply dummy text of the printing and typesetting industry..." },
261 { actor
: logic
.player
, text
: "I knew that already..." },
262 { actor
: logic
.player
, text
: "But..." },
263 { actor
: logic
.player
, text
: "Would you go out on a date with me?" },
264 { actor
: this, text
: "..." },
265 { actor
: this, text
: "No." } ] ));
268 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "..." } ] ));
274 logic
.gameinterface
.dropNotice(this.shortname
+ ": Have a great day, John!");
278 logic
.openDoor("cutedoor");
279 return super.actionTake();
283 return (this.talkcount
< 6);
287 class NPC_Carlos
extends GameNPC
{
289 if (logic
.clara
.alive
) {
290 switch (this.talkcount
) {
292 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "Good morning, Carlos! What's up?" },
293 { actor
: this, text
: "Hey, John! Not too much, I'm just trying to sell some shit to this new client." },
294 { actor
: logic
.player
, text
: "And so? Is it hard to convince them?" },
295 { actor
: this, text
: "Of course, they don't want to buy. It's shit." },
296 { actor
: this, text
: "I mean, who would want to buy shit?" },
297 { actor
: logic
.player
, text
: "Yeah. Relatable... But why are you trying to sell shit? I mean, why not one of our cutting edge technologies?" },
298 { actor
: this, text
: "They couldn't afford it." },
299 { actor
: logic
.player
, text
: "Then why are you trying to sell them... anything at all? They'd better off with a cheaper company." },
300 { actor
: this, text
: "Company policies. Plus the management instructed me to sell to them, no matter what." },
301 { actor
: logic
.player
, text
: "That sucks... Well... good luck!" },
302 { actor
: this, text
: "Thanks..." } ] ));
303 logic
.closeDoor("cutedoor");
304 logic
.openDoor("carlosdoor");
307 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." },
308 { actor
: this, text
: "These layoffs are terrifying. They let go of anyone for even the slightest mistake." },
309 { actor
: logic
.player
, text
: "But it's not a mistake when our client doesn't buy something they don't need." },
310 { actor
: this, text
: "Tell this to my boss..." } ] ));
313 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." },
314 { actor
: this, text
: "..." },
315 { 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..." },
316 { 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." },
317 { actor
: this, text
: "So I thought I could grow my own pig in the garden from pig seeds!" },
318 { actor
: logic
.player
, text
: "Interesting. Where are you going with this?" },
319 { actor
: this, text
: "I don't know... sometimes I feel like I'd rather sell pig semen to our clients, heh!" },
320 { actor
: this, text
: "Uhm..." },
321 { actor
: this, text
: "Totally don't tell this to Saiki!" } ] ));
322 this.pigsemen
= true;
325 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "Weren't you heading to the IT department to the right?" },
326 { actor
: this, text
: "You know... the green department which looks way better than blue!" },
327 { actor
: this, text
: "..." },
328 { actor
: this, text
: "Damn, why do I have to work in blue? I just feel... so blue about it." } ] ));
331 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." },
332 { actor
: this, text
: "You're so lucky that you can work with her every day!" } ] ));
335 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "Guess you'll stay here then. It's cool, you're great company anyway." } ] ));
339 switch (this.talkcount
) {
341 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "Good morning, Carlos!" },
342 { actor
: this, text
: "Whoa, Clara! You have changed so much! I barely recognize you. What's up?" },
343 { actor
: logic
.player
, text
: "I need to talk to Saiki at the IT department, but... my card doesn't allow me to enter there." },
344 { actor
: this, text
: "Well... I can certainly help you with that..." },
345 { actor
: this, text
: "..." } ] ));
348 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "Carlos. You promised to help me." },
349 { actor
: this, text
: "Uhm... It's just... Please give me 5 mins to finish this e-mail." },
350 { actor
: logic
.player
, text
: "I don't have much time, Carlos." },
351 { 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." },
352 { actor
: logic
.player
, text
: "..." } ] ));
355 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "Time is up, Carlos!" },
356 { actor
: this, text
: "Please give me just another min." },
357 { actor
: logic
.player
, text
: "Fine. Please just give me your card and I'll help myself!" },
358 { actor
: this, text
: "But... you know that company policies forbid that, Clara! Please just be a little more patient!" },
359 { actor
: logic
.player
, text
: "You will give me your card now or you will regret!" },
360 { actor
: this, text
: "...?" },
361 { actor
: this, text
: "You're not gonna treat me like this. Forget it!" },
362 { actor
: logic
.player
, text
: "You'll not work here tomorrow." } ] ));
365 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "..." } ] ));
372 if (logic
.clara
.alive
) {
373 logic
.gameinterface
.dropNotice(this.shortname
+ ": Bye, John! Pass on my greetings to Saiki!");
378 logic
.closeDoor("cutedoor");
379 logic
.openDoor("carlosdoor");
380 return super.actionTake();
384 return (logic
.clara
.alive
) || (this.talkcount
< 3);
388 class NPC_Saiki
extends GameNPC
{
390 if (logic
.carlos
.alive
) {
391 switch (this.talkcount
) {
393 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "Hi Saiki!" },
394 { actor
: this, text
: "Hi John! Glad you arrived, here's some work for you!" },
395 { actor
: logic
.player
, text
: "Awesome! What is it?" },
396 { actor
: this, text
: "Haha, joking! Actually, our queue is suspiciously empty for today." },
397 { actor
: logic
.player
, text
: "Yeah... That's really suspicious!" },
398 { actor
: logic
.player
, text
: "Maybe I can get home today in time?" },
399 { actor
: this, text
: "You mean, you wouldn't spend the mandatory free extra working hours?" },
400 { 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?" },
401 { actor
: this, text
: "*Whispers with wink.* I hope you get my sarcasm." },
402 { actor
: logic
.player
, text
: "Haha! I always get it, Saiki!" } ] ));
403 logic
.closeDoor("carlosdoor");
404 logic
.openDoor("saikidoor");
407 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." },
408 { actor
: this, text
: "Clara has to enter people manually." },
409 { actor
: logic
.player
, text
: "Yeah, I'll definitely check that." } ] ));
412 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "So... what's up with the trash can?" },
413 { actor
: this, text
: "I'm always up for such deep conversation" },
414 { actor
: this, text
: "about trash cans." },
415 { 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." },
416 { 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." },
417 { actor
: logic
.player
, text
: "Hmm... Maybe it's too much to ask. Can we take one from another department?" },
418 { actor
: this, text
: "No, everyone holds on to their trash cans." },
419 { actor
: logic
.player
, text
: "You certainly did your research." },
420 { actor
: this, text
: "Of course. It's an important subject." } ] ));
423 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "My parents named me after a Japanese rock singer." },
424 { actor
: logic
.player
, text
: "Cool! Which band?" },
425 { 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." } ] ));
428 if ((logic
.carlos
.pigsemen
) && (this.talkcount
== 4)) {
429 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?" },
430 { actor
: this, text
: "Hmm..." },
431 { actor
: this, text
: "I guess it didn't work." },
432 { actor
: this, text
: "So do you want to know what I think about this?" },
433 { actor
: this, text
: "IT'S BRILLIANT!!!" },
434 { actor
: this, text
: "You know, it really sparkled my artistic vision! Now I must draw a pig with its legs rooted into the ground!" },
435 { actor
: logic
.player
, text
: "That's gross. Poor pig." },
436 { 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." },
437 { actor
: logic
.player
, text
: "You have a point." },
438 { 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." } ] ));
439 //this.offscreenTeleportation(new Phaser.Point(logic.carlos.x + 128, logic.carlos.y), this.tpdone);
442 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!" } ] ));
447 switch (this.talkcount
) {
449 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "I love you, Saiki!" },
450 { actor
: this, text
: "Hi Carlos..." },
451 { actor
: logic
.player
, text
: "I'm infatuated by the mere thought of you." },
452 { actor
: this, text
: "Well... it sounds pretty much creepy." },
453 { actor
: logic
.player
, text
: "Will you go out on a date with me?" },
454 { actor
: this, text
: "..." },
455 { actor
: this, text
: "Sorry to hurt your feelings, but... even though I like you... Your sudden, unprecedented confession makes me scared." },
456 { actor
: this, text
: "Especially with that facial expression." },
457 { actor
: this, text
: "I mean... you're not even joking." },
458 { actor
: this, text
: "So sorry... I won't date you." } ] ));
461 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "I thought I could impress you." },
462 { actor
: this, text
: "I'm sorry." } ] ));
465 logic
.gameinterface
.talk(new Dialogue( [ { actor
: logic
.player
, text
: "You will give me your card." },
466 { actor
: this, text
: "Geez, what for? Go back to your department and work!" },
467 { actor
: logic
.player
, text
: "I need it." },
468 { actor
: this, text
: "..." } ] ));
471 logic
.gameinterface
.talk(new Dialogue( [ { actor
: this, text
: "Don't you have anything better to do?" } ] ));
478 if (logic
.carlos
.alive
) {
479 logic
.gameinterface
.dropNotice(this.shortname
+ ": It was nice talking to you!");
484 logic
.closeDoor("carlosdoor");
485 logic
.openDoor("saikidoor");
486 return super.actionTake();
490 return (logic
.carlos
.alive
);
495 class GameInterface
extends Phaser
.Group
{
496 constructor(game
, parent
) {
497 super(game
, parent
, 'GUI', false, false, 0);
498 this.back_notice
= new Phaser
.Graphics(game
, 0, game
.height
- 50);
499 this.back_notice
.beginFill(0x000000);
500 this.back_notice
.drawRect(0, 0, game
.width
, 30);
501 this.back_notice
.endFill();
502 this.add(this.back_notice
);
503 this.text_notice
= new Phaser
.Text(game
, 0, this.back_notice
.y
, null, { align
: 'left', fill
: 'white', font
: 'Ubuntu Mono', fontSize
: 18, fontWeight
: 'bold' });
504 this.text_notice
.anchor
.setTo(-0.5, -0.2);
505 this.add(this.text_notice
);
508 this.back_menu
= new Phaser
.Graphics(game
, 150, (game
.height
/ 2) + 40);
509 this.back_menu
.beginFill(0x000000);
510 this.back_menu
.drawRect(0, 0, 155, 105);
511 this.back_menu
.endFill();
512 this.back_menu
.lineStyle(3, Phaser
.Color
.YELLOW
, 1);
513 this.back_menu
.moveTo(10, 35);
514 this.back_menu
.lineTo(this.back_menu
.width
- 10, 35);
515 this.add(this.back_menu
);
516 var style
= { align
: 'left', fill
: 'yellow', font
: 'Ubuntu Mono', fontSize
: 22, fontWeight
: 'bold' };
517 this.text_menutitle
= new Phaser
.Text(game
, this.back_menu
.x
, this.back_menu
.y
, null, style
);
518 this.text_menutitle
.anchor
.setTo(-0.2, -0.2);
519 style
= { align
: 'left', fill
: 'white', font
: 'Ubuntu Mono', fontSize
: 18, fontWeight
: 'bold' };
520 this.text_menuitem_Talk
= new Phaser
.Text(game
, this.back_menu
.x
+ 35, this.back_menu
.y
+ 40, "Talk", style
);
521 this.text_menuitem_Leave
= new Phaser
.Text(game
, this.back_menu
.x
+ 35, this.text_menuitem_Talk
.y
+ GUI_MENUITEM_DISTANCE
, "Leave", style
);
522 this.text_menuitem_Take
= new Phaser
.Text(game
, this.back_menu
.x
+ 35, this.text_menuitem_Leave
.y
+ GUI_MENUITEM_DISTANCE
, "Take ID", style
);
523 style
.fill
= 'yellow';
524 this.text_menucursor
= new Phaser
.Text(game
, this.back_menu
.x
+ 15, this.text_menuitem_Talk
.y
, "→", style
);
525 this.add(this.text_menutitle
);
526 this.add(this.text_menuitem_Talk
);
527 this.add(this.text_menuitem_Leave
);
528 this.add(this.text_menuitem_Take
);
529 this.add(this.text_menucursor
);
531 this.last_menustep
= 0;
533 this.back_talk
= new Phaser
.Graphics(game
, 100, game
.height
- 120);
534 this.back_talk
.beginFill(0x000000);
535 this.back_talk
.drawRect(0, 0, game
.width
- 200, 105);
536 this.back_talk
.endFill();
537 this.back_talk
.lineStyle(3, Phaser
.Color
.YELLOW
, 1);
538 this.back_talk
.moveTo(10, 35);
539 this.back_talk
.lineTo(this.back_talk
.width
- 10, 35);
540 this.add(this.back_talk
);
541 style
= { align
: 'left', fill
: 'yellow', font
: 'Ubuntu Mono', fontSize
: 22, fontWeight
: 'bold' };
542 this.text_talktitle
= new Phaser
.Text(game
, this.back_talk
.x
, this.back_talk
.y
, null, style
);
543 this.text_talktitle
.anchor
.setTo(-0.2, -0.2);
544 this.add(this.text_talktitle
);
545 this.strikethrough_talktitle
= new Phaser
.Graphics(game
, this.back_talk
.x
, this.back_talk
.y
);
546 this.strikethrough_talktitle
.lineStyle(3, Phaser
.Color
.RED
, 1);
547 this.strikethrough_talktitle
.moveTo(20, 20);
548 this.strikethrough_talktitle
.lineTo(75, 20);
549 this.add(this.strikethrough_talktitle
);
550 style
= { align
: 'left', fill
: 'white', font
: 'Ubuntu Mono', fontSize
: 18, fontWeight
: 'bold' };
551 this.text_talk
= new Phaser
.Text(game
, this.back_talk
.x
+ 35, this.back_talk
.y
+ 40, null, style
);
552 this.text_talk
.wordWrap
= true;
553 this.text_talk
.wordWrapWidth
= this.back_talk
.width
- 70;
554 this.text_talk
.lineSpacing
= -5;
555 this.add(this.text_talk
);
561 this.text_notice
.text
= text
;
562 this.back_notice
.visible
= true;
563 this.text_notice
.visible
= true;
567 this.back_notice
.visible
= false;
568 this.text_notice
.visible
= false;
575 this.text_menutitle
.text
= npc
.shortname
;
576 this.back_menu
.visible
= true;
577 this.text_menutitle
.visible
= true;
578 this.text_menuitem_Talk
.visible
= true;
579 this.text_menuitem_Leave
.visible
= true;
580 this.text_menuitem_Take
.visible
= true;
581 this.currentmenuitem
= MENUITEM_TALK
;
582 this.actualizeCursorPosition();
583 this.text_menucursor
.visible
= true;
584 this.last_menustep
= game
.time
.now
;
589 this.back_menu
.visible
= false;
590 this.text_menutitle
.visible
= false;
591 this.text_menuitem_Talk
.visible
= false;
592 this.text_menuitem_Leave
.visible
= false;
593 this.text_menuitem_Take
.visible
= false;
594 this.text_menucursor
.visible
= false;
600 this.dialogue
= dialogue
;
602 this.back_talk
.visible
= true;
603 this.text_talktitle
.visible
= true;
604 this.text_talk
.visible
= true;
609 this.dialogue
= null;
610 this.back_talk
.visible
= false;
611 this.text_talktitle
.visible
= false;
612 this.strikethrough_talktitle
.visible
= false;
613 this.text_talk
.visible
= false;
617 console
.log(this.dialogue
);
618 console
.log(this.dialogue
.actual());
619 var actualdialogue
= this.dialogue
.actual();
620 if (actualdialogue
) {
621 if (actualdialogue
.actor
.disguise
) {
622 this.text_talktitle
.text
= actualdialogue
.actor
.shortname
+ " " + actualdialogue
.actor
.disguise
.shortname
;
623 this.strikethrough_talktitle
.visible
= true;
626 this.text_talktitle
.text
= actualdialogue
.actor
.shortname
;
627 this.strikethrough_talktitle
.visible
= false;
629 this.text_talk
.text
= actualdialogue
.text
;
630 this.dialogue
.advance();
636 this.last_talk
= game
.time
.now
;
639 actualizeCursorPosition() {
640 this.text_menucursor
.y
= this.text_menuitem_Talk
.y
+ (this.currentmenuitem
* GUI_MENUITEM_DISTANCE
);
644 if ((this.inMenu
) && (hasTimePassed(this.last_menustep
, WAIT_MENUSTEP
))) {
645 if (cursors
.up
.isDown
)
647 this.currentmenuitem
--;
648 if (this.currentmenuitem
< MENUITEM_TALK
) this.currentmenuitem
= MENUITEM_TAKE
;
649 this.actualizeCursorPosition();
651 else if (cursors
.down
.isDown
)
653 this.currentmenuitem
++;
654 if (this.currentmenuitem
> MENUITEM_TAKE
) this.currentmenuitem
= MENUITEM_TALK
;
655 this.actualizeCursorPosition();
657 if (game
.input
.keyboard
.isDown(Phaser
.Keyboard
.ENTER
)) {
658 logic
.callMenu(this.currentmenuitem
);
660 this.last_menustep
= game
.time
.now
;
662 if ((this.inTalk
) && (game
.input
.keyboard
.isDown(Phaser
.Keyboard
.ENTER
)) && (hasTimePassed(this.last_talk
, WAIT_TALK
))) {
671 this.player
= this.clara
= this.carlos
= this.saiki
= this.peter
= this.bianca
= null;
672 this.gameinterface
= new GameInterface(game
, game
.stage
);
673 //this.doors = game.add.group(game.world, "doors");
674 this.last_menuselect
= 0;
677 createObject(object
) {
678 switch (object
.type
) {
679 case 'spawnpoint': this.createCharacter(object
); break;
680 case 'door': this.createDoor(object
); break;
681 case '': console
.error("Object type is empty:", object
); break;
682 default: console
.error("Unknown object type:", object
);
686 createCharacter(object
) {
688 switch (object
.name
) {
690 newChar
= new Player(object
.x
, object
.y
, 'player');
691 this.player
= newChar
;
692 this.player
.enablePhysics();
693 game
.camera
.follow(this.player
);
696 newChar
= new NPC_Clara(object
.x
, object
.y
, 'clara', "Clara", "Clara Tnavelerri", 200);
697 this.clara
= newChar
;
700 newChar
= new NPC_Carlos(object
.x
, object
.y
, 'carlos', "Carlos", "Carlos Elbacalper", 150);
701 this.carlos
= newChar
;
704 newChar
= new NPC_Saiki(object
.x
, object
.y
, 'saiki', "Saiki", "Saiki Ytpme", 200);
705 this.saiki
= newChar
;
708 console
.error("Unknown character:", object
);
710 newChar
.name
= object
.name
;
711 game
.add
.existing(newChar
);
712 console
.log(newChar
);
716 /* Calculate movement vector and correct position (32 = half tile width/height). */
718 switch (object.rotation) {
720 case 0: vector = new Phaser.Point( -1, 0); object.x += 32; object.y -= 32; break;
721 case 90: vector = new Phaser.Point( 0, -1); object.x += 32; object.y += 32; break;
722 case 180: vector = new Phaser.Point( 1, 0); object.x -= 32; object.y += 32; break;
723 case 270: vector = new Phaser.Point( 0, 1); object.x -= 32; object.y -= 32; break;
724 default: console.error("Invalid rotation:", object.rotation);
726 this.doors.add(new Door(object.x, object.y, object.name, object.rotation, vector, object.properties.longpanel));
730 console.log("Menu callback received:", menuitem);
731 this.last_menuselect = game.time.now;
732 this.gameinterface.leaveMenu();
735 this.player.interactablenpc.actionTalk();
738 this.player.interactablenpc.actionLeave();
739 this.player.unfreeze();
742 if (this.player.interactablenpc.actionTake())
743 this.player.unfreeze();
749 if (this.player.interactablenpc) {
750 if (this.player.interactablenpc.endTalk()) {
751 this.gameinterface.npcMenu(this.player.interactablenpc);
754 this.player.unfreeze();
755 this.last_menuselect = game.time.now;
761 this.doors.children.forEach(function(o) { if (o.name == doorname) o.open(); });
764 closeDoor(doorname) {
765 this.doors.children.forEach(function(o) { if (o.name == doorname) o.close(); });
769 if ((game.input.keyboard.isDown(Phaser.Keyboard.ENTER)) && (hasTimePassed(this.last_menuselect, WAIT_MENUSTEP))) {
770 if ((this.player.interactablenpc) && (this.player.interactablenpc.interactable) && (!this.gameinterface.inMenu) && (!this.gameinterface.inTalk)) {
771 console.log("Starting interaction with", this.player.interactablenpc.fullname);
772 this.player.freeze();
773 this.gameinterface.npcMenu(this.player.interactablenpc);
780 class GamePlay extends Phaser.State {
785 logic = new GameLogic();
786 game.world.updateOnlyExistingChildren = true;
787 //game.state.add('GameOver', GameOver, false);
793 game.load.image('player', 'john.png');
794 game.load.image('clara', 'clara.png');
795 game.load.image('carlos', 'carlos.png');
796 game.load.image('saiki', 'saiki.png');
797 game.load.image('tileset', 'tileset.png');
798 game.load.image('objects', 'objects.png');
799 game.load.tilemap('gamemap', 'tilemap.json', null, Phaser.Tilemap.TILED_JSON);
805 game.world.setBounds(0, 0, 800, 600);
806 game.stage.backgroundColor = '#000000';
807 game.physics.startSystem(Phaser.Physics.ARCADE);
808 console.log("Debug enabled:", !game.debug.isDisabled);
810 var map = game.add.tilemap('gamemap');
811 map.addTilesetImage('tileset', 'tileset');
812 map.addTilesetImage('objects', 'objects');
813 var layer_floor = map.createLayer('floor');
814 layer_floor.resizeWorld();
815 this.layer_walls = map.createLayer('walls');
816 map.setCollisionBetween(1, 100, true, this.layer_walls);
817 this.layer_furniture = map.createLayer('furniture');
818 map.setCollisionBetween(1, 100, true, this.layer_furniture);
820 // FIXME: Don't create a group here like this, it's too ugly! Now I have it here due to the display order.
821 logic.doors = game.add.group(game.world, "doors");
823 map.objects['objects'].forEach(function(o) { logic.createObject(o); });
824 console.log(map.objects);
826 cursors = game.input.keyboard.createCursorKeys();
833 game.physics.arcade.collide(logic.player, this.layer_walls);
834 game.physics.arcade.collide(logic.player, this.layer_furniture);
835 game.physics.arcade.collide(logic.player, logic.doors);