Jump to content

matching buttons with group content


Recommended Posts

I know I’ve been a little annoying the last few weeks, but it seems that anything I try won’t work!


In my game, a dance revolution-like game, I have a group of randomly generated arrows (1 minimum - 3 maximum), If the group has more than 1 arrow and the player press the same arrows in his keyboard, that will give points, but if the player misses one or more arrows, the game won’t give points.


To sum it up, how can I check if the arrows the player press, match with the arrows coming in the group in order to give points?


I really appreciate all the help you’ve been giving me, this is the most ambitious game I’ve been working on and really want to make it work.


thanks in advance!

Link to comment
Share on other sites

You probably want to use a keypress function. 


See here: http://www.html5gamedevs.com/topic/2739-on-key-up-event-or-on-release/


As you are creating the sprites (arrows) and they move down the screen, make a "hit" area that just checks if any sprites are inside that hit area, 


I've done it, although slightly differently here.. where a bar rolls down the screen, and if the bar's bottom most y is inside the box's top most y, it does something, here is my collision detection: I wrote it myself instead of using the arcade to increase performance on mobiles :)

	collisionDetection: function() {		if (this.slider.y + this.slider.height >= this.box.y && this.slider.y <= (this.box.y + this.box.height)) {			this.updateScore(this.player.speed * this.player.difficulty);			this.player.speed ++;			this.player.difficulty ++;			this.manageBox();		} else {			this.player.lives --;			this.healthSprite.animations.play("rotate", 15, false);			if (this.player.speed <= 1) {			} else {				this.player.speed --;			}		}	},

All you then have to do, is create an object of arrows that are floating down the screen, check if the arrow that's next in the object is in the hit box, if it is and the player presses the right key then you can give them score.


As far as giving them score, you could simply get the centre point of your hit area and give say 100 points if the moving arrows's centre x is the same as the hit area and subtract 10 points for every x value it's off.


Something like:

calcScore: function(hitPos) {	return 100 - ((hitPos - 450) * 10) ;	// where 450 is the centre point of your hit area},

won't work straight off the bat, but might give you an idea, or some inspiration on how to do what it is you want to do :)

Link to comment
Share on other sites


  • Recently Browsing   0 members

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