Skip to content

Commit

Permalink
Comments for Player ,Mob, Level Class
Browse files Browse the repository at this point in the history
  • Loading branch information
349928465 committed Jun 13, 2024
1 parent 0788841 commit 0293a66
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 10 deletions.
94 changes: 89 additions & 5 deletions Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
/**
* Level Superclass
*
* @author Adrian, Jimmy
* @version June 13, 2024
*/

public class Level extends World {
protected static int totalCoins = 0;
Expand All @@ -20,14 +26,21 @@ public class Level extends World {
protected Button saveButton = new Button();
private Orb orb;


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


/**
* Constructor
*
* @param int The level to go to
*/
public Level(int level) {
super(1280, 720, 1, false);
saveButtonImage.scale(150, 60);
Expand All @@ -36,24 +49,40 @@ public Level(int level) {
setLevel(level);
}

/**
* Resets coins
*/
public static void resetCoin() {
totalCoins = 0;
}

/**
* Adds a singular coin to the total
*/
public static void addToTotalCoin() {
totalCoins++;
}

/**
* Adds one crown to the total
*/
public static void addCrown() {
numOfCrown++;
}

/**
* Spawns the floor of the world
*/
public void spawnFloor(ImgScroll sc) {
for (int i = 0; i < sc.getScrollWidth() + 64; i += 64) {
addObject(new Brick(), i, 700);
}
}

/**
* Check if touching Orb.
* If it is touching orb, go to the next level
*/
public void checkNext() {
if (orb.isBeingTouched()) {
if (level == 0) {
Expand All @@ -69,32 +98,61 @@ public void checkNext() {
}
}

/**
* Sets the current level to the desired level
*
* @param int The desired level to go to
*/
public void setLevel(int level) {
Level.level = level;
}

/**
* Returns the size of the world
*
* @return int[] the size of the world
*/
public int[] getWorldSize() {
return worldSize;
}

/**
* Returns the boundaries of the map
*
* @return int[] the boundary of the map
*/
public int[] getMapBoundary() {
int[] mapBoundary = new int[2];
mapBoundary[0] = scroll.getScrolledX();
mapBoundary[1] = scroll.getScrollWidth() + scroll.getScrolledX();
return mapBoundary;
}

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

/**
* Updates the coin and hp and sets the location of it
*
* @param SuperDisplayLabel the label to update
*/
public void updateCoin(SuperDisplayLabel cl) {
cl.update("Coins: " + totalCoins + " HP: " + totalHP);
cl.setLocation(getWidth() / 2, 20);
}

/**
* Loads level from a csv file
*
* @param level The level to load
* @return int[][] The 2d array with the location of the blocks
*/
public int[][] loadLevel(int level) {
ArrayList<String> data = new ArrayList<String>();
Scanner scan = null;
Expand All @@ -118,10 +176,16 @@ public int[][] loadLevel(int level) {
}
return blocks;
}



/**
* Spawns the blocks
*
* @param identifier The 2d array of blocks to be loaded
*
*
* NOTE - Use a 2d array of [40][10] for this to work as intended
* Each value in the array represents 64x and 72y
* Each value in the array represents 64x and 64y
*/
public void spawnTerrain(int[][] identifier) {
for (int i = 0; i < identifier.length; i++) {
Expand All @@ -148,6 +212,9 @@ public void spawnTerrain(int[][] identifier) {
}
}

/**
* Saves the values to a csv file
*/
public void checkToSave() {
try {
FileWriter out = new FileWriter("saveFile1.csv");
Expand All @@ -159,20 +226,37 @@ public void checkToSave() {
}
}

/**
* Checks if saveButton has been clicked
* If clicked, runs the checkToSave() method
*/
public void checkSaveButton() {
if (Greenfoot.mouseClicked(saveButton)) {
checkToSave();
}
}

/**
* Increases level by one
*/
public void levelUp() {
level++;
}

/**
* Sets current HP to desired HP
*
* @param hp The desired HP
*/
public void setHP(int hp) {
totalHP = hp;
}


/**
* Sets coins to the desired coins
*
* @param coins The desired coins
*/
public void setCoins(int coins) {
totalCoins = coins;
}
Expand Down
23 changes: 22 additions & 1 deletion Mobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@

import java.util.List;

/**
* Mobs Class
*
* @author Adrian
* @version June 13 2024
*/

public abstract class Mobs extends SuperSmoothMover {
public World w;
private int hp;
private int speed = 2;
private int dmg;
private int direction = 1;

/**
* Constructor
*/
public Mobs() {
enableStaticRotation();
}
Expand Down Expand Up @@ -46,6 +56,9 @@ private void boundary() {
}
}

/**
* Checks for collision with the Brick class
*/
public void collision() {
if (getOneObjectAtOffset(getImage().getWidth() / 2, 0, Brick.class) != null) {
setLocation(getX() - speed, getY());
Expand Down Expand Up @@ -112,6 +125,9 @@ public Player getPlayer(int range) {
return null;
}

/**
* If stepped on by Player class, remove this mob
*/
public void stepped() {
if (getWorld() == null) {
return;
Expand All @@ -120,7 +136,12 @@ public void stepped() {
getWorld().removeObject(this);
}
}


/**
* Checks if Mob attacks Player and changes HP by dmg if Player gets hit
*
* @param dmg The amount to change Player HP by
*/
public void attack(int dmg) {
Player p = (Player) getOneIntersectingObject(Player.class);
if (p == null) {
Expand Down
36 changes: 32 additions & 4 deletions Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import greenfoot.World;
import greenfoot.*;
/**
* Write a description of class Player here.
* Player Class
* Main Physics by Jimmy and Adrian
* Animation by Anson
*
* @author (your name)
* @version (a version number or a date)
* @author Jimmy, Adrian, Anson
* @version June 13, 2024
*/
public class Player extends Actor {
private static int speed;
Expand Down Expand Up @@ -77,6 +79,11 @@ public void act() {
fixDirections();
}

/**
* Movement for the Player
*
* @return void
*/
private void movement() {
if (Greenfoot.isKeyDown("D")) {
setLocation(getX() + 8, getY());
Expand Down Expand Up @@ -111,6 +118,11 @@ private void fixDirections(){
}
}

/**
* Jump method for the Player
*
* @return void
*/
private void jump() {
if (Greenfoot.isKeyDown("Space") && getOneObjectAtOffset(0, (getImage().getHeight() / 2) + 1, Brick.class) != null) {
jumpActs = 30;
Expand Down Expand Up @@ -199,14 +211,30 @@ private void checkHP() {
}
}

/**
* Returns the speed for the Player
*
* @return int speed of the Player
*/
public int getSpeed() {
return speed;
}


/**
* Change the HP for the Player
*
* @param int amount of hp to be changed
* @return void
*/
public void changeHP(int deltaHP) {
hp += deltaHP;
}

/**
* Returns if the Player is touching a Spike
*
* @return boolean true if it is touching Spike, false if not touching Spike
*/
public boolean touchingSpike(){
return (isTouching(Spike.class));
}
Expand Down

0 comments on commit 0293a66

Please sign in to comment.