hey i’m trying to make a small tank game but i tried making my bullets as a weapon and now it wont collide with my enemies please help. This is the code for my tank game so far. Some part of my code is french tho like jeu is game but most is english.
var jeu = new Phaser.Game(1200, 600, Phaser.CANVAS, ‘’, { preload: chargement, create: creation, update: repetition });
var tank;
var enemieTank;
var jouer = true;
var fleches;
var backdrop;
var barrel;
var weapon;
function chargement () {
jeu.load.image(‘tank’, ‘ressources/images/tank160X120.png’);
jeu.load.image(‘enemie’, ‘ressources/images/enemie160X120.png’);
jeu.load.image(‘backdrop’, ‘ressources/images/backdrop.png’);
jeu.load.image(‘barrel’, ‘ressources/images/barrel.png’);
jeu.load.image(‘bullet’, ‘ressources/images/bullet.png’);
}
function creation () {
jeu.physics.startSystem(Phaser.Physics.ARCADE);
jeu.world.setBounds(0, 0, 4000, 600);
backdrop = jeu.add.sprite(2000, 300, 'backdrop');
barrel = jeu.add.sprite(231, 486, 'barrel');
enemieTank = jeu.add.sprite(1280, 475, 'enemie');
weapon = jeu.add.weapon(99, 'bullet');
weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
jeu.physics.enable(weapon, Phaser.Physics.ARCADE);
weapon.bulletSpeed = 500;
weapon.fireRate = 400;
weapon.rotation = jeu.physics.arcade.angleToPointer(weapon);
tank = this.add.sprite(220, 475, 'tank');
weapon.trackSprite(barrel, 0, 0, true);
jeu.input.activePointer.isDown = false;
backdrop.anchor.setTo(0.5,0.5);
tank.anchor.setTo(0.5,0.5);
barrel.anchor.setTo(0.5,0.5);
enemieTank.anchor.setTo(0.5,0.5);
jeu.physics.enable(tank, Phaser.Physics.ARCADE);
jeu.physics.enable(barrel, Phaser.Physics.ARCADE);
jeu.physics.enable(enemieTank, Phaser.Physics.ARCADE);
jeu.camera.follow(tank);
enemieTank.body.immovable = true;
enemieTank.body.velocity.setTo(0, 0);
enemieTank.body.bounce.setTo(1, 1);
tank.body.collideWorldBounds = true;
enemieTank.body.collideWorldBounds = true;
cleD = jeu.input.keyboard.addKey(Phaser.Keyboard.D);
cleA = jeu.input.keyboard.addKey(Phaser.Keyboard.A);
}
function platformerFollow() {
jeu.camera.follow(tank, Phaser.Camera.FOLLOW_PLATFORMER);
style = ‘STYLE_PLATFORMER’;
}
function repetition () {
if (jouer){
//jeu.physics.arcade.collide(bullet, enemieTank);
//jeu.physics.arcade.overlap(bullet, enemieTank, bulletHitEnemy, null, this);
jeu.physics.arcade.collide(tank, enemieTank);
tank.body.velocity.setTo(0, 0);
barrel.rotation = jeu.physics.arcade.angleToPointer(barrel);
barrel.body.x = tank.body.x + 8
if (cleD.isDown){
tank.body.velocity.x = 200;
}
else if (cleA.isDown){
tank.body.velocity.x = -200;
}
if (jeu.input.activePointer.isDown){
weapon.fire();
}
jeu.physics.arcade.overlap(weapon, enemieTank, collisionHandler, null, this);
}
}
function bulletHitEnemy (tank, bullet) {
bullet.kill();
}
function collisionHandler (weapon, enemieTank) {
weapon.kill();
enemieTank.kill();
}