Skip to content

Commit

Permalink
Merge pull request #30 from Adrian400811/Dz1
Browse files Browse the repository at this point in the history
new function for mobs
  • Loading branch information
reihoron authored Jun 12, 2024
2 parents f8683b7 + 4acc4f9 commit 870b95d
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 95 deletions.
2 changes: 2 additions & 0 deletions Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public void addedToWorld(World w) {

@Override
public void 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
3 changes: 2 additions & 1 deletion Coin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public class Coin extends Collection {

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

}

/**
Expand Down
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();
}
}
}
5 changes: 4 additions & 1 deletion 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,7 +25,9 @@ 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() + 64; i += 63) {
Expand Down
10 changes: 8 additions & 2 deletions Mobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 @@ -108,7 +110,11 @@ public Player getPlayer(int range) {
}
return null;
}

public void stepped(){
if(getOneObjectAtOffset(getX(), -(getImage().getHeight()/2), Player.class)!=null){
getWorld().removeObject(this);
}
}
public void attack() {
Player p = (Player) getOneIntersectingObject(Player.class);
if (p == null) {
Expand Down
3 changes: 2 additions & 1 deletion RedBee.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +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
3 changes: 2 additions & 1 deletion Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void act() {
}
attack();
timeout();
super.act();
}

protected void movement() {
Expand Down Expand Up @@ -73,7 +74,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
Binary file added images/marioCoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 870b95d

Please sign in to comment.