Jump to content

Arcade collisions Problem


JokerJESUS
 Share

Recommended Posts

Hello, i have a problem with collisions, betwen player and box (betwen box and bullets works fine!!).

 

R to reload.

 

thats how it looks, and sorry for mess in code, but i m changing everything all time.

 

 

thats my "game". I m just testing and learning.

jokerjesus.pl <--- app.html it's a game.

thats my code:

<spoiler>

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'jesus', { preload: preload , create: create , update: update, render: render });var bullets,    bullet,    cursors,    fireButton,    player,    ammo,    R, W, S, A, D,    boxGroup,    box,    box1;var bulletTime = 0;var reload = 25;var pre_reload = 0;function preload(){    game.load.image('bullet', 'img/bullet.png');    game.load.image('players', 'img/players.png', 16, 32);    game.load.image('box', 'img/box.png', 32, 32);}function create(){    //PLUGINS!!!    game.add.plugin(Phaser.Plugin.Debug);    //END of Plugins!!!    ammo = game.add.text(10, 10, 'AMMO:' + reload, { font: '12px Arial', fill: '#fff' });    player = game.add.sprite(30,30,'players');    game.physics.enable(player);    game.camera.follow(player);    player.anchor.set(0.5);    player.checkWorldBounds = true;    player.enableBody = true;    createBullets();    createBoxes();    cursors = game.input.keyboard.createCursorKeys();    fireButton = game.input.keyboard.addKey(Phaser.Keyboard.leftMouse);    R = game.input.keyboard.addKey(Phaser.Keyboard.R);    W = game.input.keyboard.addKey(Phaser.Keyboard.W);    S = game.input.keyboard.addKey(Phaser.Keyboard.S);    A = game.input.keyboard.addKey(Phaser.Keyboard.A);    D = game.input.keyboard.addKey(Phaser.Keyboard.D);}function update() {    ammo.text = 'AMMO:'+reload+'/25';        //Movement!!!    player.rotation = game.physics.arcade.angleToPointer(player);    if (A.isDown)    {        player.x --;    }    if (D.isDown)    {        player.x ++;    }    if (W.isDown)    {        player.y --;    }    if (S.isDown)    {        player.y ++;    }    if(R.isDown){        if(pre_reload == 0) {            pre_reload = 1;            reload = 0;            AUTOreload();        }    }    else    {        player.animations.stop();        player.body.velocity.y = 0;        player.body.velocity.x = 0;    }    //END of Movement ...    //Shooting AND Reloading!!!    bullet = bullets.getFirstExists(false);    if (reload > 0) {        if (bullet) {            if (game.input.mousePointer.isDown) {                fire();            }        }    }else if(reload < 1 && pre_reload == 0){        AUTOreload();        pre_reload = 1;    }    //END of Shooting ...    //COLLISIONS !!!    game.physics.arcade.collide(bullets, boxGroup,function(bullet){        bullet.kill();    });    game.physics.arcade.collide(bullets, player);    game.physics.arcade.collide(player, boxGroup);    game.physics.arcade.collide(player, box1,function(){        player.kill();    });    //END OF COLLISIONS!!!}function render() {    //game.debug.geom( rect, 'rgba(255,0,0,1)' ) ;    game.debug.spriteBounds(box1);    game.debug.body(player);}function AUTOreload(){    setTimeout(function(){        reload = 25;        pre_reload = 0;    },3000);}function createBullets(){    bullets = game.add.group();    bullets.enableBody = true;    bullets.physicsBodyType = Phaser.Physics.ARCADE;    bullets.createMultiple(30, 'bullet');    bullets.setAll('anchor.x', 0.5);    bullets.setAll('anchor.y', 0.5);    bullets.setAll('outOfBoundsKill', true);    bullets.setAll('checkWorldBounds', true);}function createBoxes(){    boxGroup = game.add.group();    boxGroup.physicsBodyType = Phaser.Physics.ARCADE;    boxGroup.enableBody = true;    boxGroup.setAll('anchor.x', 0.5);    boxGroup.setAll('anchor.y', 0.5);    box1 = game.add.sprite(100,100,'box',0,boxGroup);    box1.body.immovable = true;}function fire(){        if (game.time.now > bulletTime) {            reload -= 1;            bullet.reset(player.x, player.y);            //bullet.body.velocity.setTo(game.input.x, game.input.y);            bullet.body.speed = 100;            bullet.rotation = game.physics.arcade.moveToPointer(bullet, 1200, game.input.activePointer, 0);            //bullet.rotation = game.physics.arcade.moveToXY(bullet, game.input.x, game.input.y, 600, 600);//(, 1000, game.input.activePointer, 400);            bulletTime = game.time.now + 200;            console.log(reload);        }}

</spoiler>

Link to comment
Share on other sites

function update() {    game.physics.arcade.collide(bullets, boxGroup,function(bullet){        bullet.kill();    });    game.physics.arcade.collide(bullets, player);    game.physics.arcade.collide(player, boxGroup);    game.physics.arcade.collide(player, box1,function(){        player.kill();    });    ammo.text = 'AMMO:'+reload+'/25';        //Movement!!!    player.rotation = game.physics.arcade.angleToPointer(player);    if (A.isDown)    {        player.x --;    }    if (D.isDown)    {        player.x ++;    }    if (W.isDown)    {        player.y --;    }    if (S.isDown)    {        player.y ++;    }    if(R.isDown){        if(pre_reload == 0) {            pre_reload = 1;            reload = 0;            AUTOreload();        }    }    else    {        player.animations.stop();        player.body.velocity.y = 0;        player.body.velocity.x = 0;    }    //END of Movement ...    //Shooting AND Reloading!!!    bullet = bullets.getFirstExists(false);    if (reload > 0) {        if (bullet) {            if (game.input.mousePointer.isDown) {                fire();            }        }    }else if(reload < 1 && pre_reload == 0){        AUTOreload();        pre_reload = 1;    }    //END of Shooting ...    //COLLISIONS !!!    /*game.physics.arcade.collide(bullets, boxGroup,function(bullet){        bullet.kill();    });    game.physics.arcade.collide(bullets, player);    game.physics.arcade.collide(player, boxGroup);    game.physics.arcade.collide(player, box1,function(){        player.kill();    });*/    //END OF COLLISIONS!!!}

Still nothing. ;/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...