![]() If (x >= myWorld.getWidth() || y >= myWorld. SetLocation(getX() - moveAmount, getY()) SetLocation(getX(), getY() - moveAmount) SetLocation(getX() + moveAmount, getY()) ![]() SetLocation(getX(), getY() + moveAmount) * Move one cell forward in the current direction. Check whether there is a leaf in the same cell as we are.Īctor leaf = getOneObjectAtOffset(0, 0, Leaf.class) ("myWorld.getHeight() :" + myWorld.getHeight()) ("myWorld.getWidth() :" + myWorld.getWidth()) this allows us to get the width and height of the world Int flipACoin = (int)(randD *2) //this multiplies the random decimal by two then cuts of the decimal here is the method that you can use to set the original locationĭouble randD = Math.random() //between 0 and. addObject(new Orange(), Greenfoot.getRandomNumber(600), 0) The in the orange class we have made the orange to move down so that it gives a feel of oranges falling from the sky and at the bottom the oranges should not get collected hence they are removed from the world as soon as they reach the bottom edge of the world. A Wombat moves forward until it can't do so anymore, at Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) Run the code and try to learn from what's printed out. Greenfoot Chapter 2 Solutions Use as a checklist for the activities in the. Copy and paste all of the code below into the class. Part 2 of the Greenfoot Tutorial for the Eduqas / WJEC GCSE 2016 specification. Using move () along with mouseinfo, you can use your mouse to move instead. You can also make things follow the mouse. For instance, you can get the mouse x and y coordinates of where you clicked or last click. Now if you store this in a int, you can do all sorts of things. Use methods such as isKeyDown, setRotation and move. To get information on a mouse click, you use Greenfoot.getMouseInfo (). move(int distance) This makes an object move a. ![]() This sets the rotation of an object to 90 degrees i.e. setRotation(90) written in an Actor object. If (Greenfoot.My Students: create a new subclass of Actor called person. Learn how to edit code in Greenfoot to make objects move using the arrow keys. Greenfoot Cheat Sheet Aims Useful Methods Method Purpose Example Explanation setRotation(int rotation) Sets the rotation of an object. * The attribute isKeyDown is used to prevent setting the headlights on and off when the key "space" is pressed (and remains pressed for some time) * Turn the headlights on when the key "space" is pressed. * Turn the car to the right every time the key "right" is pressed * Turn the car to the left every time the key "left" is pressed * Move the car back every time the key "down" is pressed * Move the car forward every time the key "up" is pressed * Method that is being always invoked when the program is running Sets the image that appears in the screen at the beginning to the one in file1 SetImage2(file2) // Sets the attribute image2 to file2 SetImage1(file1) // Sets the attribute image1 to file1 * Class that models objects of type "car" I would like to make something like ("up") and ("w") for moveForward(), ("down") and ("s") for moveBack() etc. Greenfoot requires a capital G and the isKeyDown method most be written with a lowercase i but uppercase K and D. Exercise 1.2 Invoke the move() method on a wombat. Your code must be perfect or it wont work. I would like to move two cars differently one using "up", "down", "left", "right" for the car1 and "w", "s", "a", "d" respectively. Start Greenfoot and open the scenario leaves-and-wombats from the Greenfoot book scenarios folder.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |