Skip to content

Commit

Permalink
new function for mob
Browse files Browse the repository at this point in the history
  • Loading branch information
danielzzhuang committed Jun 11, 2024
1 parent 44b4bed commit ef9bc6e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
1 change: 1 addition & 0 deletions Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void addedToWorld(World w) {

@Override
public void act() {
super.act();
attack();
collision();
}
Expand Down
14 changes: 1 addition & 13 deletions Coin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
*/
public class Coin extends Collection
{
private GreenfootImage image;

public Coin(){
image = new GreenfootImage("marioCoin.png");
image.scale(45,55);
setImage(image);
}


/**
* Act - do whatever the Coin wants to do. This method is called whenever
Expand All @@ -29,10 +23,4 @@ public void act()
}
}

public boolean isBeingTouched(){
if (isTouching(Player.class)){
return true;
}
return false;
}
}
5 changes: 4 additions & 1 deletion Crown.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class Crown extends Collection
*/
public void act()
{
// Add your action code here.
if (isTouching(Player.class)){
getWorld().removeObject(this);
Level.addCrown();
}
}
}
11 changes: 8 additions & 3 deletions Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Level extends World {
private Font font = new Font("Arial", 18);
protected SuperDisplayLabel coinLabel = new SuperDisplayLabel(Color.BLACK, Color.WHITE, font);
protected static int totalCoins = 0;

protected static int numOfCrown=0;
public Level() {
super(1280, 720, 1, false);
scroll = new ImgScroll(this, new GreenfootImage(background), worldSize[0], worldSize[1]);
Expand Down Expand Up @@ -47,7 +47,10 @@ public void spawnTerrain(int[][] identifier) {
addObject(orb = new Orb(), i * 64, j * 64);
}
if (identifier[i][j] == 3) {
addObject(new Coin(), i * 64, j * 72);
addObject(new Coin(), i * 64, j * 64);
}
if (identifier[i][j] == 4) {
addObject(new Crown(), i * 64, j * 64);
}
}
}
Expand All @@ -70,7 +73,9 @@ public int[] getMapBoundary() {
mapBoundary[1] = scroll.getScrollWidth() + scroll.getScrolledX();
return mapBoundary;
}

public static void addCrown(){
numOfCrown++;
}
public static void addToTotalCoin(){
totalCoins++;
}
Expand Down
2 changes: 1 addition & 1 deletion Level0.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Level0() {
blockGeneration[11][5] = 1;
blockGeneration[12][5] = 1;
blockGeneration[28][5] = 1;
blockGeneration[10][6] = 2;
blockGeneration[20][6] = 2;
blockGeneration[10][9] = 1;
blockGeneration[5][7] = 1;
blockGeneration[5][8] = 3;
Expand Down
10 changes: 8 additions & 2 deletions Mobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public Mobs() {
public void addedToWorld(World w) {
this.w = w;
}

public void act(){
stepped();
}

private void gravity() {
if (!isTouching(Brick.class)) {
Expand Down Expand Up @@ -92,7 +94,11 @@ public Player getPlayer(int range) {
}
return null;
}

public void stepped(){
if(getOneObjectAtOffset(getX(), getY()-1, Player.class)!=null){
getWorld().removeObject(this);
}
}
public void attack() {
Player p = (Player) getOneIntersectingObject(Player.class);
if (p == null) {
Expand Down
1 change: 1 addition & 0 deletions RedBee.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void act() {
} else {
idle();
}

}


Expand Down
1 change: 1 addition & 0 deletions Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void act() {
}
attack();
timeout();
super.act();
}

protected void movement() {
Expand Down

0 comments on commit ef9bc6e

Please sign in to comment.