Skip to content

Commit

Permalink
Merge branch 'rc' into Dz1
Browse files Browse the repository at this point in the history
  • Loading branch information
reihoron authored Jun 11, 2024
2 parents 79e8de8 + d7e21b7 commit 44b4bed
Show file tree
Hide file tree
Showing 15 changed files with 471 additions and 17 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();
}
}
19 changes: 19 additions & 0 deletions Button.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Button here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Button extends Actor
{
/**
* Act - do whatever the Button wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}
22 changes: 20 additions & 2 deletions Coin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@
*/
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
* the 'Act' or 'Run' button gets pressed in the environment.
*/

public void act()
{
// Add your action code here.
if (isTouching(Player.class)){
getWorld().removeObject(this);
Level.addToTotalCoin();
}
}

public boolean isBeingTouched(){
if (isTouching(Player.class)){
return true;
}
return false;
}
}
13 changes: 13 additions & 0 deletions Level.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import greenfoot.Greenfoot;
import greenfoot.GreenfootImage;
import greenfoot.World;
import greenfoot.*;

public class Level extends World {
protected final ImgScroll scroll;
private final int[] worldSize = {2560, 720};
private final String background = "2dPixelForestBackground.png";
protected Player player;
private Orb orb;
private Font font = new Font("Arial", 18);
protected SuperDisplayLabel coinLabel = new SuperDisplayLabel(Color.BLACK, Color.WHITE, font);
protected static int totalCoins = 0;

public Level() {
super(1280, 720, 1, false);
scroll = new ImgScroll(this, new GreenfootImage(background), worldSize[0], worldSize[1]);
addObject(coinLabel, 1100, 10);
coinLabel.update("Coins: " + totalCoins);
}

public void act() {
Expand Down Expand Up @@ -40,6 +46,9 @@ public void spawnTerrain(int[][] identifier) {
if (identifier[i][j] == 2) {
addObject(orb = new Orb(), i * 64, j * 64);
}
if (identifier[i][j] == 3) {
addObject(new Coin(), i * 64, j * 72);
}
}
}
}
Expand All @@ -61,4 +70,8 @@ public int[] getMapBoundary() {
mapBoundary[1] = scroll.getScrollWidth() + scroll.getScrolledX();
return mapBoundary;
}

public static void addToTotalCoin(){
totalCoins++;
}
}
9 changes: 7 additions & 2 deletions Level0.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import greenfoot.GreenfootImage;
import greenfoot.*;

/**
* Write a description of class Level0 here.
Expand All @@ -12,7 +13,7 @@ public class Level0 extends Level {
private final int[] worldSize = {2560, 720};
private final String background = "2dPixelForestBackground.png";
private Orb orb;

/**
* Constructor for objects of class Level0.
*/
Expand All @@ -30,15 +31,19 @@ public Level0() {
blockGeneration[10][6] = 2;
blockGeneration[10][9] = 1;
blockGeneration[5][7] = 1;
blockGeneration[5][8] = 3;
spawnTerrain(blockGeneration);


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() {
coinLabel.update("Coins: " + totalCoins);
coinLabel.setLocation(getWidth()/2, 20);
scroll.scroll(getWidth() / 2 - player.getX(), getHeight() / 2 - player.getY());
checkNext();
}
Expand Down
2 changes: 2 additions & 0 deletions Level1.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public Level1() {
}

public void act() {
coinLabel.update("Coins: " + totalCoins);
coinLabel.setLocation(getWidth()/2, 20);
scroll.scroll(getWidth() / 2 - player.getX(), getHeight() / 2 - player.getY());
}

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
Loading

0 comments on commit 44b4bed

Please sign in to comment.