0

How to create an incremented score after he pickup the rubbish? I am very new on this thing and need help on coding.

My code below is on a separated .as file (movieclip).

As you can see, there are codes for when the player hittestobject, the "rubbish" will go away but how to apply a new code for score to that specific function? so the score will be incremented each time he pick up the rubbish.

d

package  {

    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;


    public class mazeClass extends MovieClip {
        var mouseUp:Boolean = false;
        var mouseDown:Boolean = false;
        var mouseLeft:Boolean = false;
        var mouseRight:Boolean = false;

         var speed:Number = 5;

        public function mazeClass() {
            // constructor codea



            stage.addEventListener(KeyboardEvent.KEY_DOWN, CheckDownKeys);
            stage.addEventListener(KeyboardEvent.KEY_UP, CheckUpKeys);
            stage.addEventListener(Event.ENTER_FRAME, updatePos);
        }
        private function CheckDownKeys(e:KeyboardEvent){
            if(e.keyCode == Keyboard.UP){
                mouseUp =true;
                }
            if(e.keyCode == Keyboard.DOWN){
                mouseDown =true;
                }
            if(e.keyCode == Keyboard.LEFT){
                mouseLeft =true;
                }
            if(e.keyCode == Keyboard.RIGHT){
                mouseRight =true;
                }

            }
            private function CheckUpKeys(e:KeyboardEvent){
                if(e.keyCode == Keyboard.UP){
                mouseUp =false;
                }
            if(e.keyCode == Keyboard.DOWN){
                mouseDown =false;
                }
            if(e.keyCode == Keyboard.LEFT){
                mouseLeft =false;
                }
            if(e.keyCode == Keyboard.RIGHT){
                mouseRight =false;
                }

            }
            private function updatePos(e:Event){
            if(mouseUp == true){
                if(!wall.hitTestPoint(jacob.x,jacob.y-22, true)){

                jacob.y -= speed;
                }
            }
            if(mouseDown == true){
                if(!wall.hitTestPoint(jacob.x, jacob.y+22, true)){

                jacob.y += speed;
                }
            }
            if(mouseLeft == true){
                if(!wall.hitTestPoint(jacob.x-22, jacob.y, true)){

                jacob.x -= speed;
                }
            }
            if(mouseRight == true){
                if(!wall.hitTestPoint(jacob.x+22, jacob.y, true)){

                jacob.x += speed;
                }
            }
            if(jacob.hitTestObject(a1)){
                a1.x = a1.y = -1000;
                _root.score = 0;
                _root.score++;
                score.text = _root.score;
                }
            if(jacob.hitTestObject(a2)){
                a2.x = a2.y = -1000;
                }
            if(jacob.hitTestObject(a3)){
                a3.x = a3.y = -1000;
                }
            if(jacob.hitTestObject(a4)){
                a4.x = a4.y = -1000;
                }   
        }
    }

}
Shizu
  • 66
  • 1
  • 11
  • anyone knows? sorry to bump – Shizu Dec 21 '19 at 14:48
  • 2
    There's no any **TextField** reference in your class. Normally, you need to have a **score:int** class member, then you update the **TextField** each time the **score** changes. – Organis Dec 21 '19 at 16:16
  • 1
    Look through the [TextField](https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html) documentation for putting it into your game – ugotopia123 Dec 22 '19 at 02:37

0 Answers0