A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Keypress accuracy reward

  1. #1
    Member
    Join Date
    Nov 2006
    Posts
    93

    Keypress accuracy reward

    Hey, heres what I'm trying to do.

    I have an mc which flies across the screen towards a holder, when the player presses the left key, if the mc is over the holder he gets a score added. I'm trying to make it so the more perfect the mc is over the holder the higher the score.

    So I make this code:
    Code:
     			//Spectacular arrow press
    			if (Key.isDown(Key.LEFT) and (this._x>174 and (this._x<176))) {
    				trace("Spectacular!");
    				//Add to score
    				_root.scoreG += 500;
    				_root.scoreC += 500;
    				//Add to combo
    				_root.comboScore++;
    				_root.combo_score.text = _root.comboScore;
    				trace(_root.comboScore);
    				//Only add enough to put HP back to 200 if its above 190
    				if (_root.hpAmount>190 and (_root.hpAmount<200)) {
    					_root.hpAmount += (_root.hpMax-_root.hpAmount);
    				}
    				//Add HP if HP is less than 190
    				if (_root.hpAmount<=190) {
    					_root.hpAmount += 10;
    				}
    				trace(_root.hpAmount);
    				//Keep HP Bar at Maximum
    				if (_root.hpAmount>200) {
    					_root.hpAmount = 200;
    				}
    				this.unloadMovie();
    (It goes on with the same but changes the X co-ordinate for great, good, okay etc and the script contains no errors)

    Instead of using hitTest I decided to try and just use the mc's current X co-ordinate.

    If its at a certain point when the player presses the key, the more or less the score given.

    However its not working. Currently the only way it will work is if I HOLD down the left key (rather than just pressing it) and all that does is give me the trace "Spectacular" and 500 points...this cant be right though because it should give the least amount of points because if the keys being held down the mc will immediately get to the lowest X co-ordinate specified, such as Oh Dear, or Bad (rather than the highest which is spectacular, if that makes sense).

    So any ideas as to what might be going wrong? Why do I have to hold the key, and why does only spectacular work etc.

    I realise the way I've written the code isnt the best way, or tidiest (still learning...) but in my eyes what I've written should have worked. (At least for the arrow coming towards the holder, havnt specified the extra X co-ordinate if statements for if it goes past the holder).

    Any help would be greatly appreciated as ever, thanks.
    Last edited by xtrava; 11-25-2006 at 03:38 PM.

  2. #2
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259

    hi

    i work best with demo FLAs. I don't really don't understand your game and I'm lazy.
    CEO OF

  3. #3
    Member
    Join Date
    Nov 2006
    Posts
    93
    It's a rhythm action game. Ever seen DDR or Stepmania? Arrows fly to the holders and the user has to press the corresponding arrow on time..

  4. #4
    Pencil Farmer cadin's Avatar
    Join Date
    Jul 2006
    Location
    Vancouver BC
    Posts
    323
    My guess would be just that you made it too hard.
    You've only given it a range of 2 pixels to actually hit it. Depending on how fast the movie clip is moving it might not ever actually be in that range (ie. if it moves 3 pixels each frame).
    Hard to say why the others aren't working unless you post the code for them.

    A good way to start debugging would be to trace the x value of the clip whenever you hit the button. Then you can see if you're actually hitting it when it's in that range.

  5. #5
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259

    one thing

    one thing that may be a problem is the speed at witch the arrows are going. lets say the DDR arrows go at _x+=25 this means that the MC is not moving at 25 pix/frame it means it is jumping 25 pix a frame. I had a problem like this in a dodging game i made. After the speed of X# the walls could not stop my hero it would jump over him(so to speak). The solution was to make my speed slower and my frame rate higher.
    Last edited by zervell; 11-25-2006 at 05:40 PM.
    CEO OF

  6. #6
    Member
    Join Date
    Nov 2006
    Posts
    93
    I see...The trace gives me 174.85, or if I increase the range it gives say 164.85...However this doesnt even seem to be happening at the right place.

    The arrows move at a speed of 5, tried it at 1, and even then it doesnt work very well =/

    How else could I do this. I was thinking is it possible to go inside my arrow MC, and define sections of it so that depending on what part of it is hitting the holder MC theres a different score given???

    Thanks for trying to help...

    Also, it seems that if I change the order of the if statements, the one at the top is the one that seems to work, and the others seem to get ignored.

    They are coded the same as the other one I posted, heres an example:

    Code:
    			//Oh Dear arrow press
    			if (Key.isDown(Key.LEFT) and (this._x>155 and (this._x<170))) {
    				trace("Oh Dear!");
    				//Add to score
    				_root.scoreG += 300;
    				_root.scoreC += 300;
    				//Add to combo
    				_root.comboScore++;
    				_root.combo_score.text = _root.comboScore;
    				trace(_root.comboScore);
    				//Only add enough to put HP back to 200 if its above 190
    				if (_root.hpAmount>190 and (_root.hpAmount<200)) {
    					_root.hpAmount += (_root.hpMax-_root.hpAmount);
    				}
    				//Add HP if HP is less than 190
    				if (_root.hpAmount<=190) {
    					_root.hpAmount += 10;
    				}
    				trace(_root.hpAmount);
    				//Keep HP Bar at Maximum
    				if (_root.hpAmount>200) {
    					_root.hpAmount = 200;
    				}
    				this.unloadMovie();
    They go one after the other.
    Last edited by xtrava; 11-25-2006 at 06:22 PM.

  7. #7
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259
    Code:
    range = 40;
    closeness = 0;
    function onEnterFrame() {
    	arrowcode();
    }
    function arrowcode() {
    	arrow_._x += 10;
    	closeness = checkpoint._x-arrow_._x;
    	if ((arrow_._x>checkpoint._x-range) && (arrow_._x<checkpoint._x+range)) {
    		//scored
    		//delete the movie
    		closeness = "good";
    	}
    	if (arrow_._x>checkpoint._x+range) {
    		//score -1
    		//delete the movie
    		closeness = "missed";
    	}
    }
    this code i made works fine. It just needs to be made for dynamic movies. This file should give you the idea of what to do.

    the thing you needed was a good "if statement" to check it. The if statement that I wrote is what your looking for. I wish you would give the fla I could better understand you, but this code should do it for you.

    pointgame.zip
    CEO OF

  8. #8
    Member
    Join Date
    Nov 2006
    Posts
    93
    I have MX I'll try to get the code to work...Thanks

    EDIT: I've simplified it and I think I've got it working right

    Code:
    closeness = _root.left._x-this._x;
    	if (Key.isDown(Key.LEFT) and (closeness <= 10) and (closeness >= -10)){
    It's working perfectly at the moment, just going to put it around the bulk of my arrows code and see if it still functions properly.
    Last edited by xtrava; 11-25-2006 at 07:56 PM.

  9. #9
    Senior Member zervell's Avatar
    Join Date
    May 2004
    Posts
    259
    CEO OF

  10. #10
    Member
    Join Date
    Nov 2006
    Posts
    93
    I seem to have it working now. Thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center