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

2012/10/8

Getting a random falling shell

1
2
3
4
danpost danpost

2012/10/9

#
This is what I have in the Shell class:
import greenfoot.*;

public class shell extends Animal
{
    double realX, realY;
    
    public void addedToWorld(World world)
    {
        realX = (double) getX();
        realY = (double) getY();
    }
    
    public void act() 
    {
        move();       
    } 

    public void fall()
    {
        int r=Greenfoot.getRandomNumber(60);
        setRotation(60+r);
    }
    
    public void move()
    {
        realX += Math.cos(getRotation() * Math.PI / 180);
        realY += Math.sin(getRotation() * Math.PI / 180);
        setLocation((int) Math.round(realX), (int) Math.round(realY));
    }
}
-nic- -nic-

2012/10/9

#
ok its not that
-nic- -nic-

2012/10/9

#
did you edit anything in the world?
danpost danpost

2012/10/9

#
The shell class does not need to extend Animal; it can extend Actor since it has its own move method.
-nic- -nic-

2012/10/9

#
true
danpost danpost

2012/10/9

#
No, I did not change anything in the world, or elsewhere for that matter.
-nic- -nic-

2012/10/9

#
i added the removel of the shell but the shell still moves forward
-nic- -nic-

2012/10/9

#
ill look
-nic- -nic-

2012/10/9

#
ok i wassuch a fool and i removed some code that was needed but thank you soo much and im again sorry
danpost danpost

2012/10/9

#
Does that mean you now have the falling of the shells working properly now?
-nic- -nic-

2012/10/9

#
yes sorry i was being a fool
-nic- -nic-

2012/10/10

#
is there a way using the code that you showed in the (move() method) to make object move quicker? Forget That ive got a way
danpost danpost

2012/10/10

#
Just multiply in lines 26 and 27 by any double greater than one.
Game/maniac Game/maniac

2012/10/10

#
this works better:
import greenfoot.*;     
public class shell extends Animal  
{
    int gravity=1;
    int vSpeed=5;
    int i=0;
    public void act()
    {
        turn(20);
        eject();
        if(atWorldEdge()){getWorld().removeObject(this);}
    }
    public void eject()
    {
        setLocation(getX(),getY()-vSpeed);
        timer(2);
    }
    public void timer(int time)  
    {  
        i++;  
        if(i==time)  
        vSpeed-=gravity;  
        if(i==time+1)  
        i=0;  
    }
}
-nic- -nic-

2012/10/10

#
its great and what im looking for thanks
There are more replies on the next page.
1
2
3
4