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

2012/8/12

turning on impact

1
2
davemib123 davemib123

2012/8/12

#
Hi guys, i'm trying to accomplish the following: Hero get hit with missile Hero turn + 5 Hero turn - 10 Hero return back to normal position Any ideas on how this would be implemented?
SPower SPower

2012/8/12

#
The last 2nd and 3rd are simple:
// in the Hero class, to turn 5 degrees
turn(5);
// in the Hero class, to turn 10 degrees to the left
turn(-10);
but I've got some questions about the 1st and the last one: - What should be implemented about getting hit with a Missle? The dying system, or something else? - What was the original position? If you don't know that, you'll never get back to it :)
davemib123 davemib123

2012/8/12

#
This is within the missile code:
public void checkHeroCollision(){
        Actor collided = getOneIntersectingObject(Hero.class);
        if (collided != null){
            getWorld().addObject(new explosionSmall(), getX(), getY());
            getWorld().removeObject(this);
            collided.turn(-10);
            return;
        } else {
            if (getX() <= - outOfBoundary) {
                getWorld().removeObject(this);
            } 
        }
    }
This is what it is doing right now: http://www.greenfoot.org/scenarios/5799
SPower SPower

2012/8/12

#
In the Hero class:
public void applyDamage(Missile missile)
{
    // something like life -= missile.getDamage();
}
In the Missile class:
public int getDamage()
{
    // return something
}
change this to the code you gave:
public void checkHeroCollision() {  
        Hero collided = (Hero) getOneIntersectingObject(Hero.class);
        if (collided != null){
            collided.applyDamage(this);
            // the rest
davemib123 davemib123

2012/8/12

#
not getting much luck with this, I get this error in the compiler:
cannot find symbol - method shake (Missiles)
SPower SPower

2012/8/12

#
where are you using the method 'shake'?
davemib123 davemib123

2012/8/12

#
in the enemy missile class. I was thinking of attempting it possibly this way. I have the bullet impact with the Hero and this sets the Hero to rotate -25 Now the question is for the Hero how would I set this back to 0 if the rotation has gone to -25. I tried this in the hero but didnt work:
public void shake(){
        if (getRotation(this) >= -25){
            setRotation(0);
        }
}
SPower SPower

2012/8/12

#
this should work:
public void shake()
{
     if (getRotation()>= -25) {
            setRotation(0);
     }
}
the getRotation takes no arguments. A little advice, I see you making the 2 methods you gave me public, but if you don't need to call that method from some other object, it can be private.
SPower SPower

2012/8/12

#
Also another question: at which line is the error?
davemib123 davemib123

2012/8/12

#
OK no error now, but it moves back to normal far too quick any way of slowing down. I used the word "this" in getRotation which generated the error.
SPower SPower

2012/8/12

#
You want to build in a delay. This is a simple way:
private int turnDelay = 0;
in your act:
turnDelay++;
change schake:
public void shake()  
{
     // 20 can be changed later on, I don't know what will work
     if (getRotation()>= -25 && turnDelay >= 20) {  
           setRotation(0);
     }  
}  
this is one way, but the other way is easier: don't turn 25 degrees immediately, turn 2 or something like that.
davemib123 davemib123

2012/8/12

#
could you expand on the second option?
SPower SPower

2012/8/12

#
Instead of something like this:
turn(-25);
do this a few times (in act):
turn(-1);
do you understand?
davemib123 davemib123

2012/8/12

#
thanks for the tips SPower. But it is not working as I want it to .... will come back to this at a later date :)
davemib123 davemib123

2012/8/12

#
tried something different - what do you think? It's not smooth but it does shake ....
There are more replies on the next page.
1
2