Skip to content

Commit

Permalink
new function for mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielzzhuang committed Jun 11, 2024
1 parent 144d006 commit f6e2962
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public void addedToWorld(World w) {

@Override
public void act() {
super.act();

attack();
collision();
super.act();
}
}
3 changes: 2 additions & 1 deletion BlueBee.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public void addedToWorld(World w) {
}

public void act() {
super.act();

movement();
collision();
super.act();
}

private void movement() {
Expand Down
12 changes: 5 additions & 7 deletions Coin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
* @author (your name)
* @version (a version number or a date)
*/
public class Coin extends Actor {
public class Coin extends Collection {
private GreenfootImage image;

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

}

/**
Expand All @@ -25,9 +26,6 @@ public void act() {
getWorld().removeObject(this);
Level.addToTotalCoin();
}
}

public boolean isBeingTouched() {
return isTouching(Player.class);

}
}
7 changes: 5 additions & 2 deletions Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class Level extends World {
protected static int totalCoins = 0;
protected static int numOfCrown=0;
private final int[] worldSize = {2560, 720};
private final String background = "2dPixelForestBackground.png";
private final Font font = new Font("Arial", 18);
Expand All @@ -24,10 +25,12 @@ public Level() {
public static void addToTotalCoin() {
totalCoins++;
}

public static void addCrown(){
numOfCrown++;
}
public void spawnFloor(ImgScroll sc) {
for (int j = 0; j < sc.getScrollHeight() - 100; j += 300) {
for (int i = 0; i < sc.getScrollWidth(); i += 63) {
for (int i = 0; i < sc.getScrollWidth()+64; i += 63) {
addObject(new Brick(), i, 700);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Player getPlayer(int range) {
return null;
}
public void stepped(){
if(getOneObjectAtOffset(getX(), getY()-1, Player.class)!=null){
if(getOneObjectAtOffset(getX(), -(getImage().getHeight()/2), Player.class)!=null){
getWorld().removeObject(this);
}
}
Expand Down
4 changes: 2 additions & 2 deletions RedBee.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public RedBee(int range) {

@Override
public void act() {
super.act();

curSpeed = speed;
if (getPlayer(range) != null) {
sprint();
} else {
idle();
}

super.act();
}


Expand Down
2 changes: 1 addition & 1 deletion Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void timeout() {
}
if (oob) {
long elapsedTime = System.currentTimeMillis() - startTime;
if (elapsedTime > 10 * 1000) {
if (elapsedTime > 10 * 1000 && getWorld() != null) {
w.removeObject(this);
}
}
Expand Down

0 comments on commit f6e2962

Please sign in to comment.