<commit_before>/*
* Player constructor
* 
* @class Roguelike.Player
* @classdesc A player object that creates his own layout!
*
* @property {Roguelike.Game} game - Reference to the current game object
* @param {object} position - The x and y coordinate of this player, in tiles
*/
Roguelike.Player = function(game, position){

    /*
    * @property {Roguelike.Game} game - Reference to the current game object
    */
    this.game = game;

    /*
    * @property {object} position - The x and y coordinate of this player, in tiles
    */
    this.position = Object.create(position);

    /*
    * @property {int} speed - The speed of the player, in tiles
    */
    this.speed = 1;

};

Roguelike.Player.prototype = {

    /*
    * The function that get's called on a keypress
    * @protected
    */
    move: function(){

        //Check which controls are being pressed and update the player accordingly
        if(this.game.controls.left && this.game.map.tiles[this.position.y][this.position.x - this.speed].type === 2){
            this.position.x -= this.speed;
        }else if(this.game.controls.up && this.game.map.tiles[this.position.y - this.speed][this.position.x].type === 2){
            this.position.y -= this.speed;
        }else if(this.game.controls.right && this.game.map.tiles[this.position.y][this.position.x + this.speed].type === 2){
            this.position.x += this.speed;
        }else if(this.game.controls.down && this.game.map.tiles[this.position.y + this.speed][this.position.x].type === 2){
            this.position.y += this.speed;
        }

        //Update the game when the player moves
        this.game.update();

    }

};<commit_msg>Added a self initializing function to the player.<commit_after>/*
* Player constructor
* 
* @class Roguelike.Player
* @classdesc A player object that creates his own layout!
*
* @property {Roguelike.Game} game - Reference to the current game object
* @param {object} position - The x and y coordinate of this player, in tiles
*/
Roguelike.Player = function(game, position){

    /*
    * @property {Roguelike.Game} game - Reference to the current game object
    */
    this.game = game;

    /*
    * @property {object} position - The x and y coordinate of this player, in tiles
    */
    this.position = Object.create(position);

    /*
    * @property {int} speed - The speed of the player, in tiles
    */
    this.speed = 1;

    //Initialize itself
    this.initialize();

};

Roguelike.Player.prototype = {

    /*
    * Initialize the player object, set the controls
    * @protected
    */
    initialize: function(){

        //Add up key and tell it to move the player up when it hits
        this.game.keyboard.addKey(38);

    },

    /*
    * The function that get's called on a keypress
    * @protected
    */
    move: function(){

        //Check which controls are being pressed and update the player accordingly
        if(this.game.controls.left && this.game.map.tiles[this.position.y][this.position.x - this.speed].type === 2){
            this.position.x -= this.speed;
        }else if(this.game.controls.up && this.game.map.tiles[this.position.y - this.speed][this.position.x].type === 2){
            this.position.y -= this.speed;
        }else if(this.game.controls.right && this.game.map.tiles[this.position.y][this.position.x + this.speed].type === 2){
            this.position.x += this.speed;
        }else if(this.game.controls.down && this.game.map.tiles[this.position.y + this.speed][this.position.x].type === 2){
            this.position.y += this.speed;
        }

        //Update the game when the player moves
        this.game.update();

    }

};
{'fraction_non_alphanumeric': 0.13545925320250748, 'fraction_numerical': 0.003270645952575634, 'mean_word_length': 2.475378787878788, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4791158', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1088, 'n_words': 305}