Skip to content

Commit

Permalink
Merge pull request #34 from Adrian400811/Adrian
Browse files Browse the repository at this point in the history
Fixed Mobs attack
  • Loading branch information
reihoron authored Jun 12, 2024
2 parents 870b95d + 9b91d55 commit fc0883f
Show file tree
Hide file tree
Showing 57 changed files with 7,220 additions and 91 deletions.
3 changes: 1 addition & 2 deletions Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public void addedToWorld(World w) {

@Override
public void act() {

attack();
attack(dmg);
collision();
super.act();
}
Expand Down
20 changes: 13 additions & 7 deletions Crown.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.GreenfootImage;

/**
* Write a description of class Crown here.
*
* @author (your name)
*
* @author (your name)
* @version (a version number or a date)
*/
public class Crown extends Collection
{
public class Crown extends Collection {
private final GreenfootImage image;

public Crown() {
image = new GreenfootImage("crown.png");
image.scale(64, 64);
setImage(image);
}

/**
* Act - do whatever the Crown wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
public void act() {
if (isTouching(Player.class)){
getWorld().removeObject(this);
Level.addCrown();
Expand Down
57 changes: 27 additions & 30 deletions GameOverScreen.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.*;

/**
* Write a description of class GameOverScreen here.
*
* @author (your name)
*
* @author (your name)
* @version (a version number or a date)
*/
public class GameOverScreen extends World
{
private Font font = new Font("Arial", 64);
private SuperDisplayLabel titleLabel = new SuperDisplayLabel(Color.WHITE, Color.BLACK, font);
private GreenfootImage titleImage = new GreenfootImage("GameOverText.png");

private SuperDisplayLabel gameOverLabel = new SuperDisplayLabel(font);
private GreenfootImage gameOverImage = new GreenfootImage("gameOverInstructions.png");

public class GameOverScreen extends World {
private final Font font = new Font("Arial", 64);
private final SuperDisplayLabel titleLabel = new SuperDisplayLabel(Color.WHITE, Color.BLACK, font);
private final GreenfootImage titleImage = new GreenfootImage("GameOverText.png");

private final SuperDisplayLabel gameOverLabel = new SuperDisplayLabel(font);
private final GreenfootImage gameOverImage = new GreenfootImage("gameOverInstructions.png");

/**
* Constructor for objects of class GameOverScreen.
*
*/
public GameOverScreen()
{
public GameOverScreen() {
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1280, 720, 1);
super(1280, 720, 1);

// Background
setBackground("bricks.jpg");
setBackground("brick.jpg");

// Title
addObject(titleLabel, 600, 200);
titleLabel.setImage(titleImage);
titleLabel.setLocation(640,150);
titleLabel.setLocation(640, 150);

// Instruction Label
addObject(gameOverLabel,getWidth()/2, 600);
addObject(gameOverLabel, getWidth() / 2, 600);
gameOverLabel.update("Press 'enter' to go to the Title Screen");
gameOverImage.scale(1100, 60);
gameOverLabel.setImage(gameOverImage);
gameOverLabel.setLocation(getWidth()/2, 600);
gameOverLabel.setLocation(getWidth() / 2, 600);


}
public void act(){

public void act() {
checkKeys();
}
private void checkKeys(){
if (Greenfoot.isKeyDown("enter")){

private void checkKeys() {
if (Greenfoot.isKeyDown("enter")) {
TitleScreen title = new TitleScreen();
Greenfoot.setWorld(title);
}
Expand Down
16 changes: 16 additions & 0 deletions Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Level() {
super(1280, 720, 1, false);
}

public static void resetCoin() {
totalCoins = 0;
}

public static void addToTotalCoin() {
totalCoins++;
}
Expand Down Expand Up @@ -54,6 +58,17 @@ public int[] getMapBoundary() {
return mapBoundary;
}

public void followPlayer(ImgScroll scr, Player p) {
if (p != null) {
scr.scroll(getWidth() / 2 - p.getX(), getHeight() / 2 - p.getY());
}
}

public void updateCoin(SuperDisplayLabel cl) {
cl.update("Coins: " + totalCoins);
cl.setLocation(getWidth() / 2, 20);
}

public int[][] loadLevel(int level) {
ArrayList<String> data = new ArrayList<String>();
Scanner scan = null;
Expand Down Expand Up @@ -94,6 +109,7 @@ public void spawnTerrain(int[][] identifier) {
case 6 -> new RedBee();
case 7 -> new GreenBee();
case 8 -> new Spider();
case 9 -> new Crown();
default -> null;
};
if (a != null) {
Expand Down
9 changes: 4 additions & 5 deletions Level0.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class Level0 extends Level {
private final ImgScroll scroll;
private final Player player;
private final int[] worldSize = {2560, 720};
private final int[] worldSize = {7680, 720};
private Orb orb;

/**
Expand All @@ -22,16 +22,15 @@ public Level0() {
spawnFloor(scroll);
addObject(player = new Player(), 100, 622);
addObject(coinLabel, 1100, 10);
coinLabel.update("Coins: " + totalCoins);
resetCoin();

int[][] blockGeneration = loadLevel(0);
spawnTerrain(blockGeneration);
}

public void act() {
scroll.scroll(getWidth() / 2 - player.getX(), getHeight() / 2 - player.getY());
coinLabel.update("Coins: " + totalCoins);
coinLabel.setLocation(getWidth() / 2, 20);
followPlayer(scroll, player);
updateCoin(coinLabel);
checkNext();
}
}
6 changes: 2 additions & 4 deletions Level1.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public Level1() {
spawnFloor(scroll);
addObject(player = new Player(), 100, 622);
addObject(coinLabel, 1100, 10);
coinLabel.update("Coins: " + totalCoins);

// Individual Block Placement
int[][] blockGeneration = new int[120][20];
Expand All @@ -31,8 +30,7 @@ public Level1() {
}

public void act() {
coinLabel.update("Coins: " + totalCoins);
coinLabel.setLocation(getWidth() / 2, 20);
scroll.scroll(getWidth() / 2 - player.getX(), getHeight() / 2 - player.getY());
followPlayer(scroll, player);
updateCoin(coinLabel);
}
}
1 change: 1 addition & 0 deletions Mites.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void act() {
direction = bounceWall(direction, image);
collision();
fall();
attack(dmg);
}

private void fall() {
Expand Down
2 changes: 1 addition & 1 deletion Mobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void stepped(){
getWorld().removeObject(this);
}
}
public void attack() {
public void attack(int dmg) {
Player p = (Player) getOneIntersectingObject(Player.class);
if (p == null) {
return;
Expand Down
5 changes: 2 additions & 3 deletions Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ private void collision() {
}

private void checkHP() {
if (hp > 0) {
return;
if (hp < 0) {
Greenfoot.setWorld(new GameOverScreen());
}
w.removeObject(this);
}

public int getSpeed() {
Expand Down
2 changes: 1 addition & 1 deletion Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void act() {
} else {
movement();
}
attack();
attack(dmg);
timeout();
super.act();
}
Expand Down
Loading

0 comments on commit fc0883f

Please sign in to comment.