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

2015/10/21

Make the lighthouses move up and down continuously.

grimancepizza grimancepizza

2015/10/21

#
The top lighthouse should move downward, and when it is the same level as the initial level of the bottom lighthouse, it should start moving upward, and so on.The bottom lighthouse should move upward, and when it is the same level as the initial level of the top lighthouse, it should start moving downward, and so on.
grimancepizza grimancepizza

2015/10/21

#
I started with this... public void act() { if (getY()-getImage().getHeight() >= 0) { setLocation(getX(), getY() + 4); } } is it correct?
danpost danpost

2015/10/21

#
The code given will only have the actor move down the screen if, and only if, there is a gap of a least half the height of the image of the actor between the top edge of the world and the image of the actor. If you are to have your actor move both up and down the screen alternatively, you need to track which direction it is currently moving. Then, you can use that with the y-coordinate of the actors location to determine when to switch directions. Since movement will be both in a positive and a negative direction, an int field can be used whose value can alternate between positive one and negative one (requiring only a negation of its value to change directions). Its value can be multiplied by the vertical speed of the actor for movement. Since the speed is four:
setLocation(getX(), getY()+direction*4);
When the y-coordinate (the returned value of 'getX') is at the higher limit and its value is increasing, or if it is at the lower limit and its value is decreasing, then, negate the value of the direction field.
AngelusNeko13 AngelusNeko13

2015/10/21

#
hey guys this may seem unrelated but can anyone show me how to make cars collide and make a sound before ending the game after you collide into them? im making a game where you dodge traffic while going up the road (kinda like spy hunter) but when i put this code nothing happened when the car touched the traffic, can anyone show me why? heres my code:
  
public void checkCollision()
    {
        
       Actor Car = getOneIntersectingObject(Vehicle.class);
        
        if(Car != null)
        
        {
            Greenfoot.playSound("crash.wav");
            Greenfoot.stop();
            
        }
    }
AngelusNeko13 AngelusNeko13

2015/10/21

#
btw the car is the character you control and the vehicle class is the traffic
You need to login to post a reply.