This site requires JavaScript, please enable it in your browser!
Greenfoot back
het52
het52 wrote ...

2017/5/6

Chracter punches when key pressed once

het52 het52

2017/5/6

#
im making a fighter game. in this game my character is suppose to punch, move and jump. movement and jump work perfectly fine but my punch method doesnt. when the punch key is pressed once the character is suppose to go through an array to make it look like an animation. but the game isnt going through the animation at all. it sets all the other variables but it doesnt setImage to the punchGif. Code that isnt green is code that i think is affecting the punch method.
    private void image(GreenfootImage r)
    {
        if(skipCount % 8 ==0)
        {
            setImage(r);
            count++;
        }
        skipCount++;
    }
    private void movement()
    {
        if(getX() == getX() && isPunching == false)
        {
            move = false;
        }
        /*if(Greenfoot.isKeyDown("d"))
        {
            setLocation(getX()+3,getY());
            image(gif[count % gif.length]);
            move = true;
            facingRight = true;
        }*/else if(move == false && facingRight == true)
        {
            setImage(stand);
        }
        /*if(Greenfoot.isKeyDown("a"))
        {
            setLocation(getX()-3,getY());
            image(mGif[count  % mGif.length]);
            move = true;
            facingRight = false;
        }*/else if(move == false && facingRight == false)
        {
            setImage(mstand);
        }
    }
    private void punch()
    {
        if(Greenfoot.isKeyDown(".") && keyDown == false)
        {
            move = true;
            image(punchGif[count  % punchGif.length]);
            isPunching = true;
            facingRight = true;
            punchCount++;
            if(punchCount ==3)
            {
                keyDown = true;
                punchCount =0;
            }
        }
        if(!Greenfoot.isKeyDown(".") && keyDown == true)
        {
            isPunching = false;
            keyDown = false;
        }
        /*if(Greenfoot.isKeyDown(","))
        {
            image(mpunchGif[count  % mpunchGif.length]);
            move = true;
            isPunching = true;
            facingRight = false;
        }else
        {
            isPunching = false;
        }*/
    }
You need to login to post a reply.