-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButterfly.java
More file actions
57 lines (57 loc) · 1.97 KB
/
Copy pathButterfly.java
File metadata and controls
57 lines (57 loc) · 1.97 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Hawk here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Butterfly extends Actor
{
/**
* Act - do whatever the Hawk wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public static int laserButterfly = 10;
public void act(){
int dx = getImage().getWidth()/4;
// Add your action code here.
if(Greenfoot.isKeyDown("p")){
dx = 0;
}else{
if(getX() + getImage().getWidth()/2 >= getWorld().getWidth() && getRotation() == 0) {
turn(90);
move(getImage().getHeight());
turn(90);
} else if(getX() - getImage().getWidth()/2 <= 0 && getRotation() == 180) {
turn(-90);
move(getImage().getHeight());
turn(-90);
} else if(isTouching(Mushroom.class)){
move(-dx);
if (getRotation() == 0) {
turn(90);
move(getImage().getHeight());
turn(90);
} else {
turn(-90);
move(getImage().getHeight());
turn(-90);
}
} else {
move(dx);
}
if(isTouching(Laser.class)){
Mushroom m = new Mushroom();
m.getImage().scale(20,20);
getWorld().addObject(m, getX(), getY());
removeTouching(Laser.class);
getWorld().removeObject(this);
laserButterfly--;
}else if(getY() > getWorld().getHeight()){
getWorld().removeObject(this);
}else if (isTouching(Player.class)) {
getWorld().removeObjects(getWorld().getObjects(Player.class));
}
}
}
}