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

2016/9/30

Why are powerups so confusing?

1
2
dERPscHNOzzLE dERPscHNOzzLE

2016/9/30

#
and for my player actor
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class Player extends Actor
{
    private final int SPEED_BOOST_TIMER = 115;
    private int speedBoostTimeLeft = SPEED_BOOST_TIMER;
    private int mySpeed;
    private boolean gotSpeedBoost = false;
    public Player()
    {
        mySpeed = 5;
    }     
    public void act()
    {
        getSpeedBoost();
        if (isTouching(SpeedBoost.class))
        {
            removeTouching(SpeedBoost.class);
            speedBoostTimeLeft = SPEED_BOOST_TIMER;
            if (!gotSpeedBoost)
            {
                mySpeed += 5;
                gotSpeedBoost = true;
            }
        }
        if (gotSpeedBoost)
        {
            speedBoostTimeLeft--;
            if (speedBoostTimeLeft == 0)
            {
                gotSpeedBoost = false;
                mySpeed -=5;
            }
        }
    }
    public void getSpeedBoost()
    {
        if (isTouching(SpeedBoost.class))
        {
            removeTouching(SpeedBoost.class);
            gotSpeedBoost = true;
            mySpeed += 5;
        }
    }
    public void speedBoostTimer()
    {
        speedBoostTimeLeft--;
        if (speedBoostTimeLeft <= 0)
        {
            gotSpeedBoost = false;
            mySpeed -= 5;
            speedBoostTimeLeft = SPEED_BOOST_TIMER;
        }
    }
    public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(-10, 0, clss);
        return actor != null;        
    }
    public void eat(Class clss)
    {
        Actor actor = getOneObjectAtOffset(-10, 0, clss);
         if(actor != null) {
            getWorld().removeObject(actor);
        }
    }
}
danpost danpost

2016/9/30

#
Your mouse will only act using the act method in the Mouse class (the act method of the Player class is overridden). Just remove the act method from the Player class to begin with. That should not change anything, I am still looking into the issue.
danpost danpost

2016/9/30

#
It appears you have duplicated some of the code for speed-boosting in the Mouse and Player class. You should only have it in one of the two classes. If all types of Player objects (all objects created by classes that extend the Player class) have speed boosting, then the Player class would be the place for it; otherwise, removing all speed boost code from the Player class and keep the code in the Mouse class. Move any speed boost methods not already in the Mouse class there before removing them from the Player class.
dERPscHNOzzLE dERPscHNOzzLE

2016/9/30

#
Thanks!! It works now
dERPscHNOzzLE dERPscHNOzzLE

2016/9/30

#
what about hitboxes because i dont have the slightest idea how to fix them
danpost danpost

2016/9/30

#
dERPscHNOzzLE wrote...
what about hitboxes because i dont have the slightest idea how to fix them
What is the issue with hitboxes? This was not mentioned previously in this discussion thread.
dERPscHNOzzLE dERPscHNOzzLE

2016/9/30

#
yeah sorry it was just another one of my problems, I just need to make work better, because sometimes my actor touches another actor and it doesnt work but then sometimes they're far away from each other and it says they touch
dERPscHNOzzLE dERPscHNOzzLE

2016/9/30

#
i was thinking i had to use getObjectsInRange but it didnt seem to work
dERPscHNOzzLE dERPscHNOzzLE

2016/9/30

#
it says incompatible types: java.util.List cannot be converted to greenfoot.Actor
danpost danpost

2016/9/30

#
dERPscHNOzzLE wrote...
it says incompatible types: java.util.List cannot be converted to greenfoot.Actor
Try using 'getOneIntersectingObject' instead of 'getObjectsInRange'.
You need to login to post a reply.
1
2