console.log("Hello");

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });

function preload() {
  game.load.image('ghost', '/ghost.png');
  game.load.image('person', '/person.png');
  game.load.image('star', '/star.png');
  game.load.image('platform', '/firstaid.png');
  game.load.image('diamond', '/diamond.png');
}

var characters = []; //Pacman + All Ghosts
var ghosts = []; //All Ghosts
var person; //Pacman
var ghost1, ghost2, ghost3, ghost4; //Individual Ghosts
var dots = []; //All Dots
var platforms;

var key1, key2, key3, key4;



function create() {

  game.physics.startSystem(Phaser.Physics.ARCADE);

  createBoard();
  createPerson();
  createGhosts();
  createHotkeys();
  createDots();

  //  Enable physics for sprites, make world boundaries.
  game.physics.arcade.enable(characters);
  game.physics.arcade.enable(dots);

  characters.forEach(function(character) { character.body.collideWorldBounds = true; });

  key1.onDown.add(function() { setUserControl(ghosts, 1) });
  key2.onDown.add(function() { setUserControl(ghosts, 2) });
  key3.onDown.add(function() { setUserControl(ghosts, 3) });
  key4.onDown.add(function() { setUserControl(ghosts, 4) });

} // End create()


function update() {

  game.physics.arcade.overlap(person, ghosts, loseLife, null, this);
  game.physics.arcade.overlap(person, dots, eatDot, null, this);

  characters.forEach(function(character) {
    if (character.userControl === true) {
      if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
        character.x -= 4;
        returnCoordinates(character);
      }
      else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
        character.x += 4;
        returnCoordinates(character);
      }
      else if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
        character.y -= 4;
        returnCoordinates(character);
      }
      else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
        character.y += 4;
        returnCoordinates(character);
      }
    }
  });

  // Ghost random
  // ghosts.forEach(function(item) {
  //     if (item.body.enable == false) {
  //       item.body.velocity.x = 100;
  //     }
  // });
}

function returnCoordinates(sprite) {
  var coordinates = [sprite.x, sprite.y];
  console.log(coordinates);
  return coordinates;
}

function gameOver () {
  // ghost eats pac OR checks to see if if .count equals 0
}

function loseLife (person, ghosts) {
  person.kill();
}

function eatDot (person, dots) {
  dots.kill();
}

@@ -562,16 +562,47 @@
 forms;%0A%0A
+var score = 0;%0Avar scoreText;%0A%0A
 var key1
@@ -621,16 +621,16 @@
 , key4;%0A
-
 %0A%0A%0Afunct
@@ -1257,16 +1257,122 @@
 4) %7D);%0A%0A
+  scoreText = game.add.text(32, 550, 'score: 0', %7B font: %2220px Arial%22, fill: %22#ffffff%22, align: %22left%22 %7D);%0A
 %7D // End
@@ -2427,16 +2427,18 @@
 e.y%5D;%0A  
+//
 console.
@@ -2655,16 +2655,16 @@
 dots) %7B%0A
-
   dots.k
@@ -2662,18 +2662,67 @@
 %0A  dots.kill();%0A
+  score++;%0A  scoreText.text = 'score: ' + score;%0A
 %7D%0A

add score