Jump to content

Random collisions for seemingly no reason


rkn7
 Share

Recommended Posts

Hello,

 

I'm a fairly decent PHP coder but have never really delved into Javascript before until I came across Phaser and had to give it a try (it's the most appealing game engine I've ever come across, it got me to write my first game!) so I've created a fairly basic Flappy Birds-style game that allows the main sprite to jump before falling and trying to avoid enemies that are coming in from the right.

 

Because I've never attempted any massive Javascript undertaking before, especially game-making, I've encountered a few problems but have generally been able to fix them.

 

However, for some reason, I've been having problems that seem to be coming from an overlap event. At random points in the game (sometimes when the player seemingly jumps too high), it will trigger the end_game_hit() function and end the game. This is frustrating because it seems to come from nowhere and the game keeps restarting. It works fine for when they actually hit but the random hits seem to come from nowhere and I can't figure out where.

 

I've got this set up for the collision event in update():

this.game.physics.overlap(this.main, this.enemies, this.end_game_hit, null, this);

And these are the other functions. (To avoid confusion, each time there's a collision, it chooses a random number and plays the appropriate sound file. This all works fine.)

    end_game_hit: function() {        console.log('Hit an enemy.');        this.kill_sound_no = random_number(5);        this.kill_sound[this.kill_sound_no].play();        this.end_game();    },    end_game: function() {        this.game.time.events.remove(this.timer);        this.game.time.events.remove(this.sound_timer);        this.game.score = this.score;        if(this.game.score > readCookie('highscore')) {            createCookie('highscore',this.game.score,30);        }        this.game.state.start('main');    }

It's probably something I've overlooked but I'd appreciate any help! Thanks in advance.

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