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

2016/1/23

make object disappear after 3 hits (take damage)

1
2
3
nico_vo nico_vo

2016/1/27

#
also, line 79, should make the explosion gif I also created, but as just after changing to be the explosion it's deleted, it's not visually shown.
danpost danpost

2016/1/27

#
What is your class structure from Actor to the PowerUp class (which classes extend what)?
nico_vo nico_vo

2016/1/27

#
they all extend the actor main class
danpost danpost

2016/1/27

#
The explosion image should not be set to the rocket actor. You should have an Explosion class which you can create an object from to replace the rocket actor in the world.
nico_vo nico_vo

2016/1/28

#
Ah, okay, thanks :)
nico_vo nico_vo

2016/1/28

#
how can I make it so that the rocket appears on the left when it goes through the right side and viceversa?
danpost danpost

2016/1/28

#
If, after moving, the rotation of the rocket is between 271 and 359 or between 0 and 89 (both inclusive) AND its x-coordinate indicates it is at the right edge of the world, then set its location to the left edge at the same y-coordinate of its location:
setLocation(0, getY());
nico_vo nico_vo

2016/1/28

#
danpost wrote...
If, after moving, the rotation of the rocket is between 271 and 359 or between 0 and 89 (both inclusive) AND its x-coordinate indicates it is at the right edge of the world, then set its location to the left edge at the same y-coordinate of its location:
setLocation(0, getY());
I've tried what you gave me, but it Works just for one side. This is the code I have and the problems with it: With this one, when I hit left side it works, but when I hit the right side, it doesn't work.
public void act()
{
if(getX() == 0){
            setLocation(400, getY()); 
        }
        if(getX() == 400){
            setLocation(0, getY());
        }
}
However, when I write getx() == 399 in the second "if" (as shown in code below), it happens the opposite: right side makes the rocket to go to the left, but left doesn't make rocket go to the right.
public void act()
{
        if(getX() == 0){
            setLocation(400, getY());
        }
        if(getX() == 399){
            setLocation(0, getY());
        }
}
Super_Hippo Super_Hippo

2016/1/28

#
Look what it does: Code 1: Your actor reached the left side (x=0). It enters the first if-block because line 3 returns true. Now the object gets teleported to x=400. Because of that, the second if-block is executed and it is teleported to the left side again (x=0). Next act cycle it starts again. Because it is teleported twice, you won't see it at the right side, it looks like it stays at the left side. Code 2: After teleporting to the right side, it stays there, because 400 is not 399. When teleporting to the left side (x=0), it will be teleported back the next act cycle. Problem about teleporting to the right side is, that it will be teleported to the left side again when it moves to the middle (1 cell). Does this work as it should?
public void act()
{
    if (getX() == 0)
    {
        setLocation(399, getY()); 
    }
    else if (getX() == 400)
    {
        setLocation(1, getY());
    }
}
nico_vo nico_vo

2016/1/28

#
Super_Hippo wrote...
Look what it does: Code 1: Your actor reached the left side (x=0). It enters the first if-block because line 3 returns true. Now the object gets teleported to x=400. Because of that, the second if-block is executed and it is teleported to the left side again (x=0). Next act cycle it starts again. Because it is teleported twice, you won't see it at the right side, it looks like it stays at the left side. Code 2: After teleporting to the right side, it stays there, because 400 is not 399. When teleporting to the left side (x=0), it will be teleported back the next act cycle. Problem about teleporting to the right side is, that it will be teleported to the left side again when it moves to the middle (1 cell). Does this work as it should?
public void act()
{
    if (getX() == 0)
    {
        setLocation(399, getY()); 
    }
    else if (getX() == 400)
    {
        setLocation(1, getY());
    }
}
nope, just works from left to right. I tried also removing one number more, but nothing :/
Super_Hippo Super_Hippo

2016/1/28

#
How big is your world? In other words, does this work?
public void act()
{
    int x = getWorld().getWidth();
    if (getX() == 0)
    {
        setLocation(x-2, getY()); 
    }
    else if (getX() == x-1)
    {
        setLocation(1, getY());
    }
}
nico_vo nico_vo

2016/1/28

#
it's 400 (width) x 600 (height)
nico_vo nico_vo

2016/1/28

#
Super_Hippo wrote...
How big is your world? In other words, does this work?
public void act()
{
    int x = getWorld().getWidth();
    if (getX() == 0)
    {
        setLocation(x-2, getY()); 
    }
    else if (getX() == x-1)
    {
        setLocation(1, getY());
    }
}
It worked! thank you for your apport :)
nico_vo nico_vo

2016/1/28

#
now I want to do the cooldown for the shots, so that they don't get shot once each act cycle. Any ideas? I don't know how to start that :S
danpost danpost

2016/1/29

#
nico_vo wrote...
now I want to do the cooldown for the shots, so that they don't get shot once each act cycle. Any ideas? I don't know how to start that :S
You just need a field to count down some number of act methods. Check for shooting if zero, else decrement it.
There are more replies on the next page.
1
2
3