/*
 * Game state
 * ==========
 *
 * Experimenting with parallax backgrounds.
 */

import BgLayer from '../objects/BgLayer';
import Ground from '../objects/prefabs/scenery/Ground';
import AvocadoSmasher from '../objects/AvocadoSmasher';

export default class Game extends Phaser.State {

  create () {
    this.world.setBounds(0, 0, 2000, 640);

    this.game.physics.startSystem(Phaser.Physics.ARCADE);
    this.game.physics.arcade.gravity.y = 300;

    this.groups = {};
    this.groups['level'] = this.game.add.group();
    this.groups['players'] = this.game.add.group();

    this.prefabs = {
      'bg-sky':          new BgLayer(this.game, 0, 0, 2000,  304, 'bg-layer-sky', 0.1),
      'bg-layer-sea':    new BgLayer(this.game, 0, 304, 2000,  96, 'bg-layer-sea', 0.2),
      'level-grass':     new Ground(this, {x: 10, y: 380}, {width: 2000, height: 22}),
      'avocado-smasher': new AvocadoSmasher(this, {x: 100, y: 290}, {group: 'players'})
    };

    this.add.existing(this.prefabs['bg-sky']);
    this.add.existing(this.prefabs['bg-layer-sea']);
    this.add.existing(this.prefabs['level-grass']);
    this.add.existing(this.prefabs['avocado-smasher']);

    this.camera.follow(this.prefabs['avocado-smasher']);
  }

  update() {
    // Handle player colliding with a ground tile
    this.game.physics.arcade.collide(this.prefabs['avocado-smasher'], this.prefabs['level-grass'], Ground.collide);
  }

  render () {
    if (this.game.DEBUG) {
      this.game.debug.text(' vx: ' + this.prefabs['avocado-smasher'].body.velocity.x + '  vy: ' + this.prefabs['avocado-smasher'].body.velocity.y, 16, 16);
      this.game.debug.text('onFloor: ' + this.prefabs['avocado-smasher'].body.onFloor() + ' jumpCounter: ' + this.prefabs['avocado-smasher'].jumpCounter, 16, 32);
      this.game.debug.cameraInfo(this.camera, 16, 54);
    }
  }
}

@@ -483,21 +483,26 @@
 groups%5B'
-level
+background
 '%5D = thi
@@ -538,23 +538,22 @@
 groups%5B'
-players
+ground
 '%5D = thi
@@ -572,17 +572,16 @@
 roup();%0A
-%0A
     this
@@ -585,45 +585,115 @@
 his.
+groups%5B'
 prefabs
+'%5D
  = 
-%7B%0A      'bg-sky':          
+this.game.add.group();%0A%0A    // Add background layers%0A    this.groups%5B'background'%5D.add(
 new 
@@ -753,35 +753,45 @@
 0.1)
-,
+);
 %0A    
-  'bg-layer-sea':    
+this.groups%5B'background'%5D.add(
 new 
@@ -852,31 +852,76 @@
 0.2)
-,
+);%0A
 %0A    
-  'level-grass': 
+// Add some sample platforms (added to a group on creation)%0A
     
@@ -962,19 +962,19 @@
 %7Bwidth: 
-200
+198
 0, heigh
@@ -981,56 +981,27 @@
 t: 2
-2%7D),
+1%7D);
 %0A    
-  'avocado-smasher': new AvocadoSmasher
+new Ground
 (thi
@@ -1012,257 +1012,281 @@
 x: 1
-0
+6
 0, y: 
-29
+30
 0%7D, %7B
-group: 'players'%7D)%0A    %7D;%0A%0A    this.add.existing(this.prefabs%5B'bg-sky'%5D);%0A    this.add.existing(this.prefabs%5B'bg-layer-sea'%5D);%0A    this.add.existing(this.prefabs%5B'level-grass'%5D);%0A    this.add.existing(this.prefabs%5B'avocado-smasher'%5D);%0A
+width: 32, height: 21%7D);%0A%0A    // Prefabs that we need to keep track of (added to a group on creation)%0A    this.prefabs = %7B%0A      'avocado-smasher': new AvocadoSmasher(this, %7Bx: 64, y: 290%7D, %7Bgroup: 'prefabs'%7D)%0A    %7D;%0A%0A    // Simple camera follow on the player
 %0A   
@@ -1486,28 +1486,22 @@
 his.
-prefabs%5B'level-grass
+groups%5B'ground
 '%5D, 
@@ -1723,171 +1723,8 @@
 6);%0A
-      this.game.debug.text('onFloor: ' + this.prefabs%5B'avocado-smasher'%5D.body.onFloor() + ' jumpCounter: ' + this.prefabs%5B'avocado-smasher'%5D.jumpCounter, 16, 32);%0A
     

Use 'ground' group for collisions and addition to the world