Skip to content

Commit

Permalink
Add image for Spider
Browse files Browse the repository at this point in the history
Moved map file into levels dir
  • Loading branch information
reihoron committed Jun 11, 2024
1 parent cba11dd commit b064478
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 120 deletions.
13 changes: 4 additions & 9 deletions Coin.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import greenfoot.Actor;
import greenfoot.GreenfootImage;

/**
Expand All @@ -7,12 +6,12 @@
* @author (your name)
* @version (a version number or a date)
*/
public class Coin extends Actor {
private GreenfootImage image;
public class Coin extends Collection {
private final GreenfootImage image;

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

Expand All @@ -26,8 +25,4 @@ public void act() {
Level.addToTotalCoin();
}
}

public boolean isBeingTouched() {
return isTouching(Player.class);
}
}
Empty file modified Collection.java
100644 → 100755
Empty file.
Empty file modified Crown.java
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public int[][] loadLevel(int level) {
ArrayList<String> data = new ArrayList<String>();
Scanner scan = null;
try {
scan = new Scanner(new File("level" + level + ".csv"));
scan = new Scanner(new File("levels/" + level + ".csv"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down
7 changes: 1 addition & 6 deletions Level0.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ public Level0() {
addObject(player = new Player(), 100, 622);
addObject(coinLabel, 1100, 10);
coinLabel.update("Coins: " + totalCoins);



int[][] blockGeneration = loadLevel(0);
spawnTerrain(blockGeneration);
addObject(new BlueBee(), 800, 600);
addObject(new RedBee(), 100, 600);
addObject(new Spider(), 750, 600);
addObject(new Mites(), 150, 600);
}

public void act() {
Expand Down
14 changes: 6 additions & 8 deletions Mites.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public class Mites extends Mobs {
private final int hp;
private final int dmg;
private final int speed;
private final int direction = 1;
private final GreenfootImage image;
private int direction = 1;
private Level w;
private int movementAct;
private int jumpAct;
Expand All @@ -16,6 +16,8 @@ public Mites() {
dmg = 1;
speed = 2;
image = new GreenfootImage("images/mites.png");
image.scale(64, 43);
setImage(image);
}

public void addedToWorld(World w) {
Expand All @@ -26,23 +28,19 @@ public void act() {
movementAct--;
jumpAct--;
movement();
bounceWall();
direction = bounceWall(direction, image);
collision();
fall();
}

private void flipImage() {
image.mirrorHorizontally();
}

private void fall() {
if (getOneObjectAtOffset(0, (getImage().getHeight() / 2) + 1, Brick.class) == null && jumpAct < 15) {
if (getOneObjectAtOffset(0, (getImage().getHeight() / 2) + 1, Tile.class) == null && jumpAct < 15) {
setLocation(getX() + (speed * direction), getY() + 5);
}
}

private void movement() {
if (movementAct < 0 && getOneObjectAtOffset(0, (getImage().getHeight() / 2) + 1, Brick.class) != null) {
if (movementAct < 0 && getOneObjectAtOffset(0, (getImage().getHeight() / 2) + 1, Tile.class) != null) {
jumpAct = 30;
movementAct = 60;
}
Expand Down
16 changes: 13 additions & 3 deletions Mobs.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import greenfoot.GreenfootImage;
import greenfoot.World;

import java.util.List;
Expand Down Expand Up @@ -51,10 +52,19 @@ public void collision() {
}
}

protected void bounceWall() {
if (getOneObjectAtOffset(direction * getImage().getWidth() + 1, 0, Brick.class) != null) {
direction *= -1;
protected int bounceWall(int dir) {
if (getOneObjectAtOffset(dir * getImage().getWidth() + 2, 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() {
Expand Down
5 changes: 5 additions & 0 deletions Spider.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import greenfoot.GreenfootImage;
import greenfoot.World;

public class Spider extends Mobs {
private final int hp;
private final double speed;
private final int dmg;
private final GreenfootImage image;
private World w;
private int direction = 1;
private long startTime;
Expand All @@ -15,6 +17,9 @@ public Spider() {
hp = 2;
speed = 1;
dmg = 1;
image = new GreenfootImage("spider.png");
image.scale(47, 64);
setImage(image);
}

public void addedToWorld(World w) {
Expand Down
Binary file removed images/bricks.jpg
Binary file not shown.
Empty file modified images/coin.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified images/crown.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/mites.flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/mites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/spider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion level0.csv → levels/0.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
15,9,1
16,8,1
17,8,1
1,1,4
12,1,4
2,2,5
3,3,6
4,4,8
Expand Down
File renamed without changes.
Loading

0 comments on commit b064478

Please sign in to comment.