Skip to content

Commit f285f74

Browse files
committed
initial commit
0 parents  commit f285f74

File tree

172 files changed

+1729
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+1729
-0
lines changed

Ghost1.class

1.62 KB
Binary file not shown.

Ghost1.ctxt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#BlueJ class context
2+
comment0.target=Ghost1
3+
comment1.params=speed\ stopPointLeft\ stopPointRight
4+
comment1.target=Ghost1(int,\ int,\ int)
5+
comment2.params=
6+
comment2.target=void\ act()
7+
comment3.params=
8+
comment3.target=void\ moveHorizontally()
9+
comment4.params=
10+
comment4.target=void\ checkCollision()
11+
numComments=5

Ghost1.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import greenfoot.*;
2+
3+
public class Ghost1 extends Actor
4+
{
5+
private int speed;
6+
private boolean movingRight;
7+
private int stopPointLeft;
8+
private int stopPointRight;
9+
10+
public Ghost1(int speed, int stopPointLeft, int stopPointRight) {
11+
this.speed = speed;
12+
this.movingRight = true; // default ke kanan
13+
this.stopPointLeft = stopPointLeft;
14+
this.stopPointRight = stopPointRight;
15+
}
16+
17+
public void act()
18+
{
19+
if (getWorld() == null) {
20+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
21+
}
22+
checkCollision();
23+
if (getWorld() == null) {
24+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
25+
}
26+
moveHorizontally();
27+
}
28+
29+
public void moveHorizontally() {
30+
if (getWorld() == null) {
31+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
32+
}
33+
checkCollision();
34+
if (getWorld() == null) {
35+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
36+
}
37+
if (movingRight) {
38+
move(speed);
39+
if (isAtEdge() || isTouching(Platform2.class) || getX() >= stopPointRight) {
40+
movingRight = false;
41+
setImage("Ghost1-Run-Left.png");
42+
}
43+
} else {
44+
move(-speed);
45+
if (isAtEdge() || isTouching(Platform2.class) || getX() <= stopPointLeft) {
46+
movingRight = true;
47+
setImage("Ghost1-Run-Right.png");
48+
}
49+
}
50+
}
51+
52+
private void checkCollision() {
53+
skill1Charge skill1 = (skill1Charge) getOneIntersectingObject(skill1Charge.class);
54+
skill2Charge skill2 = (skill2Charge) getOneIntersectingObject(skill2Charge.class);
55+
if (skill1 != null) {
56+
Greenfoot.playSound("Magic-Explode.mp3");
57+
getWorld().removeObject(this);
58+
}
59+
if (skill2 != null) {
60+
Greenfoot.playSound("Magic-Explode.mp3");
61+
getWorld().removeObject(this);
62+
}
63+
}
64+
}

Ghost1Skill.class

320 Bytes
Binary file not shown.

Ghost1Skill.ctxt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#BlueJ class context
2+
comment0.target=Ghost1Skill
3+
comment1.params=
4+
comment1.target=void\ act()
5+
numComments=2

Ghost1Skill.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import greenfoot.*;
2+
3+
public class Ghost1Skill extends Actor
4+
{
5+
public void act()
6+
{
7+
8+
}
9+
}

Ghost2.class

1.62 KB
Binary file not shown.

Ghost2.ctxt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#BlueJ class context
2+
comment0.target=Ghost2
3+
comment1.params=speed\ stopPointLeft\ stopPointRight
4+
comment1.target=Ghost2(int,\ int,\ int)
5+
comment2.params=
6+
comment2.target=void\ act()
7+
comment3.params=
8+
comment3.target=void\ moveHorizontally()
9+
comment4.params=
10+
comment4.target=void\ checkCollision()
11+
numComments=5

Ghost2.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import greenfoot.*;
2+
3+
public class Ghost2 extends Actor
4+
{
5+
private int speed;
6+
private boolean movingRight;
7+
private int stopPointLeft;
8+
private int stopPointRight;
9+
10+
public Ghost2(int speed, int stopPointLeft, int stopPointRight) {
11+
this.speed = speed;
12+
this.movingRight = true; // default ke kanan
13+
this.stopPointLeft = stopPointLeft;
14+
this.stopPointRight = stopPointRight;
15+
}
16+
17+
public void act()
18+
{
19+
if (getWorld() == null) {
20+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
21+
}
22+
checkCollision();
23+
if (getWorld() == null) {
24+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
25+
}
26+
moveHorizontally();
27+
}
28+
29+
public void moveHorizontally() {
30+
if (getWorld() == null) {
31+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
32+
}
33+
checkCollision();
34+
if (getWorld() == null) {
35+
return; // Jika objek telah dihapus dari dunia, hentikan eksekusi
36+
}
37+
if (movingRight) {
38+
move(speed);
39+
if (isAtEdge() || isTouching(Platform2.class) || getX() >= stopPointRight) {
40+
movingRight = false;
41+
setImage("Ghost2-Walk-Left.png");
42+
}
43+
} else {
44+
move(-speed);
45+
if (isAtEdge() || isTouching(Platform2.class) || getX() <= stopPointLeft) {
46+
movingRight = true;
47+
setImage("Ghost2-Walk-Right.png");
48+
}
49+
}
50+
}
51+
52+
private void checkCollision() {
53+
skill1Charge skill1 = (skill1Charge) getOneIntersectingObject(skill1Charge.class);
54+
skill2Charge skill2 = (skill2Charge) getOneIntersectingObject(skill2Charge.class);
55+
if (skill1 != null) {
56+
Greenfoot.playSound("Magic-Explode.mp3");
57+
getWorld().removeObject(this);
58+
}
59+
if (skill2 != null) {
60+
Greenfoot.playSound("Magic-Explode.mp3");
61+
getWorld().removeObject(this);
62+
}
63+
}
64+
}

Level1.class

2.64 KB
Binary file not shown.

0 commit comments

Comments
 (0)