From ef9bc6eb1d93be0d6f410e4127ebc631c15879a9 Mon Sep 17 00:00:00 2001 From: danielzzhuang <349545699@gapps.yrdsb.ca> Date: Tue, 11 Jun 2024 11:37:16 -0700 Subject: [PATCH] new function for mob --- Bee.java | 1 + Coin.java | 14 +------------- Crown.java | 5 ++++- Level.java | 11 ++++++++--- Level0.java | 2 +- Mobs.java | 10 ++++++++-- RedBee.java | 1 + Spider.java | 1 + 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Bee.java b/Bee.java index 40a83c8..8216983 100755 --- a/Bee.java +++ b/Bee.java @@ -19,6 +19,7 @@ public void addedToWorld(World w) { @Override public void act() { + super.act(); attack(); collision(); } diff --git a/Coin.java b/Coin.java index 5547b78..c125e35 100644 --- a/Coin.java +++ b/Coin.java @@ -8,13 +8,7 @@ */ public class Coin extends Collection { - private GreenfootImage image; - - public Coin(){ - image = new GreenfootImage("marioCoin.png"); - image.scale(45,55); - setImage(image); - } + /** * Act - do whatever the Coin wants to do. This method is called whenever @@ -29,10 +23,4 @@ public void act() } } - public boolean isBeingTouched(){ - if (isTouching(Player.class)){ - return true; - } - return false; - } } diff --git a/Crown.java b/Crown.java index 8d129b1..dea4494 100644 --- a/Crown.java +++ b/Crown.java @@ -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(); + } } } diff --git a/Level.java b/Level.java index 576d685..3cc01f9 100755 --- a/Level.java +++ b/Level.java @@ -12,7 +12,7 @@ public class Level extends World { private Font font = new Font("Arial", 18); protected SuperDisplayLabel coinLabel = new SuperDisplayLabel(Color.BLACK, Color.WHITE, font); protected static int totalCoins = 0; - + protected static int numOfCrown=0; public Level() { super(1280, 720, 1, false); scroll = new ImgScroll(this, new GreenfootImage(background), worldSize[0], worldSize[1]); @@ -47,7 +47,10 @@ public void spawnTerrain(int[][] identifier) { addObject(orb = new Orb(), i * 64, j * 64); } if (identifier[i][j] == 3) { - addObject(new Coin(), i * 64, j * 72); + addObject(new Coin(), i * 64, j * 64); + } + if (identifier[i][j] == 4) { + addObject(new Crown(), i * 64, j * 64); } } } @@ -70,7 +73,9 @@ public int[] getMapBoundary() { mapBoundary[1] = scroll.getScrollWidth() + scroll.getScrolledX(); return mapBoundary; } - + public static void addCrown(){ + numOfCrown++; + } public static void addToTotalCoin(){ totalCoins++; } diff --git a/Level0.java b/Level0.java index 72f72b2..0bd6d2f 100755 --- a/Level0.java +++ b/Level0.java @@ -28,7 +28,7 @@ public Level0() { blockGeneration[11][5] = 1; blockGeneration[12][5] = 1; blockGeneration[28][5] = 1; - blockGeneration[10][6] = 2; + blockGeneration[20][6] = 2; blockGeneration[10][9] = 1; blockGeneration[5][7] = 1; blockGeneration[5][8] = 3; diff --git a/Mobs.java b/Mobs.java index bf619c7..007a40b 100755 --- a/Mobs.java +++ b/Mobs.java @@ -16,7 +16,9 @@ public Mobs() { public void addedToWorld(World w) { this.w = w; } - + public void act(){ + stepped(); + } private void gravity() { if (!isTouching(Brick.class)) { @@ -92,7 +94,11 @@ public Player getPlayer(int range) { } return null; } - + public void stepped(){ + if(getOneObjectAtOffset(getX(), getY()-1, Player.class)!=null){ + getWorld().removeObject(this); + } + } public void attack() { Player p = (Player) getOneIntersectingObject(Player.class); if (p == null) { diff --git a/RedBee.java b/RedBee.java index 53fe734..2a03e21 100755 --- a/RedBee.java +++ b/RedBee.java @@ -25,6 +25,7 @@ public void act() { } else { idle(); } + } diff --git a/Spider.java b/Spider.java index 777bf7c..aa9d418 100755 --- a/Spider.java +++ b/Spider.java @@ -30,6 +30,7 @@ public void act() { } attack(); timeout(); + super.act(); } protected void movement() {