Collision detection for one frame in JavaScript -


i'm playing around crafty.js game engine. have small game player ball , drops down platforms. every time hits next platform, gains point. score stored variable , displayed on screen. i'm using crafty's collision detection detect when player hits new platform. if you're not familiar crafty, it's pretty simple, whenever player hits new platform, event fired , can add 1 score.

my problem: game running around 60fps. every time canvas reloads, crafty detect whether or not player touching platform. results in score variable incrementing 1 every single frame player touching level. far want. want score incremented once per platform. problem don't know how fix.

other things i've tried solve it: considered measuring distance player starting point tell (by division) platform player on (since platforms equally vertically spaced). problem since crafty having issues giving me current location of player.

what think work: think if have event fired on first frame player hits each platform, might work. (side note, if player stays on 1 platform , jumps , lands on same platform second time, want one point added. not double jumping)

what need guys: have ever had issue? need finish game. , minor technical problem preventing me finishing it. i'd love somebodys input.

the simplest solution seem setting variable each platform tracks whether player has landed on platform or not. then, whenever ball in contact platform hasn't been landed on yet, award point , mark platform landed on.

if platforms in linear sequence, have single integer variable tracks platform player on.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -