-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGround.java
98 lines (91 loc) · 2.11 KB
/
Ground.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
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ground here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ground extends Actor
{
private int side;
private int trans;
private int swich;
/**
* Ground Constructor
* Initialize the value for all the variable in this class
*/
public Ground(){
side = 1;
trans = 255;
swich = 0;
}
/**
* Act - do whatever the Ground wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
movement();
touchingEdge();
SetTrans();
}
/**
* Method SetTrans
* Change the Transparency
* From 225 - 0 than 0 - 225
*/
public void SetTrans(){
if(swich == 0){
trans += 1;
if(trans > 255){
swich = 1;
trans = 255;
}
getImage().setTransparency(trans);
}else{
getImage().setTransparency(trans);
trans -= 1;
if(trans < 0){
swich = 0;
trans = 0;
}
}
}
/**
* Method movement
* Make the Ground move back and forth
*/
public void movement(){
if(side == 1){
move(5);
}else{
move(-5);
}
}
/**
* Method touchingEdge
* Keep track of the ground for which side it should be move right now
*/
public void touchingEdge(){
if(isAtEdge()){
switch(side){
case 1:
side = 0;
break;
case 0:
side = 1;
break;
}
}
}
/**
* Method getSide
*
* Return what side the Ground are moving right now
* then when the player stand on this object it can follow this to move around
*/
public int getSide(){
return side;
}
}