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

#
Where do you call it from? (show me)
-nic- -nic-

2012/10/9

#
fire is called every time you press the mouse
public void fire()
    {
        Bullet b = new Bullet();
        getWorld().addObject(b,getX(),getY());
        shell s= new shell();
        getWorld().addObject(s,getX(),getY());
        s.fall();
        b.setRotation(getRotation());
        b.move(20);
    }
danpost danpost

2012/10/9

#
OK (that was not there before). I was just wondering why you would have the shell direct itself to a specific area through random choice; instead of letting it move with some random angle to wherever it ends up.
-nic- -nic-

2012/10/9

#
ive got this
public void fall()
    {
        int r=Greenfoot.getRandomNumber(60);
        setRotation(60+r);
        
        
        
    }
-nic- -nic-

2012/10/9

#
i shared the scenario fun
danpost danpost

2012/10/9

#
Adding the following to the Shell class should allow the shells to fall in different directions:
// instance variables
double realX, realY;
// method addedToWorld(World world)
public void addedToWorld(World world)
{
    realX = (double) getX();
    realY = (double) getY();
}
// method move()
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));
}
Just change 'move(1);' in your act() method to 'move();'.
danpost danpost

2012/10/9

#
Edited the previous post in this discussion to include the addedToWorld(World world) method.
-nic- -nic-

2012/10/9

#
it doesent fall it goes to the top left of the screen and slowly moves right see www.greenfoot.org/scenarios/6076
danpost danpost

2012/10/9

#
Please refer to my last post on this discussion.
-nic- -nic-

2012/10/9

#
now it goes from the starting postion and goes forward in a straght line
danpost danpost

2012/10/9

#
I made those exact changes in my downloaded Fun scenario and they drop in different directions and then follow the bottom edge left or right until a corner is reached (unless it drops straight down to begin with; in which case, it does not move along the bottom edge at all).
-nic- -nic-

2012/10/9

#
ok ill add code to remove the shell but im not surr whative done
danpost danpost

2012/10/9

#
I was referring to the falling movement of the shells. That has nothing to do with the possible removal of them. Did you get the falling of them fixed? or not!
-nic- -nic-

2012/10/9

#
can you paste the source cod efor the shell class please
-nic- -nic-

2012/10/9

#
i still havent got the falling working
There are more replies on the next page.
1
2
3
4