<commit_before>
var platformGroup;
var myId=0;
var ready = false;
var nextPlatformTimer = 0;
var gameStarted = false;
var eurecaServer;
var eClient;
var created = false;

var eurecaClientSetupGame = function() {
    eClient = eurecaClient;
    console.log("client",eClient);
    if(!created){
      createGame();
    }
    //methods defined under "exports" namespace become available in the server side

    //updates the state in the playerList of any player that has changed
    eurecaClient.exports.updateState = function(id, state){
      if (playerList[id])  {
          playerList[id].cursor = state;
          playerList[id].player.x = state.x;
          playerList[id].player.y = state.y;
          playerList[id].update();
      }
    }
    eurecaClient.exports.interact = function(action,args) {
      console.log(action)
      window[action](args);
    }
}

game.state.add('playgame', { preload: preload, create:eurecaClientSetupGame, update:update });
var platformX;
var cursorX;
var cursorY;
var maxPlatforms = 2;
var cameraScrollRate = .05;
var playerGravity = 350;
var leftButton;
var leftButtonDown = false;
var rightButton;
var rightButtonDown = false;
var currentPlatformType = "solid";

function preload () {
  game.load.image( 'platform', '/assets/basic_platform.png');
  game.load.spritesheet( 'player', '/assets/astrousa.png', 32, 64, 3);
  game.load.image( 'background', '/assets/space_race_bg_generic_320.jpg');
  game.load.image( 'leftButton', '/assets/LeftButton.png');
  game.load.image( 'rightButton', '/assets/RightButton.png');
  game.load.image( 'solidPlatform', '/assets/solid_platform.png');
  game.load.image( 'icePlatform', '/assets/ice_platform.png');
  game.load.image( 'bouncePlatform', '/assets/bounce_platform.png');
  game.load.image( 'spikePlatform', '/assets/spike_platform.png');
  game.load.image( 'stickyPlatform', '/assets/sticky_platform.png');
  game.load.image( 'holePlatform', '/assets/hole_platform.png');
}

Player = function(game) {
  this.cursors = {
      left:false,
      right:false,
      up:false,
      fire:false
  };

  this.input = {
      left:false,
      right:false,
      up:false,
      fire:false
  };

  this.game = game;
  this.self = game.add.sprite(130, 8800, 'player');
  game.physics.enable(this.self, Phaser.Physics.ARCADE);
  this.self.body.gravity.y = playerGravity;
};

Player.prototype.update = function() {
  var inputChanged = (
    this.cursor.left != this.input.left ||
    this.cursor.right != this.input.right ||
    this.cursor.up != this.input.up
  );

  if (inputChanged) {
    //Handle input change here
    //send new values to the server
    if (this.tank.id == myId) {
        // send latest valid state to the server
        this.input.x = this.tank.x;
        this.input.y = this.tank.y;

        console.log('send to the server');
    }
  }

  if (this.cursors.left.isDown || leftButtonDown) {
    this.self.body.velocity.x = -150
  } else if (this.cursors.right.isDown || rightButtonDown) {
    this.self.body.velocity.x = 150;
  } else {
    this.self.body.velocity.x = 0;
  }

  if (cursors.up.isDown && player.body.touching.down) {
    player.body.velocity.y = -300;
    gameStarted = true;
  }
  console.log("this bitch be updated")

};

function createGame () {
  eurecaServer.playerHandshake();
  role = eurecaServer.getRole(function() {
    role = role.result
    console.log(role)
  });

  game.physics.startSystem(Phaser.Physics.ARCADE);
  game.world.setBounds(0, 0, 320, 9000);

  game.background = game.add.sprite(0, -400, 'background');

  game.background.inputEnabled = true;
  //game.background.events.onInputDown.add(setPlatform, this);
  game.background.events.onInputDown.add(sendPlatform,this);

  startingSpace = game.add.sprite(110, 8880, 'platform');
  game.physics.enable(startingSpace, Phaser.Physics.ARCADE);
  startingSpace.body.immovable = true;



  player = new Player(game);
  player = player.self;
  player.id = myId;
  player.animations.add('left', [0]);
  player.animations.add('right', [1]);
  player.animations.add('front', [2]);

  // leftButton = game.add.sprite(10, 410, 'leftButton');
  // leftButton.fixedToCamera = true;
  // leftButton.inputEnabled = true;
  // leftButton.events.onInputDown.add(movePlayerLeft, this);
  // leftButton.events.onInputUp.add(leftButtonUp, this);
  // rightButton = game.add.sprite(260, 410, 'rightButton');
  // rightButton.fixedToCamera = true;
  // rightButton.inputEnabled = true;
  // rightButton.events.onInputDown.add(movePlayerRight, this);
  // rightButton.events.onInputUp.add(rightButtonUp, this);<commit_msg>accept id as arg in player constructor<commit_after>
var platformGroup;
var ready = false;
var nextPlatformTimer = 0;
var gameStarted = false;
var eurecaServer;
var eClient;
var created = false;

var eurecaClientSetupGame = function() {
    eClient = eurecaClient;
    console.log("client",eClient);
    if(!created){
      createGame();
    }
    //methods defined under "exports" namespace become available in the server side

    //updates the state in the playerList of any player that has changed
    eurecaClient.exports.updateState = function(id, state){
      if (playerList[id])  {
          playerList[id].cursor = state;
          playerList[id].player.x = state.x;
          playerList[id].player.y = state.y;
          playerList[id].update();
      }
    }
    eurecaClient.exports.interact = function(action,args) {
      console.log(action)
      window[action](args);
    }
}

game.state.add('playgame', { preload: preload, create:eurecaClientSetupGame, update:update });
var platformX;
var cursorX;
var cursorY;
var maxPlatforms = 2;
var cameraScrollRate = .05;
var playerGravity = 350;
var leftButton;
var leftButtonDown = false;
var rightButton;
var rightButtonDown = false;
var currentPlatformType = "solid";

function preload () {
  game.load.image( 'platform', '/assets/basic_platform.png');
  game.load.spritesheet( 'player', '/assets/astrousa.png', 32, 64, 3);
  game.load.image( 'background', '/assets/space_race_bg_generic_320.jpg');
  game.load.image( 'leftButton', '/assets/LeftButton.png');
  game.load.image( 'rightButton', '/assets/RightButton.png');
  game.load.image( 'solidPlatform', '/assets/solid_platform.png');
  game.load.image( 'icePlatform', '/assets/ice_platform.png');
  game.load.image( 'bouncePlatform', '/assets/bounce_platform.png');
  game.load.image( 'spikePlatform', '/assets/spike_platform.png');
  game.load.image( 'stickyPlatform', '/assets/sticky_platform.png');
  game.load.image( 'holePlatform', '/assets/hole_platform.png');
}

Player = function(game, id) {
  this.cursors = {
      left:false,
      right:false,
      up:false,
      fire:false
  };

  this.input = {
      left:false,
      right:false,
      up:false,
      fire:false
  };

  this.game = game;
  this.self = game.add.sprite(130, 8800, 'player');
  game.physics.enable(this.self, Phaser.Physics.ARCADE);
  this.self.body.gravity.y = playerGravity;
  this.self.id = id;
};

Player.prototype.update = function() {
  var inputChanged = (
    this.cursor.left != this.input.left ||
    this.cursor.right != this.input.right ||
    this.cursor.up != this.input.up
  );

  if (inputChanged) {
    //Handle input change here
    //send new values to the server
    if (this.tank.id == myId) {
        // send latest valid state to the server
        this.input.x = this.tank.x;
        this.input.y = this.tank.y;

        console.log('send to the server');
    }
  }

  if (this.cursors.left.isDown || leftButtonDown) {
    this.self.body.velocity.x = -150
  } else if (this.cursors.right.isDown || rightButtonDown) {
    this.self.body.velocity.x = 150;
  } else {
    this.self.body.velocity.x = 0;
  }

  if (cursors.up.isDown && player.body.touching.down) {
    player.body.velocity.y = -300;
    gameStarted = true;
  }
  console.log("this bitch be updated")

};

function createGame () {
  eurecaServer.playerHandshake();
  role = eurecaServer.getRole(function() {
    role = role.result
    console.log(role)
  });

  game.physics.startSystem(Phaser.Physics.ARCADE);
  game.world.setBounds(0, 0, 320, 9000);

  game.background = game.add.sprite(0, -400, 'background');

  game.background.inputEnabled = true;
  //game.background.events.onInputDown.add(setPlatform, this);
  game.background.events.onInputDown.add(sendPlatform,this);

  startingSpace = game.add.sprite(110, 8880, 'platform');
  game.physics.enable(startingSpace, Phaser.Physics.ARCADE);
  startingSpace.body.immovable = true;



  player = new Player(game, myId);
  player = player.self;
  player.animations.add('left', [0]);
  player.animations.add('right', [1]);
  player.animations.add('front', [2]);

  // leftButton = game.add.sprite(10, 410, 'leftButton');
  // leftButton.fixedToCamera = true;
  // leftButton.inputEnabled = true;
  // leftButton.events.onInputDown.add(movePlayerLeft, this);
  // leftButton.events.onInputUp.add(leftButtonUp, this);
  // rightButton = game.add.sprite(260, 410, 'rightButton');
  // rightButton.fixedToCamera = true;
  // rightButton.inputEnabled = true;
  // rightButton.events.onInputDown.add(movePlayerRight, this);
  // rightButton.events.onInputUp.add(rightButtonUp, this);
{'fraction_non_alphanumeric': 0.14935911362155116, 'fraction_numerical': 0.014447099717575494, 'mean_word_length': 3.513235294117647, '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': '2924153', 'n_tokens_mistral': 3212, 'n_tokens_neox': 3057, 'n_words': 591}