Skip to content
Snippets Groups Projects
Commit eb0ec92d authored by Samson's avatar Samson
Browse files

firing bullets

parent f4462312
No related branches found
No related tags found
No related merge requests found
Pipeline #163946 passed
harkka3/samson/assets/sprites/penis-barrel.png

2.12 KiB

harkka3/samson/assets/sprites/penis-cannon-base.png

7.27 KiB

harkka3/samson/assets/sprites/sperm.png

522 B

demo.state2 = function(){};
var barrel, bullets, velocity = 1000;
demo.state2.prototype = {
preload: function(){},
preload: function(){
game.load.image('base', 'assets/sprites/penis-cannon-base.png');
game.load.image('barrel', 'assets/sprites/penis-barrel.png');
game.load.image('bullet', 'assets/sprites/sperm.png');
},
create: function(){
game.stage.backgroundColor = '#0066ff';
addChangeStateEventListeners();
var base = game.add.sprite(centerX, centerY, 'base');
base.anchor.setTo(0.5);
base.scale.setTo(0.4);
barrel = game.add.sprite(centerX, centerY, 'barrel');
barrel.anchor.setTo(0.5, 1);
barrel.scale.setTo(0.5);
bullets = game.add.group();
bullets.enableBody = true;
bullets.physicsBodyType = Phaser.Physics.ARCADE;
bullets.createMultiple(50, 'bullet');
bullets.setAll('checkWorldBounds', true);
bullets.setAll('outOfBoundsKill', true);
},
update: function(){
barrel.rotation = game.physics.arcade.angleToPointer(barrel);
if(game.input.activePointer.isDown) {
this.fire();
}
},
update: function(){}
fire: function() {
console.log('firing');
var bullet = bullets.getFirstDead();
bullet.reset(barrel.x, barrel.y);
game.physics.arcade.moveToPointer(bullet, velocity);
bullet.rotation = game.physics.arcade.angleToPointer(bullet);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment