function Player() { this.speed = 1; // double this.x = 0; // int this.y = 0; // int this.state = "idle"; // string this.animation = ""; // object:animation this.level; // object:level this.alias = ""; // string this.dir = 0; // int } /* * Makes the player move in the specified * direction according to the player's * speed property **/ Player.prototype.move = function(dir) { // Do not allow the player to move // if it has an illegal state if (this.canMove() == false) return; switch (dir) { case 0: this.y -= 1 * this.speed; break; case 1: this.x -= 1 * this.speed; break; case 2: this.y += 1 * this.speed; break; case 3: this.x += 1 * this.speed; break; } } Player.prototype.canMove = function() { var illegalStates = [ "dead" ]; if (illegalStates.indexOf(this.getState()) > -1) { return false; } return true; } Player.prototype.getState = function() { return this.state; } Player.prototype.setState = function(state) { this.state = state; } Player.prototype.setLevel = function(level) { level.loadLevel(level); this.levelName = level; }