Jump to content

Cursor Down Collision Kill - Pokemon Stadium


maroxby
 Share

Recommended Posts

Forewarning: semi-newbie

Basically, if the user has the left cursor down and a "token" collides with the lftRect, I want to kill the token. For some reason my kill callback function for the collision is not working (below is relevant code):  

gumballGoGo.Preloader = function(game){
    this.player = null;
    this.ground = null;
    //this.tokens = null;
    this.ready = false;
};

var cursors, lftInit, rghtInit, ground, testDrp, sprite, tokens, rect, lftRect, ctrRect, rghtRect, lftToken;
var total = 0;

function lftHit(lftRect, lftToken) {
    if ( lftInit == true ){
        lftToken.kill()   
    }
};

gumballGoGo.Preloader.prototype = {
    preload: function(){
    },
    
    create: function() {

        // LFT BOX
        lftRect = this.add.sprite(0, this.world.height - 150, null);
        this.physics.enable(lftRect, Phaser.Physics.ARCADE);
        lftRect.body.setSize(100, 100, 0, 0);
        
        
        // CNTR BOX
        ctrRect = this.add.sprite(100, this.world.height - 150, null);
        this.physics.enable(ctrRect, Phaser.Physics.ARCADE);
        ctrRect.body.setSize(100, 100, 0, 0);
        
        
        // RGHT BOX
        rghtRect = this.add.sprite(200, this.world.height - 150, null);
        this.physics.enable(rghtRect, Phaser.Physics.ARCADE);
        rghtRect.body.setSize(100, 100, 0, 0);
        
        
        // INIT TOKEN GROUP  
        tokens = this.add.group();
        tokens.enableBody = true;
        this.physics.arcade.enable(tokens);

        testDrp = tokens.create(125, -50, 'token');
        testDrp.body.gravity.y = 300;
        
        
        
        // CONTROLS
        this.cursors = this.input.keyboard.createCursorKeys();

    },
    
    update: function() {
        this.ready = true;
        
        if (this.cursors.left.isDown)
            {
                lftInit = true;
            }
        else if (this.cursors.right.isDown)
            {
                rghtInit = true;
            }
        else
            {
                lftInit, rghtInit = false;
                
            }
        
        if (total < 20)
            {
                tokenSpawn();
            }
        
        this.physics.arcade.collide(lftRect, lftToken, lftHit, null, this);    
            
    }
};


function tokenSpawn() {

    lftToken = tokens.create(25, -(Math.random() * 800), 'token');
    
    lftToken.body.gravity.y = 300;
    
    total++;

}


PLEASE HELP! The ultimate goal is to recreate this type of gameplay

One additional note: as of now I am dropping "tokens" using a random spawn loop. I'd rather use a timed patter for the token drop. If you have any advice on that please share as well. Thanks :]

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...