123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- include("mouseinput.js");
- include("camera.js");
- include("background.js");
- include("player.js");
- include("place.js");
- include("dialog.js");
- include("headsupdisplay.js");
- include("curtain.js");
- include("mobile.js");
- include("item.js");
- function World() {
- this.game = null;
- this.system = null;
- this.player = null;
- this.mouse = null;
- this.mobiles = [];
- this.places = [];
- this.items = [];
- this.camera = null;
- this.background = null;
- this.dialog = null;
- this.curtain = null;
- this.isStarted = false;
- this.displayItemNames = false;
- this.init = function(systemObject, canvas) {
- this.game = this;
- this.system = systemObject;
- this.mobiles = [];
- this.items = [];
- this.places = [];
- system.assets.buildSprite("human1", "charsprite", {x:0, y:0}, {width: 16, height: 16});
- system.assets.buildSprite("human2", "charsprite", {x:0, y:17}, {width: 16, height: 16});
- system.assets.buildSprite("human3", "charsprite", {x:0, y:34}, {width: 16, height: 16});
- system.assets.buildSprite("orc", "charsprite", {x:0, y:51}, {width: 16, height: 16});
-
- system.assets.buildSprite("woman1", "charsprite", {x:0, y:86}, {width: 16, height: 16});
- system.assets.buildSprite("woman2", "charsprite", {x:17, y:86}, {width: 16, height: 16});
- system.assets.buildSprite("man1", "charsprite", {x:0, y:102}, {width: 16, height: 16});
- system.assets.buildSprite("man2", "charsprite", {x:17, y:102}, {width: 16, height: 16});
- system.assets.buildSprite("woman3", "charsprite", {x:0, y:119}, {width: 16, height: 16});
- system.assets.buildSprite("woman4", "charsprite", {x:17, y:119}, {width: 16, height: 16});
- system.assets.buildSprite("man3", "charsprite", {x:0, y:136}, {width: 16, height: 16});
- system.assets.buildSprite("man4", "charsprite", {x:17, y:136}, {width: 16, height: 16});
- system.assets.buildSprite("knight", "charsprite", {x:0, y:187}, {width: 16, height: 16});
- system.assets.buildSprite("grass1", "mapsprite", {x:85, y:0}, {width: 16, height: 16});
- system.assets.buildSprite("grass2", "mapsprite", {x:85, y:17}, {width: 16, height: 16});
- system.assets.buildSprite("grass3", "mapsprite", {x:51, y:272}, {width: 16, height: 16});
- system.assets.buildSprite("food1", "mapsprite", {x:919, y:257}, {width: 16, height: 16});
- this.mouse = new MouseInput();
- this.mouse.attach(canvas, this);
- canvas.style.cursor = "default";
- this.camera = new Camera();
- this.camera.init(canvas);
- this.background = new Background(this.camera);
- this.background.init();
- this.player = new Player(this.game, this.camera);
- this.player.init();
- /*var newplace = new Place();
- newplace.init();
- this.places.push(newplace);*/
- this.dialog = new Dialog(this, this.camera, this.player);
- 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;
- setInterval(function(){
- system.theater.socketSend({action: "tick"});
- }, 300);
- });
- this.handleResize(canvas);
- };
- this.end = function(callback) {
- this.mouse.detatch();
- system.theater.socketDisconnect();
- this.ui.clearChat();
- this.closeCurtain(callback);
- }
- this.closeCurtain = function(callback) {
- system.theater.stage.curtain.close(700, function() {
- callback();
- });
- }
- this.updateDelta = function(delta, canvas){
- for(var index in this.places) {
- var place = this.places[index];
- place.update(delta);
- }
- this.player.update(delta);
- for(var index in this.mobiles) {
- this.mobiles[index].update(delta);
- }
- this.dialog.update(delta);
- this.camera.update(canvas, this.player, delta);
- this.ui.update(delta);
- this.update(canvas);
- this.curtain.updateDelta(delta);
- };
- this.update = function(canvas) {
- this.background.update(canvas);
- if(system.keyboard.isPressed(Keys.F1)) {
- system.theater.changeStage("mainmenu");
- }
- if(system.keyboard.isPressed(Keys.Alt)) {
- this.displayItemNames = true;
- }
- if(system.keyboard.isReleased(Keys.Alt)) {
- this.displayItemNames = false;
- }
- if(system.keyboard.isPressed(Keys.I)) {
- this.ui.showInventory();
- }
- /*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.player.control();
- };
- 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.items) {
- var item = this.items[index];
- item.draw(context);
- }
- for(var index in this.mobiles) {
- var mobile = this.mobiles[index];
- mobile.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.ui.handleResize(canvas);
- }
- this.mouseMove = function(canvas, x, y) {
- this.player.mouseMove(this.camera, x, y);
- this.ui.mouseMove(canvas, x, y);
- };
- this.mouseDown = function(canvas, button, x, y) {
- if(!this.dialog.handleAdvance(button, x, y)) {
- this.player.mouseDown(this.camera, button, x, y);
- }
- this.ui.mouseDown(canvas, button, x, y);
- };
- this.mouseUp = function(canvas, button, x, y) {
- this.player.mouseUp(this.camera, button, x, y);
- this.ui.mouseUp(canvas, button, x, y);
- };
- this.touchStart = function(canvas, x, y) {
- if(!this.dialog.handleAdvance(null, x, y)) {
- this.player.touchStart(this.camera, x, y);
- }
- this.ui.touchStart(canvas, x, y);
- };
- this.touchMove = function(canvas, x, y) {
- this.player.touchMove(this.camera, x, y);
- this.ui.touchMove(canvas, x, y);
- };
- this.touchEnd = function(canvas, x, y) {
- this.player.touchEnd(this.camera, x, y);
- this.ui.touchEnd(canvas, x, y);
- };
- this.contextMenu = function(canvas, event) {
- this.player.contextMenu(this.camera, event);
- };
- this.handleServerMessage = function(event) {
- switch(event.action) {
- case "chat":
- this.ui.receivedChatMessage(event.data.mobileid, event.data.message);
- break;
- case "connect":
- this.player.id = event.playerid;
- for(var index in event.update.mobiles) {
- var player = event.update.mobiles[index];
- if(player.id == event.playerid) {
- for(var key in player){
- if(!this.player.hasOwnProperty(key)) { continue; }
- this.player[key] = player[key];
- }
- }
- }
- break;
- case "tickresponse":
- var mobiles = event.data.mobiles;
- var activeMobiles = [];
- for(var index in mobiles) {
- if(this.player.id == mobiles[index].id) { continue; }
- var mobile = this.getMobileById(mobiles[index].id);
- if(mobile == null) {
- mobile = new Mobile(this);
- }
- mobile.init(mobiles[index]);
- activeMobiles.push(mobile);
- }
- this.mobiles = activeMobiles;
- var items = event.data.items;
- var activeItems = [];
- for(var index in items) {
- var item = this.getItemById(items[index].id);
- if(item == null) {
- item = new Item(this);
- }
- item.init(items[index]);
- activeItems.push(item);
- }
- this.items = activeItems;
- var places = event.data.places;
- var activePlaces = [];
- for(var index in places) {
- var place = this.getPlaceById(places[index].id);
- if(place == null) {
- place = new Place(this);
- }
- place.init(places[index]);
- activePlaces.push(place);
- }
- this.places = activePlaces;
- break;
- default:
- console.warn("Unhandled event:", event);
- break;
- }
- }
- this.getMobileById = function(mobileId) {
- for(var mobileIndex in this.mobiles) {
- if(mobileId == this.mobiles[mobileIndex].id) {
- return this.mobiles[mobileIndex];
- }
- }
- }
- this.getItemById = function(itemId) {
- for(var itemIndex in this.items) {
- if(itemId == this.items[itemIndex].id) {
- return this.items[itemIndex];
- }
- }
- }
- this.getPlaceById = function(placeId) {
- for(var placeIndex in this.places) {
- if(placeId == this.places[placeIndex].id) {
- return this.places[placeIndex];
- }
- }
- }
- };
|