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

2021/10/13

After Car reaches bottom, how do I get it to the top in a different color? to simulate traffic?

ethanbf ethanbf

2021/10/13

#
Doing a school porject, I need the car to reach the bottom of the screen then disappear then return to the top as another color to simulate the illusion of traffic. Then the car must turn 90 degrees and then return next to it as another car. I have the car moving down so far here is the car actor class code. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Car here. * * @author (your name) * @version (a version number or a date) */ public class Car extends Actor { /** * Act - do whatever the Car wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(5); turnTowards(600,600); lookforPlayer(); } public void move() { move(5); turn(180); } public void turnTowards() { setRotation(90); } public void lookforPlayer() { if ( isTouching(Player.class) ) { removeTouching(Player.class); Greenfoot.playSound("splat.mp3"); Greenfoot.stop(); } } }
danpost danpost

2021/10/13

#
When turning around:
setImage(new GreenfootImage("car0"+(1+Greenfoot.getRandomNumber(3))+".png"));
("car01.png", "car02.png" and "car03.png" images must be imported into your "images" folder for that scenario)
ethanbf ethanbf

2021/10/13

#
i saw you dishing out help and am truly blessed to have your response, thank you so much!
You need to login to post a reply.