Skip to content

Commit

Permalink
Finished Spider movement
Browse files Browse the repository at this point in the history
  • Loading branch information
reihoron committed Jun 10, 2024
1 parent b889e35 commit fd239ff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
1 change: 0 additions & 1 deletion BlueSpider.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public void addedToWorld(World w) {

public void act() {
super.act();
super.movement();
}
}
2 changes: 1 addition & 1 deletion Level0.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Level0() {
int[][] mobGeneration = new int[40][10];
addObject(new BlueBee(), 800, 600);
addObject(new RedBee(), 100, 600);
addObject(new Spider(), 1200, 600);
addObject(new Spider(), 750, 600);
}

public void act() {
Expand Down
34 changes: 26 additions & 8 deletions Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ public class Spider extends Mobs {
private final double speed;
private final int dmg;
private World w;
private int direction = 1;
private long startTime;
private boolean oob = false;
private int direction = 1;
private int holdAct = 0;
private boolean holding = false;

public Spider() {
hp = 2;
speed = 0.5;
speed = 1;
dmg = 1;
}

Expand All @@ -20,23 +22,39 @@ public void addedToWorld(World w) {
}

public void act() {
movement();
if (checkBlock()) {
holdAct--;
hold();
} else {
movement();
}
attack();
timeout();
}

protected void movement() {
if (getWorld() == null) {
if (getWorld() == null || holding) {
return;
}
turnTowards(direction * 999, getY());
if (getOneObjectAtOffset(direction * getImage().getWidth(), 0, Brick.class) != null) {
setLocation(getX(), getY() + (speed * direction));
}

protected void hold() {
if (!holding) {
holding = true;
holdAct = 60;
}
if (holdAct == 0) {
holding = false;
direction *= -1;
} else {
move(speed);
setLocation(getX(), getY() + (5 * direction));
}
}

private boolean checkBlock() {
return getOneIntersectingObject(Tile.class) != null;
}

public void timeout() {
if (w == null) {
return;
Expand Down
8 changes: 4 additions & 4 deletions project.greenfoot
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependency2.type=UsesDependency
dependency20.from=RedBee
dependency20.to=Player
dependency20.type=UsesDependency
dependency21.from=RedBee
dependency21.from=Spider
dependency21.to=Brick
dependency21.type=UsesDependency
dependency22.from=RedSpider
Expand Down Expand Up @@ -76,7 +76,7 @@ editor.fx.0.height=0
editor.fx.0.width=0
editor.fx.0.x=0
editor.fx.0.y=0
height=1042
height=1040
package.numDependencies=23
package.numTargets=18
project.charset=UTF-8
Expand Down Expand Up @@ -222,5 +222,5 @@ target9.y=0
version=3.1.0
width=1920
world.lastInstantiated=Level0
xPosition=864
yPosition=317
xPosition=0
yPosition=0

0 comments on commit fd239ff

Please sign in to comment.