-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMushroom.java
More file actions
executable file
·104 lines (87 loc) · 3.05 KB
/
Copy pathMushroom.java
File metadata and controls
executable file
·104 lines (87 loc) · 3.05 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
* Base Mushroom class, class for default mushroom
*
* @author Bill Xiang
* @version 2.0
*/
public class Mushroom extends Actor
{
public Mushroom() {
}
protected int numHits = 0;
protected int hitCapacity = 4;
protected int scoreValue = 1;
public int level = 0;
public void act()
{
onHit();
specialActiveBehavior();
}
public void onHit() {
if (isTouching(Laser.class) == true) {
numHits++;
removeTouching(Laser.class);
specialHitBehavior();
if (numHits >= hitCapacity) {
List scoreList = getWorld().getObjects(Score.class);
Score score = (Score)scoreList.get(0);
score.setScore(score.getScore()+scoreValue);
specialEndBehavior();
} else {
//getImage().scale(getImage().getWidth(), getImage().getHeight()/2);
changeImage();
}
}
}
public void specialActiveBehavior() {
if (numHits == 0) {
GreenfootImage image = new GreenfootImage((level + 1) + "Mushroom_001.png");
int gridSize = ((MyWorld)getWorld()).GRID_SIZE;
image.scale(gridSize, gridSize);
setImage(image);
} else if (numHits == 1) {
GreenfootImage image = new GreenfootImage((level + 1) + "Mushroom_002.png");
int gridSize = ((MyWorld)getWorld()).GRID_SIZE;
image.scale(gridSize, gridSize);
setImage(image);
} else if (numHits == 2) {
GreenfootImage image = new GreenfootImage((level + 1) + "Mushroom_003.png");
int gridSize = ((MyWorld)getWorld()).GRID_SIZE;
image.scale(gridSize, gridSize);
setImage(image);
} else if (numHits == 3) {
GreenfootImage image = new GreenfootImage((level + 1) + "Mushroom_004.png");
int gridSize = ((MyWorld)getWorld()).GRID_SIZE;
image.scale(gridSize, gridSize);
setImage(image);
}
}
public void specialHitBehavior() {
}
public void specialEndBehavior() {
getWorld().removeObject(this);
}
public void changeImage() {
/*
GreenfootImage image = null;
if (numHits == 1) {
image = new GreenfootImage((level + 1) + "Mushroom_002.png");
} else if (numHits == 2) {
image = new GreenfootImage((level + 1) + "Mushroom_003.png");
} else if (numHits == 3) {
image = new GreenfootImage((level + 1) + "Mushroom_004.png");
}
int gridSize = ((MyWorld)getWorld()).GRID_SIZE;
image.scale(gridSize, gridSize);
setImage(image);
*/
}
public int getScoreValue() {
return scoreValue;
}
public void setScoreValue(int scoreValue) {
this.scoreValue = scoreValue;
}
}