-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWalrusSnowball.java
More file actions
43 lines (35 loc) · 1.32 KB
/
Copy pathWalrusSnowball.java
File metadata and controls
43 lines (35 loc) · 1.32 KB
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
36
37
38
39
40
41
42
43
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class WalrusSnowball extends Actor
{
int WalrusSnowballRemoved = 0;
public WalrusSnowball()
{
setImage("snowball.png");
GreenfootImage image = getImage();
image.scale(image.getWidth() / 8, image.getHeight() / 8);
setImage(image);
}
public void act()
{
move(10);
Pingu location = (Pingu)getWorld().getObjects(Pingu.class).get(0);
turnTowards(location.getX(), location.getY());
WalrusSnowballRemoved = 0;
Actor wallCell = getOneIntersectingObject(Wall.class);
if (wallCell !=null)
{
getWorld().removeObject(this);
WalrusSnowballRemoved = 1;
}
if (WalrusSnowballRemoved == 0)
{
Actor touchingPingu = getOneIntersectingObject(Pingu.class);
if (touchingPingu !=null)
{
getWorld().removeObject(this);
touchingPingu.setLocation(38, 203);
Greenfoot.setWorld(new Level2());
}
}
}
}