Skip to content

Commit

Permalink
Merge branch 'rc' into Dz1
Browse files Browse the repository at this point in the history
  • Loading branch information
danielzzhuang committed Jun 13, 2024
2 parents 40c7612 + e138e05 commit 2b74b03
Show file tree
Hide file tree
Showing 70 changed files with 7,918 additions and 224 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
18 changes: 11 additions & 7 deletions Brick.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.GreenfootImage;

/**
* Write a description of class Block here.
*
* @author (your name)
*
* @author (your name)
* @version (a version number or a date)
*/
public class Brick extends Tile
{
public class Brick extends Tile {
public Brick() {
GreenfootImage image = new GreenfootImage("brick.jpg");
image.scale(64, 64);
setImage(image);
}

/**
* Act - do whatever the Block wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
public void act() {
}
}
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
5 changes: 4 additions & 1 deletion EndScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class EndScreen extends World
public EndScreen()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1280, 720, 1);
super(1280, 720, 1);

// Background
setBackground("brick.jpg");
}
}
19 changes: 19 additions & 0 deletions FloorHole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import greenfoot.Actor;
import greenfoot.GreenfootImage;
import greenfoot.World;

import java.util.List;

public class FloorHole extends Actor {
public FloorHole() {
GreenfootImage image = new GreenfootImage(1, 1);
setImage(image);
}

public void addedToWorld(World w) {
List<Brick> brick = getObjectsInRange(32, Brick.class);
for (Brick b : brick) {
w.removeObject(b);
}
}
}
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
26 changes: 26 additions & 0 deletions JumpBooster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import greenfoot.Actor;
import greenfoot.Color;
import greenfoot.GreenfootImage;
import greenfoot.World;

public class JumpBooster extends Actor {
GreenfootImage image;

public JumpBooster() {
image = new GreenfootImage(64, 64);
image.setColor(new Color(63, 81, 181, 128));
image.fillRect(0, 0, 64, 64);
setImage(image);
}

public void addedToWorld(World w) {

}

public void act() {
Player p = (Player) getOneIntersectingObject(Player.class);
if (p != null) {
p.jumpBoost();
}
}
}
96 changes: 85 additions & 11 deletions Level.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,78 @@
import greenfoot.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

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


public Level() {
super(1280, 720, 1, false);
saveButtonImage.scale(150, 60);
saveButton.setImage(saveButtonImage);
setPaintOrder(Button.class, SuperDisplayLabel.class, Tile.class);
}

public Level(int level) {
super(1280, 720, 1, false);
saveButtonImage.scale(150, 60);
saveButton.setImage(saveButtonImage);
setPaintOrder(Button.class, SuperDisplayLabel.class, Tile.class);
setLevel(level);
}

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

public static void addToTotalCoin() {
totalCoins++;
}
public static void addCrown(){

public static void addCrown() {
numOfCrown++;
}

public void spawnFloor(ImgScroll sc) {
for (int j = 0; j < sc.getScrollHeight() - 100; j += 300) {
for (int i = 0; i < sc.getScrollWidth() + 64; i += 63) {
addObject(new Brick(), i, 700);
}
for (int i = 0; i < sc.getScrollWidth() + 64; i += 64) {
addObject(new Brick(), i, 700);
}
}

public void checkNext() {
if (orb.isBeingTouched()) {
Level1 world = new Level1();
Greenfoot.setWorld(world);
if (level == 0) {
levelUp();
Level1 world = new Level1();
Greenfoot.setWorld(world);
return;
}
if (level == 1) {
EndScreen end = new EndScreen();
Greenfoot.setWorld(end);
}
}
}

public void setLevel(int level) {
Level.level = level;
}

public int[] getWorldSize() {
return worldSize;
}
Expand All @@ -54,6 +84,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 + " HP: " + totalHP);
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 +135,10 @@ public void spawnTerrain(int[][] identifier) {
case 6 -> new RedBee();
case 7 -> new GreenBee();
case 8 -> new Spider();
case 9 -> new Crown();
case 10 -> new JumpBooster();
case 11 -> new Spike();
case 12 -> new FloorHole();
default -> null;
};
if (a != null) {
Expand All @@ -102,5 +147,34 @@ public void spawnTerrain(int[][] identifier) {
}
}
}

public void checkToSave() {
try {
FileWriter out = new FileWriter("saveFile1.csv");
PrintWriter output = new PrintWriter(out);
output.println(totalHP + "," + totalCoins + "," + level);
output.close();
} catch (IOException e) {

}
}

public void checkSaveButton() {
if (Greenfoot.mouseClicked(saveButton)) {
checkToSave();
}
}

public void levelUp() {
level++;
}

public void setHP(int hp) {
totalHP = hp;
}

public void setCoins(int coins) {
totalCoins = coins;
}
}

Loading

0 comments on commit 2b74b03

Please sign in to comment.