// Definition of all the constants of the game: // Keys: var KEY_LEFT = 37; var KEY_UP = 38; var KEY_RIGHT = 39; var KEY_DOWN = 40; var KEY_SHIFT = 16; var KEY_ALT = 18; var KEY_SPACE = 32; var KEY_ENTER = 13; var KEY_ESC = 27; var KEY_SPELLS = [68,69,70,71,72,73,74,75,76]; // letters from from 'd' to 'l' var KEY_ITEMS = [49,50,51,52,53,54,55,56]; // numbers from 1 to 8 var KEY_EQUIPPED_ITEMS = [65,66,67] // a,b,c var KEY_TALK = 84 // t var KEY_DROP_GOLD = 82; // r var KEY_CHANGE_CHARACTER = 78; // n var KEY_ZOOM = 90; // z // Direction: var DIRECTION_NONE = -1; var DIRECTION_UP = 0; var DIRECTION_RIGHT = 1; var DIRECTION_DOWN = 2; var DIRECTION_LEFT = 3; var direction_offx = [0,1,0,-1]; var direction_offy = [-1,0,1,0]; var opposite_direction = [2,3,0,1]; // Character actions and states: var ACTION_NONE = 0; var ACTION_MOVE = 1; var ACTION_TAKE = 2; var ACTION_DROP = 3; var ACTION_DROP_GOLD = 4; var ACTION_USE = 5; var ACTION_UNEQUIP = 6; var ACTION_ATTACK = 7; var ACTION_INTERACT = 8; // chop trees, open doors, etc. var ACTION_TALK = 9; var ACTION_TALK_ANGRY = 10; var ACTION_SPELL = 11; var STATE_READY = 0; var STATE_MOVING = 1; var STATE_ATTACKING = 2; var STATE_INTERACTING = 3; var STATE_CASTING = 4; var STATE_VEHICLE_READY = 5; var STATE_VEHICLE_MOVING = 6; var STATE_DEATH = 7; var STATE_TALKING = 1; // only for talk_state // Animations: // these are suffixes to add to the animations below: var ANIM_DIRECTIONS = ["-up","-right","-down","-left"]; // indexed by DIRECTON_UP, DIRECTION_RIGHT, ... var ANIM_IDLE = "idle"; var ANIM_MOVING = "moving"; var ANIM_ATTACKING = "attacking"; var ANIM_INTERACTING = "interacting"; var ANIM_CASTING = "casting"; var ANIM_TALKING = "talking"; var ANIM_DEATH = "death"; // Events: var EVENT_USE = "use"; // when an object is used, or a lever is activated/deactivated var EVENT_ACTIVATE = "activate"; // when a character moves a lever to the "on" position var EVENT_DEACTIVATE = "deactivate"; // when a character moves a lever to the "off" position var EVENT_PICKUP = "pickup"; // when a character picks up an object var EVENT_OPEN = "open"; // when a door or a chest is open var EVENT_CLOSE = "close"; // when a door is closed var EVENT_PUSH = "push"; // when a pushable wall block is pushed var EVENT_PRESS = "press"; // when an item/character is placed over a pressure plate var EVENT_CHARACTERPRESS = "characterpress"; // when a character moves onto a pressure plate var EVENT_PLAYERPRESS = "playerpress"; // when a player moves onto a pressure plate var EVENT_TIMER = "timer"; // used to program timers // Spells: var SPELL_MAGIC_MISSILE = "magic missile"; var SPELL_HEAL = "heal"; var SPELL_SHIELD = "shield"; var SPELL_INCREASE = "increase"; var SPELL_DECREASE = "decrease"; var SPELL_FIREBALL = "fireball"; var SPELL_MAGIC_EYE = "magic eye"; var SPELL_REGENERATE = "regenerate"; var SPELL_INCINERATE = "incinerate"; var spell_cost = {}; spell_cost[SPELL_MAGIC_MISSILE] = 1; spell_cost[SPELL_HEAL] = 1; spell_cost[SPELL_SHIELD] = 2; spell_cost[SPELL_INCREASE] = 2; spell_cost[SPELL_DECREASE] = 2; spell_cost[SPELL_FIREBALL] = 4; spell_cost[SPELL_MAGIC_EYE] = 4; spell_cost[SPELL_REGENERATE] = 4; spell_cost[SPELL_INCINERATE] = 8; // Inventory: var ITEM_WEAPON = 0; var ITEM_OFF_HAND = 1; var ITEM_RING = 2; var INVENTORY_SIZE = 8; // Conversation constants: var TALK_HI = "hi"; var TALK_BYE = "bye"; //var TALK_YES = "yes"; //var TALK_NO = "no"; var TALK_TRADE = "trade/give"; var TALK_ASK = "ask"; // Screen configuration: var HUD_WIDTH = 176; // size of the side bar var HUD_HEIGHT = 64; // size of the message window var TILE_WIDTH_ORIGINAL = 64; var TILE_HEIGHT_ORIGINAL = 64; var TILE_WIDTH = 64; var TILE_HEIGHT = 64; var TARGET_TILE_WIDTH = 64; var TARGET_TILE_HEIGHT = 64; // animations for basic objects: var COINPURSE_ANIMATION = "coinpurse"; var STATUS_CURIOUS_ANIMATION = "curious"; var STATUS_SCARED_ANIMATION = "scared"; var STATUS_ANGRY_ANIMATION = "angry"; var STATUS_TIRED_ANIMATION = "tired"; var STATUS_HAPPY_ANIMATION = "happy"; // Game states: var GAMESTATE_TITLE = 0; var GAMESTATE_GAME = 1; var GAMESTATE_INSTRUCTIONS = 2; var GAMESTATE_ENDING = 4; var AI_DEBUGGER_FOCUS = null; // Create the game: var Game = { cycle : 0, // cycles of actual game play (Reset each time a game restarts) state : 0, state_cycle : 0, paused : false, }; window.theA4Game = Game; Game.loadCharacters = function(xmlFilePath) { window.theA4Game = this; var xmlhttp=new XMLHttpRequest(); xmlhttp.overrideMimeType("text/xml"); xmlhttp.open("GET",xmlFilePath,false); xmlhttp.send(); var xmlDoc=xmlhttp.responseXML; var topElement = xmlDoc.documentElement; var characterTypeElements = topElement.getElementsByTagName("CharacterClass"); for(var i = 0;i0) { this.titleIMG_bg = new Image(); this.titleIMG_bg.src = gamepath + gameElement.getElementsByTagName("titleImage")[0].textContent; } // load game story: this.story = []; var storyElements = gameElement.getElementsByTagName("story")[0].getElementsByTagName("line"); for(var i = 0;iTARGET_TILE_HEIGHT) { TILE_HEIGHT--; TILE_WIDTH = TILE_HEIGHT; } }; Game.pushMessage = function(msg) { if (this.messages.length>0 && this.messages[this.messages.length-1][1] == msg) { this.messages[this.messages.length-1][0] = (new Date).getTime(); } else { this.messages.push([(new Date).getTime(),msg]); if (this.messages.length>4) { this.messages.splice(0,1); } } } Game.warpObject = function(object, x, y, map, layer) { old_map = this.maps[object.map]; new_map = this.maps[map]; // record the WARP for the perception module of the character AI: old_map.warps.push({x:object.x, y:object.y, object: object, timer: 200}); old_map.removeObject(object); new_map.addObject(object,layer); object.x = x; object.y = y; object.map = map; } // 'topic' should be a list of two elements, something like: ["monks","There is a massive amount of monks in the Black rock!"] Game.addConversationTopic = function(topic) { for(var i=0;i