

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. A Wombat moves forward until it can't do so anymore, at Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot)
#Getworld greenfoot code
Run the code and try to learn from what's printed out. Copy and paste all of the code below into the class. SetImage("Wraith_01_Idle Blinking_00" +animateImage + "(try).My Students: create a new subclass of Actor called person. SetImage("Wraith_01_Idle Blinking_00" +animateImage + "(try).png") GetWorld().addObject(fireball, getX()-100, getY()) //masukkan fireball ke dalam world dan berjarak 100 pixels dari wraith GetWorld().addObject(fireball, getX()+100, getY()) //masukkan fireball ke dalam world dan berjarak 100 pixels dari wraith SetImage("Wraith_01_Moving Forward_00" + animateImage + "(try).png") GetWorld().addObject(specialattack, getX()-100, getY()) SetRotation(specialattack.getRotation()*-1) GetWorld().addObject(specialattack, getX()+100, getY()) SpecialAttack specialattack = new SpecialAttack() Section 3 Quiz 1 - L1-L5 (Answer all questions in this section) 1. If(!up & !down & !left & !right & !space & !j) //no button is pressed If(Greenfoot.isKeyDown("j")& spaceTimer.millisElapsed() >600) //special attack powerīoolean right = Greenfoot.isKeyDown("d") īoolean space = Greenfoot.isKeyDown("space") SpaceTimer.mark() //reset balik timer kepada 0 SetImage("Wraith_01_Casting Spells_006.png") for movement restrict of wraith in the world SetImage("Wraith_01_Idle Blinking_000(try).png") SimpleTimer spaceTimer = new SimpleTimer() //timer for when the next space can be tekan lagi Int direction =1 //direction which actor facing Int animateSpeed3 = 1 //speed for shooting animation This code sends the value of leaf, as a parameter value, to the getWorld. Int animateSpeed2 = 6 //lower the animate speed for faster idle animation The Greenfoot class provides methods to control the movement in a game. Int animateSpeed = 2 //lower the animate speed for faster walking animation //3 Int animateImage = 0 //for walking animation image (frame) Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) GetWorld().showText("You Lose! - You lasted " +(gameTime/60) + " seconds", getWorld().getWidth()/2, getWorld().getHeight()/2) GetWorld().addObject(halfbar, getWorld().getWidth()/3, getWorld().getHeight()/3) If((zombie1eat != null & getNeighbours(getImage().getWidth()/2, false, Zombie1.class).contains(zombie1eat) & zombie1eat.Eat(this)) || (zombie1eatR != null & getNeighbours(getImage().getWidth()/2, false, Zombie1R.class).contains(zombie1eatR) & zombie1eatR.Eat(this)) || (zombie2eat != null & getNeighbours(getImage().getWidth(), false, Zombie2.class).contains(zombie2eat) & zombie2eat.Eat(this)) || (zombie2eatR != null & getNeighbours(getImage().getWidth(), false, Zombie2R.class).contains(zombie2eatR) & zombie2eatR.Eat(this))) Zombie2R zombie2eatR = (Zombie2R)getOneIntersectingObject(Zombie2R.class) Zombie2 zombie2eat = (Zombie2)getOneIntersectingObject(Zombie2.class) Zombie1R zombie1eatR = (Zombie1R)getOneIntersectingObject(Zombie1R.class) Zombie1 zombie1eat = (Zombie1)getOneIntersectingObject(Zombie1.class)
