Skip to content

Commit

Permalink
Added BlueSpider and RedSpider
Browse files Browse the repository at this point in the history
Added healing for RedSpider
  • Loading branch information
reihoron committed Jun 9, 2024
1 parent 97ac28e commit b763c41
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
18 changes: 18 additions & 0 deletions BlueSpider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import greenfoot.World;

public class BlueSpider extends Spider {
private World w;

public BlueSpider() {
super();
}

public void addedToWorld(World w) {
this.w = w;
}

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

}
27 changes: 27 additions & 0 deletions RedSpider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import greenfoot.World;

import java.util.Objects;

public class RedSpider extends Spider {
private World w;

public RedSpider() {
super();
healPlayer();
}

public void addedToWorld(World w) {
this.w = w;
}

private void healPlayer() {
if (w == null) {
return;
}
Player topL = (Player) getOneObjectAtOffset(-(getImage().getWidth() / 2), getImage().getHeight() / 2, Player.class);
Player topR = (Player) getOneObjectAtOffset(getImage().getWidth() / 2, getImage().getHeight() / 2, Player.class);
if (topL != null || topR != null) {
Objects.requireNonNullElse(topL, topR).changeHP(+1);
}
}
}
9 changes: 4 additions & 5 deletions Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ public class Spider extends Mobs {
private final int hp;
private final double speed;
private final int dmg;
public World w;
long startTime;
long elapsedTime;
boolean oob = false;
private World w;
private long startTime;
private boolean oob = false;

public Spider() {
hp = 2;
Expand Down Expand Up @@ -35,7 +34,7 @@ public void timeout() {
oob = false;
}
if (oob) {
elapsedTime = System.currentTimeMillis() - startTime;
long elapsedTime = System.currentTimeMillis() - startTime;
if (elapsedTime > 10 * 1000) {
w.removeObject(this);
}
Expand Down

0 comments on commit b763c41

Please sign in to comment.