diff --git a/Bee.java b/Bee.java index 69b9207..74ab8af 100755 --- a/Bee.java +++ b/Bee.java @@ -25,6 +25,7 @@ public void addedToWorld(World w) { @Override public void act() { + attackAct++; attack(dmg); collision(); super.act(); diff --git a/Level.java b/Level.java index 2554a96..a7a6879 100755 --- a/Level.java +++ b/Level.java @@ -137,6 +137,7 @@ public void followPlayer(ImgScroll scr, Player p) { } } + /** * Updates the coin and hp and sets the location of it * diff --git a/Level0.java b/Level0.java index 9468e1b..0107506 100755 --- a/Level0.java +++ b/Level0.java @@ -23,7 +23,7 @@ public Level0() { addObject(player = new Player(), 100, 622); addObject(coinLabel, 1100, 10); addObject(saveButton, getWidth() - 100, 40); - updateCoin(coinLabel); + updateCoin(); resetCoin(); setHP(5); setLevel(0); @@ -34,7 +34,7 @@ public Level0() { public void act() { followPlayer(scroll, player); - updateCoin(coinLabel); + updateCoin(); saveButton.setLocation(getWidth() - 100, 40); checkSaveButton(); checkNext(); diff --git a/Level1.java b/Level1.java index e7dfb4e..229e2ae 100755 --- a/Level1.java +++ b/Level1.java @@ -23,7 +23,7 @@ public Level1() { addObject(player = new Player(), 130, 135); addObject(coinLabel, 1100, 10); addObject(saveButton, getWidth() - 100, 40); - updateCoin(coinLabel); + updateCoin(); // Individual Block Placement int[][] blockGeneration = loadLevel(1); @@ -32,17 +32,17 @@ public Level1() { public void act() { followPlayer(scroll, player); - updateCoin(coinLabel); - saveButton.setLocation(getWidth()-100, 40); + updateCoin(); + saveButton.setLocation(getWidth() - 100, 40); checkSaveButton(); loseLife(); checkNext(); } - - private void loseLife(){ - if (player.touchingSpike()){ + + private void loseLife() { + if (player.touchingSpike()) { player.changeHP(-5); - setHP(totalHP-5); + setHP(totalHP - 5); } } } diff --git a/Mites.java b/Mites.java index 6e35556..1f9428b 100755 --- a/Mites.java +++ b/Mites.java @@ -12,7 +12,6 @@ public class Mites extends Mobs { private final int dmg; private final int speed; private final GreenfootImage image; - private int direction = 1; private Level w; private int movementAct; private int jumpAct; @@ -33,8 +32,9 @@ public void addedToWorld(World w) { public void act() { movementAct--; jumpAct--; + attackAct++; movement(); - direction = bounceWall(direction, image); + bounceWall(image); collision(); fall(); attack(dmg); diff --git a/Mobs.java b/Mobs.java index 3b1d3a9..83a69b5 100755 --- a/Mobs.java +++ b/Mobs.java @@ -11,11 +11,12 @@ */ public abstract class Mobs extends SuperSmoothMover { - public World w; - private int hp; - private int speed = 2; - private int dmg; - private int direction = 1; + protected World w; + protected int attackAct = 0; + protected int direction = 1; + protected int hp; + protected int speed = 2; + protected int dmg; /** * Constructor @@ -24,12 +25,20 @@ public Mobs() { enableStaticRotation(); } + protected void bounceWall(GreenfootImage image) { + if (getOneObjectAtOffset(direction * getImage().getWidth() + 2, 0, Tile.class) != null) { + direction *= -1; + image.mirrorHorizontally(); + } + } + public void addedToWorld(World w) { this.w = w; } public void act() { stepped(); + attackAct++; } private void gravity() { @@ -68,21 +77,6 @@ public void collision() { } } - protected int bounceWall(int dir) { - if (getOneObjectAtOffset(dir * getImage().getWidth() + 1, 0, Tile.class) != null) { - dir *= -1; - } - return dir; - } - - protected int bounceWall(int dir, GreenfootImage image) { - if (getOneObjectAtOffset(dir * getImage().getWidth() + 2, 0, Tile.class) != null) { - dir *= -1; - image.mirrorHorizontally(); - } - return dir; - } - protected void idle() { if (getWorld() == null) { return; @@ -144,10 +138,10 @@ public void stepped() { */ public void attack(int dmg) { Player p = (Player) getOneIntersectingObject(Player.class); - if (p == null) { - return; + if (p != null && attackAct > 60) { + attackAct = 0; + p.changeHP(-dmg); } - p.changeHP(-dmg); } public void changeHP(int deltaHP) { diff --git a/Player.java b/Player.java index 8e6ff3d..8815e2d 100755 --- a/Player.java +++ b/Player.java @@ -14,7 +14,7 @@ public class Player extends Actor { private static int speed; private final int dmg; private int hp; - private World w; + private Level w; private int jumpActs = 0; private int boostActs = 0; private GreenfootImage[] R, L, U, D; @@ -59,7 +59,7 @@ private void initAnim(){ } public void addedToWorld(World w) { - this.w = w; + this.w = (Level) w; } /** @@ -126,7 +126,7 @@ private void fixDirections(){ private void jump() { if (Greenfoot.isKeyDown("Space") && getOneObjectAtOffset(0, (getImage().getHeight() / 2) + 1, Brick.class) != null) { jumpActs = 30; - } + } if (jumpActs > 15) { setLocation(getX(), getY() - 8); } @@ -228,7 +228,9 @@ public int getSpeed() { */ public void changeHP(int deltaHP) { hp += deltaHP; + w.setHP(hp); } + /** * Returns if the Player is touching a Spike diff --git a/Spider.java b/Spider.java index 5a3de9d..e75476f 100755 --- a/Spider.java +++ b/Spider.java @@ -33,6 +33,7 @@ public void addedToWorld(World w) { } public void act() { + attackAct++; if (checkBlock() || checkY()) { holdAct--; hold(); diff --git a/levels/0.csv b/levels/0.csv index c9d3455..ce4c7b7 100755 --- a/levels/0.csv +++ b/levels/0.csv @@ -131,7 +131,7 @@ 71,1,1 71,4,8 72,11,12 -72,2,1 +72,1,1 72,5,8 73,10,1 74,10,1