import { ASSETS, STATES } from 'constants';

import Button from 'objects/button';
import Heading from 'objects/heading';

export default class Title extends Phaser.State {
  create() {
    const { game } = this;
    const objects = [
      new Heading(game, 'CGA RICHOCHET'),
      new Button(game, this.handleClick, 'Start game'),
    ];

    objects.forEach(game.add.existing, this);
    // tmp start level 1 for dev.
    this.game.state.start('LEVEL_01');
  }

  handleClick() {
    this.game.state.start('LEVEL_01');
  }
}

@@ -14,32 +14,203 @@
 TS, 
-STATES %7D from 'constants
+CANVAS, COLLISION_GROUPS, MATERIALS, STATES %7D from 'constants';%0Aimport %7B getMaterial, createCollisionGroup %7D from 'lib/utils';%0Aimport %7B bounce %7D from 'config/materials';%0Aimport fp from 'lodash/fp
 ';%0A%0A
@@ -246,16 +246,53 @@
 utton';%0A
+import Bullet from 'objects/bullet';%0A
 import H
@@ -379,45 +379,749 @@
 %7B%0A  
-create() %7B%0A    const %7B game %7D = this;
+preload() %7B%0A    // @TODO: Lots of duplicate code here.%0A    const bulletMaterial = getMaterial(this.game, MATERIALS.BULLET);%0A    const targetMaterial = getMaterial(this.game, MATERIALS.TARGET);%0A%0A    this.game.physics.p2.createContactMaterial(bulletMaterial, targetMaterial, bounce);%0A%0A    // Docs say these params are true by default. But without these it doesn't work.%0A    this.game.physics.p2.setBoundsToWorld(true, true, true, true, true);%0A%0A    this.game.physics.p2.setWorldMaterial(targetMaterial, true, true, true, true);%0A%0A    createCollisionGroup(this.game, COLLISION_GROUPS.BULLET);%0A  %7D%0A%0A  create() %7B%0A    const %7B game %7D = this;%0A    this.createBullet = this.createBullet.bind(this);%0A%0A    const bullets = fp.times(this.createBullet)(15);%0A
 %0A   
@@ -1233,24 +1233,42 @@
 art game'),%0A
+      ...bullets,%0A
     %5D;%0A%0A    
@@ -1309,16 +1309,17 @@
  this);%0A
+%0A
     // t
@@ -1343,24 +1343,27 @@
 for dev.%0A   
+ //
  this.game.s
@@ -1451,11 +1451,349 @@
 1');%0A  %7D
+%0A%0A  createBullet() %7B%0A    const x = fp.random(0, CANVAS.WIDTH);%0A    const y = fp.random(0, CANVAS.HEIGHT);%0A%0A    const bullet = new Bullet(this.game, x , y);%0A%0A    bullet.body.velocity.x = fp.random(300, 500) * (fp.random(0, 1) ? 1 : -1);%0A    bullet.body.velocity.y = fp.random(300, 500) * (fp.random(0, 1) ? 1 : -1);%0A%0A    return bullet;%0A  %7D
 %0A%7D%0A

Add random flying bullets on title screen