Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- class Game
- {
- preload()
- {
- game.load.image('water', 'assets/water.png');
- game.load.spritesheet('net', 'assets/net.png', 16, 16);
- }
- create()
- {
- game.physics.enable(Phaser.Physics.ARCADE);
- this.obstacles = game.add.physicsGroup();
- this.obstacles.create(240, 160, 'water');
- this.net = game.add.physicsGroup();
- game.input.addMoveCallback( (o) => this.updateGrid());
- this.createNet(10, 10);
- }
- createNet(width, height)
- {
- this.net.removeChildren();
- for(let i = 0; i < height; i++)
- {
- for( let j = 0; j < width; j++)
- {
- this.net.create(j*16, i*16, 'net');
- }
- }
- this.net.forEach( o => o.anchor.set(0.5, 0.5));
- this.net.setAll('alpha', '0.5');
- }
- updateGrid()
- {
- let x = game.input.activePointer.x ;
- let y = game.input.activePointer.y;
- x -= (x-8) % 16;
- y -= (y-8) % 16;
- if ( x != this.net.x || y != this.net.y )
- {
- this.net.x = x;
- this.net.y = y;
- this.net.forEach(o => this.updateColor(o));
- }
- }
- updateColor(o)
- {
- o.frame = game.physics.arcade.overlap(o, this.obstacles ) ? 1 : 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement