good morning or hello idk ^^
i’m french sorry for my english i will do my best, so, i’m actually creating a little platform game and i have created a moving sprite but when my player hit this sprite nothing happen with collider or overlap function, idk how to do, i’m really stuck, i hope you can help please me and also you have understand me. enjoy
here is my code, it’s a mess but only player at the begining of create and m1 and the end of create are interesting here.
let player
let cursors
let platform
let f
let g
let k
let l
let h
let g1
let g2
let g3
let g4
let g5
let ji
let ju
let jo
let ja
let g6
let ro
var n=0
let keyA
let keyR
let ti
var i = 0
var a=1
let ba
let be
let bi
let bo
let gu
let fly
let to
let h1
let h2
let h3
let h4
let h5
let h6
let h7
let m1
let m2
class Scene1 extends Phaser.Scene{
constructor(){
super(“playGame”);
}
preload (){
this.load.image(‘level’, ‘assets/terrain/grass.png’);
this.load.image(‘fond’, ‘assets/back.png’);
this.load.image(‘kayou’, ‘assets/terrain/rock.png’);
this.load.image(‘secret’, ‘assets/interactsecret.png’);
this.load.spritesheet(‘dude’, ‘assets/dude.png’,{ frameWidth: 32, frameHeight: 48 });
this.load.audio(‘power’,‘assets/tudut.mp3’);
this.load.image(‘cadre’,‘assets/carre.png’)
this.load.image(‘pic’,‘assets/interact/spikes.png’)
this.load.image(‘picp’,‘assets/interact/spikep.png’)
this.load.image(‘cle’,‘assets/interact/keye.png’)
this.load.image(‘bonus’, ‘assets/interact/bonus.png’)
this.load.image(‘lock’,‘assets/interact/lock.png’)
this.load.image(‘bonusu’, ‘assets/interact/bonusu.png’)
this.load.image(‘coin’, ‘assets/interact/coin.png’)
this.load.image(‘mario’, ‘assets/interact/tuyo.png’)
this.load.audio(‘gta’,‘assets/gta.mp3’)
this.load.image(‘caisse’, ‘assets/interact/crate.png’)
this.load.image(‘on’, ‘assets/interact/buttonon.png’)
this.load.image(‘off’, ‘assets/interact/buttonoff.png’)
this.load.image(‘planche’, ‘assets/interact/plank.png’)
this.load.image(‘bridge’, ‘assets/interact/bridge.png’);
this.load.image(‘ladder’, ‘assets/interact/ladder.png’);
this.load.image(‘dirt’, ‘assets/terrain/Dirt.png’);
this.load.image(‘hammer’,‘assets/interact/hammer.png’)
this.load.image(‘door’,‘assets/interact/door.png’)
this.load.image(‘marioo’,‘assets/interact/tuyoo.png’)
this.load.image(‘ferm’,‘assets/interact/close.png’)
this.load.image(‘fly2’,‘assets/enemies/fly2.png’)
this.load.image(‘fly3’,‘assets/enemies/fly3.png’)
}
create(){
this.add.image(470,320, ‘fond’).setScale(1.35);
to = this.physics.add.image(20000,20000,‘hammer’).setScale(1.4)
this.add.image(665,280,‘ladder’)
this.add.image(1225, 1050, ‘dirt’)
this.add.image(1225,1250,‘ladder’)
gu = this.physics.add.staticImage(1365,1000,‘marioo’)
player = this.physics.add.sprite(1200,995, ‘dude’);
player.setCollideWorldBounds(true);
;
this.physics.add.collider(player,gu)
platform = this.physics.add.staticGroup({
key: ‘level’,
repeat: 16,
setXY: { x: 35, y: 1050, stepX: 70 }
}
);
g6 = this.physics.add.staticGroup({
key: ‘level’,
repeat: 2,
setXY: { x: 1295, y: 1050, stepX: 70 }
}
);
//ro = this.physics.add.staticImage(1225,985,‘kayou’).setScale(2)
ferm = this.physics.add.staticImage(245,988,‘ferm’)
this.physics.add.collider(player,ferm)
g = this.physics.add.staticGroup({
key: ‘level’,
repeat: 3,
setXY: { x: 525, y: 910, stepX: 70 }
}
);
f = this.physics.add.staticGroup({
key: ‘level’,
repeat: 5,
setXY: { x: 35, y: 560, stepX: 70 }
}
);
g1 = this.physics.add.staticGroup({
key: ‘level’,
repeat: 1,
setXY: { x: 945, y: 770, stepX: 70 }
}
);
g2 = this.physics.add.staticGroup({
key: ‘level’,
repeat: 0,
setXY: { x: 1225, y: 630, stepX: 70 }
}
);
g3 = this.physics.add.staticGroup({
key: ‘planche’,
repeat: 0,
setXY: { x: 945, y: 560, stepX: 70 }
}
);
g4 = this.physics.add.staticGroup({
key: ‘level’,
repeat: 0,
setXY: { x: 665, y: 490, stepX: 70 }
}
);
g5 = this.physics.add.staticGroup({
key: ‘level’,
repeat: 3,
setXY: { x: 385, y: 140, stepX: 70 }
}
);
this.physics.add.staticImage(1430,60,‘door’).setScale(0.8)
ji = this.physics.add.staticImage(735,140, ‘level’).setScale(1);
ju = this.physics.add.staticGroup({
key: ‘bridge’,
repeat: 1,
setXY: { x: 805, y: 130, stepX: 70 }
}
);
h2 = this.physics.add.staticImage(787,910,‘pic’)
h2.angle = 90
this.physics.add.overlap(player,h2,morgg,null,this)
h3 = this.physics.add.staticImage(893,770,‘pic’)
h3.angle = -90
this.physics.add.overlap(player,h3,morgg,null,this)
h4 = this.physics.add.staticImage(1225,682,‘pic’)
h4.angle = -180
this.physics.add.overlap(player,h4,morgg,null,this)
h5 = this.physics.add.staticImage(613,490,‘pic’)
h5.angle = -90
this.physics.add.overlap(player,h5,morgg,null,this)
h6 = this.physics.add.staticImage(1365,190,‘pic’)
h6.angle = -180
this.physics.add.overlap(player,h6,morgg,null,this)
h7 = this.physics.add.staticImage(1435,190,‘pic’)
h7.angle = -180
this.physics.add.overlap(player,h7,morgg,null,this)
function morgg () {
player.x = 15
player.y = 950
}
ba = this.physics.add.staticImage(945,130,‘bridge’)
be = this.physics.add.staticImage(1015,130,‘bridge’)
bi = this.physics.add.staticImage(1085,130,‘bridge’)
bo = this.physics.add.staticImage(1155,130,‘bridge’)
this.physics.add.collider(player,ba);
this.physics.add.collider(player,be, lol, null, this);
this.physics.add.collider(player,bi);
this.physics.add.collider(player,bo);
function lol (){
ba.disableBody(true, true);
be.disableBody(true, true);
bi.disableBody(true, true);
bo.disableBody(true, true);
}
jo = this.physics.add.staticGroup({
key: ‘level’,
repeat: 1,
setXY: { x: 1365, y: 140, stepX: 70 }
}
);
ja = this.physics.add.staticGroup({
key: ‘bridge’,
repeat: 1,
setXY: { x: 1225, y: 130, stepX: 70 }
}
);
this.physics.add.collider(player,ji);
this.physics.add.collider(player,ju);
this.physics.add.collider(player,jo);
this.physics.add.collider(player,ja);
this.physics.add.collider(player,g1);
this.physics.add.collider(player,g2);
this.physics.add.collider(player,g3);
this.physics.add.collider(player,g4);
this.physics.add.collider(player,g5);
this.physics.add.collider(player,g6);
this.physics.add.collider(player,ro);
k = this.physics.add.image(550, 70, ‘caisse’)
this.physics.add.collider(player,k, po, null, this);
this.physics.add.collider(k,g);
this.physics.add.collider(k,f);
this.physics.add.collider(k,platform);
this.physics.add.collider(k,g5);
this.physics.add.collider(k,g4);
this.physics.add.collider(k,h);
k.setCollideWorldBounds(true);
function po (player, k) {
k.setVelocityX(-0.00000000000000000000000000001)
}
l = this.physics.add.staticImage(23,490, ‘off’);
l.angle=0.5;
this.physics.add.collider(player,l);
this.physics.add.collider(k,l, buton, null, this);
function buton (k,l) {
l.disableBody(true, true);
h = this.physics.add.staticImage(13,490, ‘on’)
this.physics.add.collider(player,h);
n = 420
to.x=player.x-6
to.y=player.y
}
this.physics.add.collider(k,h)
this.cameras.main.setBounds(0, 0, 1470 , 1085);
this.physics.world.setBounds(0, 0, 1435, 1085);
this.cameras.main.startFollow(player, true, 0.3, 0.3);
this.physics.add.collider(player,platform);
this.physics.add.collider(player,g);
this.physics.add.collider(player,f);
this.anims.create({
key: ‘left’,
frames: this.anims.generateFrameNumbers(‘dude’, { start: 0, end: 3 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: ‘turn’,
frames: [ { key: ‘dude’, frame: 4 } ],
frameRate: 20
});
this.anims.create({
key: ‘right’,
frames: this.anims.generateFrameNumbers(‘dude’, { start: 5, end: 8 }),
frameRate: 10,
repeat: -1
});
cursors = this.input.keyboard.createCursorKeys();
keyA = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A);
keyR = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.R);
this.anims.create({
key: ‘fly’,
frames: [
{ key: ‘fly2’ },
{ key: ‘fly3’, duration: 50 }
],
frameRate: 8,
repeat: -1
});
m1 = this.physics.add.sprite(10, 710, ‘fly2’).play(‘fly’)
m1.setVelocityX(200);
m1.flipX = true
this.physics.add.overlap(player,m1,morgg,null,this)
}
update(){
//if (player.x > m1.x-30 && player.x < m1.x+30 && player.y>m1.y+5 && player.y < m1.y -5) {
// player.setTint(0xff0000);
//}
m1.y=700
if (m1.x < 10){
m1.flipX = true
m1.setVelocityX(200)
}
if (m1.x>1460){
m1.flipX = false
m1.setVelocityX(-200)
}
if (n==420){
to.x=player.x-6
to.y=player.y}
if (cursors.left.isDown)
{
player.setVelocityX(-200);
player.anims.play(‘left’, true);
a = -1
}
else if (cursors.right.isDown )
{
player.setVelocityX(200);
player.anims.play(‘right’, true);
a= 1
}
else
{
player.setVelocityX(0);
player.anims.play('turn');
}
if (cursors.up.isDown && player.body.touching.down)
{
player.setVelocityY(-530);
}
if (player.x>630 && player.x<700 && player.y<525 && player.y>70 && cursors.up.isDown){
player.setVelocityY(-200);
}
if (player.y>1050){
player.setCollideWorldBounds(false);
}
if (keyA.isDown && i<1 && n==420){
i=1
ti = this.physics.add.image(player.x+15,player.y,‘hammer’).setScale(2);
ti.angle = 90a
ti.body.allowGravity = false;
ti.setVelocityX(a500)
this.physics.add.collider(ti,ro, boum, null, this)
}
if (keyR.isDown){
i=0
}
if (player.y>1085){
this.scene.start(“cave”)
}
}
}
function boum (ti,ro){
ro.disableBody(true, true);
ti.disableBody(true, true);
}