-
Notifications
You must be signed in to change notification settings - Fork 0
/
baby3.java
35 lines (31 loc) · 1.08 KB
/
baby3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class baby3 here.
*
* @authors (Teodor Grigor & Scott Turner)
* @version (v1.0)
*/
public class baby3 extends Actor
{
//method that is called when the run or act button is pressed
//method that draw the actor
public void act()
{
//getting the class of the holder world - MyWorld
World world = getWorld();
MyWorld myWorld = (MyWorld)world;
//getting the speed of the babies from the myWorld
int babySpeed = myWorld.getBabySpeed();
//getting the ball class and store it into a variable
Actor ball = (Actor)getWorld().getObjects(ball1.class).get(0);
//moving the baby towards the ball
if(ball.getY() > getY()) {
setLocation(getX(), getY() + babySpeed);
} else {
if(getY() > 200) {
//move the baby only to the half of the screen
setLocation(getX(), getY() - babySpeed);
}
}
}
}