123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- function World() {
- this.game = null;
- this.system = null;
- this.player = null;
- this.mouse = null;
- this.characters = [];
- this.places = [];
- this.camera = null;
- this.background = null;
- this.dialog = null;
- this.curtain = null;
- this.isStarted = false;
- this.init = function(systemObject, canvas) {
- this.game = this;
- this.system = systemObject;
- this.mouse = new MouseInput();
- this.mouse.attach(canvas, this);
- this.camera = new Camera();
- this.camera.init(canvas);
- this.background = new Background(this.camera);
- this.background.init();
- this.player = new Player(this.game, new HumanController());
- this.player.id = 1;
- this.player.init();
- var brain = function(self) {
- if(self.targetPosition.x == self.position.x && self.targetPosition.x == 300) {
- self.waitHere = 300;
- self.targetPosition.x = 340;
- }
- if(self.targetPosition.x == self.position.x && self.targetPosition.x == 340) {
- self.waitHere = 300;
- self.targetPosition.x = 300;
- }
- };
- var newchar = new Character(this.game);
- newchar.id = 2;
- newchar.init(brain);
- this.characters.push(newchar);
- brain = function(self) {
- if(self.facingAngle == null) {
- self.facingAngle = 0;
- self.facingLimit = Math.PI / 2;
- self.facingDirection = Math.PI / 64;
- }
- self.facingAngle += self.facingDirection;
- if(self.facingDirection > 0 && self.facingAngle > self.facingLimit) {
- self.facingLimit = 0;
- self.facingDirection *= -1;
- self.waitHere = 300;
- }
- if(self.facingDirection < 0 && self.facingAngle < self.facingLimit) {
- self.facingLimit = Math.PI / 2;
- self.facingDirection *= -1;
- self.waitHere = 300;
- }
- self.targetAngle = self.facingAngle;
- self.angleRadians = self.facingAngle;
- /*if(self.facingAngle == Math.PI / 3 || self.facingAngle == null) {
- self.waitHere = 300;
- self.targetAngle = Math.PI / 4;
- self.angleRadians = Math.PI / 4;
- self.facingAngle = Math.PI / 4;
- }
- if(self.facingAngle == Math.PI / 4) {
- self.waitHere = 300;
- self.targetAngle = Math.PI / 3;
- self.angleRadians = Math.PI / 3;
- self.facingAngle = Math.PI / 3;
- }*/
- };
- newchar = new Character(this.game);
- newchar.id = 3;
- newchar.position.x = 540;
- newchar.position.y = 540;
- newchar.targetPosition.x = 540;
- newchar.targetPosition.y = 540;
- newchar.init(brain);
- this.characters.push(newchar);
- var newplace = new Place();
- newplace.init();
- this.places.push(newplace);
- this.dialog = new Dialog(this, this.camera);
- this.dialog.init(systemObject, canvas);
- this.ui = new HeadsUpDisplay(this.game, this.camera);
- this.ui.init(this.player, canvas);
- var stage = this;
- this.curtain = new Curtain();
- this.curtain.init(systemObject, canvas);
- this.curtain.open(700, function() {
- stage.isStarted = true;
- });
- };
- this.end = function() {
- this.mouse.detatch();
- }
- this.updateDelta = function(delta, canvas){
- if(system.keyboard.isDown(Keys.Escape)) {
- this.curtain.close(1000, function() {
- system.theater.changeStage("mainmenu");
- });
- }
- this.update(canvas);
- for(var index in this.places) {
- var place = this.places[index];
- place.update(delta);
- }
- this.player.update(delta);
- for(var index in this.characters) {
- var character = this.characters[index];
- character.update(delta);
- }
- this.dialog.update(delta);
- this.camera.update(canvas, this.player, delta);
- this.ui.update(delta);
- this.curtain.updateDelta(delta);
- };
- this.update = function(canvas) {
- this.player.control();
- this.background.update(canvas);
- if(this.player.position.x > 511 && this.player.position.x < 640 && this.player.position.y > 511 && this.player.position.y < 640 && this.player.trigger(1)) {
- var conversation = ["Hi! Welcome to grid 512:512, the hippest computer nightclub this quadrant!",
- "Oh, uh... hi. I'm here for some kind of party...",
- "Yes, the Bitwise convention. Right this way! Oh, and the wifi is free, just use the password 'l33tb0x'",
- "Y-yup! I will totally be connecting to that wifi, just like everyone, totally normal."
- ];
- var speakers = [1, 0, 1, 0];
- this.dialog.beginConversation(conversation, speakers);
- }
- if(this.player.position.x > 255 && this.player.position.x < 384 && this.player.position.y > 255 && this.player.position.y < 384 && this.player.trigger(0)) {
- var conversation = [
- "Now this is the story all about how my life got flipped, turned upside down and I'd like to take a minute just sit right there I'll tell you how I became the prince of a town called Bel-air.",
- "In west Philadelphia born and raised on the playground where I spent most of my days chilling out, maxing, relaxing all cool, and all shooting some b-ball outside of the school when a couple of guys, they were up to no good started making trouble in my neighbourhood I got in one little fight and my mom got scared and said \"You're moving with your auntie and uncle in Bel-air\"",
- "I whistled for a cab and when it came near the license plate said 'fresh' and had a dice in the mirror if anything I could say that this cab was rare but I thought nah, forget it, yo homes to Bel-air!",
- "I pulled up to a house about seven or eight and I yelled to the cabby \"Yo, homes smell you later!\" looked at my kingdom I was finally there to sit on my throne as the Prince of Bel-air.",
- "Is that some kind of pop-culture reference?"
- ];
- var speakers = [0,0,0,0,1];
- this.dialog.beginConversation(conversation, speakers);
- }
- };
- this.draw = function(context) {
- context.save();
- context.translate(this.camera.position.x, this.camera.position.y);
- this.background.draw(context);
- for(var index in this.places) {
- var place = this.places[index];
- place.draw(context);
- }
- for(var index in this.characters) {
- var character = this.characters[index];
- character.draw(context);
- }
- this.player.draw(context);
- context.restore();
- this.dialog.draw(context);
- this.ui.draw(context);
- this.curtain.draw(context);
- };
- this.handleResize = function(canvas) {
- this.camera.handleResize(canvas);
- }
- this.mouseMove = function(canvas, x, y) {
- this.player.controller.mouseMove(this.camera, x, y);
- };
- this.mouseDown = function(canvas, button, x, y) {
- if(!this.dialog.handleAdvance(button, x, y)) {
- this.player.controller.mouseDown(this.camera, button, x, y);
- }
- };
- this.mouseUp = function(canvas, button, x, y) {
- this.player.controller.mouseUp(this.camera, button, x, y);
- };
- this.touchStart = function(canvas, x, y) {
- if(!this.dialog.handleAdvance(null, x, y)) {
- this.player.controller.touchStart(this.camera, x, y);
- }
- };
- this.touchMove = function(canvas, x, y) {
- this.player.controller.touchMove(this.camera, x, y);
- };
- this.touchEnd = function(canvas, x, y) {
- this.player.controller.touchEnd(this.camera, x, y);
- };
- this.contextMenu = function(canvas, event) {
- this.player.controller.contextMenu(this.camera, event);
- };
- };
|