diff --git a/saves/Level1-signs.txt b/saves/Level1-signs.txt index 2114fac..6fb060d 100644 --- a/saves/Level1-signs.txt +++ b/saves/Level1-signs.txt @@ -13,6 +13,7 @@ 2950 550 you can blow up boxes 500 200 Press WASD to move and R to restart 500 250 S makes you fall down faster +500 300 P skips the level 4250 100 You can pickup/placedown steel using right click 4250 150 Hold right click to see your pickup/placedown range 4250 200 You can't jump or throw bombs while while holding steel diff --git a/saves/Level5.txt b/saves/Level5.txt index 15c827d..335b800 100644 --- a/saves/Level5.txt +++ b/saves/Level5.txt @@ -1,4 +1,4 @@ -qwmwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwmwwwwwwwmmwwwwwwmwwwmmwwwwwmwwwwwmmwwwwwwwwwwwwwwe +qwwwwmwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwmwwwwwwwmmwwwwwwmwwwmmwwwwwmwwwwwmmwwwwwwwwwwwwwwe a mb !! b d a bbbbbbo hmmmmmmmmmmmmmm1 a b h + diff --git a/saves/Level6-dialogue.txt b/saves/Level6-dialogue.txt new file mode 100644 index 0000000..b49b9cc --- /dev/null +++ b/saves/Level6-dialogue.txt @@ -0,0 +1 @@ +$Empty \ No newline at end of file diff --git a/saves/Level6-signs.txt b/saves/Level6-signs.txt new file mode 100644 index 0000000..95e2982 --- /dev/null +++ b/saves/Level6-signs.txt @@ -0,0 +1 @@ +600 100 YOU WIN THE GAME! Have fun with these bombs \ No newline at end of file diff --git a/saves/Level6.txt b/saves/Level6.txt new file mode 100644 index 0000000..5d79732 --- /dev/null +++ b/saves/Level6.txt @@ -0,0 +1,18 @@ +qwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwe +s d +s d +s d +s d +s d +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd +zxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc \ No newline at end of file diff --git a/sound/grass.wav b/sound/grass.wav deleted file mode 100644 index 73f2074..0000000 Binary files a/sound/grass.wav and /dev/null differ diff --git a/sound/land.wav b/sound/land.wav new file mode 100644 index 0000000..ec758d1 Binary files /dev/null and b/sound/land.wav differ diff --git a/src/GamePanel.java b/src/GamePanel.java index 4081a3a..befdeb1 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -607,7 +607,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ e = UtilityFunction.intercept(e, middlewareArray); player.keyReleased(e); // pressing the P key skips to the next level - if(e.getKeyCode() == KeyEvent.VK_P){ + if(e.getKeyCode() == KeyEvent.VK_P && !isDialogue){ LevelManager.nextLevel(); try { player.resetNoSound(); diff --git a/src/LevelManager.java b/src/LevelManager.java index 51c61eb..95ebc4d 100644 --- a/src/LevelManager.java +++ b/src/LevelManager.java @@ -52,6 +52,12 @@ public class LevelManager implements Serializable { ySpawn = 350; filePath = "saves/Level5.txt"; bombs = 1; + } else if(level == 6){ + //-1100/460 + xSpawn = 0; + ySpawn = 50; + filePath = "saves/Level6.txt"; + bombs = 999999; } try { // load map into GamePanel @@ -116,6 +122,8 @@ public class LevelManager implements Serializable { bombs = 5; } else if(GameFrame.game.level == 5){ bombs = 1; + } else if(GameFrame.game.level == 6){ + bombs = 999999; } } // overloaded setLevel that accepts only a level argument diff --git a/src/Player.java b/src/Player.java index 785a174..3f8d522 100644 --- a/src/Player.java +++ b/src/Player.java @@ -18,7 +18,6 @@ public class Player extends GenericSprite { public static final int steelReachRange = 4*Tile.length; public int lastXDirection, lastYDirection, lastFrame; - public static final int walkSpeedCap = 5; public boolean alive; private transient Sound jump = new Sound("sound/jump.wav"); @@ -42,8 +41,9 @@ public class Player extends GenericSprite { public boolean leftClickPlacedSteel; public Player(int x, int y, BufferedImageWrapper[][][] sprites) throws UnsupportedAudioFileException, LineUnavailableException, IOException { + //Creates the generic sprite via super function super(x, y, PLAYER_HEIGHT, PLAYER_WIDTH); - // jump = new Sound("sound/jump.wav"); + //Sets default state of player spriteArray = sprites; alive = true; isPlayer = true; @@ -59,7 +59,8 @@ public class Player extends GenericSprite { - // moves paddle when key is pressed + //Allows the plays to move depending on which keys are pressed. + //Or reset if R is pressed public void keyPressed(KeyEvent e) throws IOException { if(e.getKeyCode() == KeyEvent.VK_D){ rightPressed = true; @@ -78,7 +79,7 @@ public class Player extends GenericSprite { } } - // stops moving paddle when key is released + //Stops movement when player releases keys public void keyReleased(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_D){ rightPressed = false; @@ -94,36 +95,42 @@ public class Player extends GenericSprite { } } + //Checks if the player overlaps with a tile public boolean collide(Tile tile, double x, double y){ if(tile==null){return false;} if(!tile.collision){ return false; } - if(x+WIDTH>tile.realX&&x tile.realX && x < tile.realX + Tile.length && y - tile.y < Tile.length && tile.y - y < HEIGHT; } - // calls parent + + //Checks if the player can change their x position by some amount, and y position by amount. + //If any tiles overlap the player, it can't update. + //Kills the player if they touch lava and sets the game to the next level if they finish. public boolean canUpdate(double x, double y) throws UnsupportedAudioFileException, LineUnavailableException, IOException { if(this.y+y<=-(HEIGHT+Tile.length)){ return false; } boolean canUpdate = true; + //To reduce lag, we only check the tiles near by, which the boundaries are set + //By these 4 variables. int lowX = Math.max(0, ((GameFrame.game.camera.x+GamePanel.GAME_WIDTH)/Tile.length)-4); int highX = Math.min(lowX + 8, GameFrame.game.map.length); int lowY = Math.max(0,(this.y/Tile.length)-6); int highY = Math.min(lowY + 12, GameFrame.game.map[0].length); + //Actually checks the blocks around and if they collide with the player. for(int i=lowX; isteelReachRange){canPlaceSteel = false; return;} + + //If there is a non-replacable block, you can't place if(GameFrame.game.map[x][y]!=null&&!GameFrame.game.map[x][y].replaceAble){canPlaceSteel = false; return;} + + //If you can't reach an area because of blocks in the way, you can't place. if(!canReach(xx,yy)){canPlaceSteel = false; return;}; - //System.out.println(realX); } + //Moves the player with physics. public void move() throws IOException, UnsupportedAudioFileException, LineUnavailableException { -// mouseX = MouseInfo.getPointerInfo().getLocation().x; -// mouseY = MouseInfo.getPointerInfo().getLocation().y; - + //To prevent spamming steel block, we have pickup delay for the steel blocks pickupDelay = Math.max(0,pickupDelay - 1); int Tilex = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length; int Tiley = (mouseY / Tile.length); + + //If the player is holding steel, we update to see if they can updatePlaceSteel. if(holdingSteel){ updatePlaceSteel(Tilex,Tiley); } + //Stops player from glitching into corner if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){ GameFrame.game.camera.x += -Math.signum(xVelocity); } + + //Prevents player from passing tiles in the x-direction if(!canUpdate(xVelocity, 0)){ int updateAmount = 0; if(xVelocity>0){ @@ -221,12 +239,14 @@ public class Player extends GenericSprite { } //xVelocity = 0; } + //Prevents player from passing blocks from the y direction if(!canUpdate(0, yVelocity)){ if(yVelocity>0){ while(canUpdate(0,1)){ y+=1; } isGrounded = true; + } else if(yVelocity<0){ while(canUpdate(0,-1)){ y-=1; @@ -234,6 +254,7 @@ public class Player extends GenericSprite { } yVelocity = 0; } + //If the player can update their position due to nothing being in the way, update their position. if(canUpdate(xVelocity, yVelocity)) { y = y + (int) yVelocity; GameFrame.game.camera.x = GameFrame.game.camera.x + (int) xVelocity; @@ -245,6 +266,8 @@ public class Player extends GenericSprite { } + //Give the player xVelocity if they press left or right + //Add particles if the player is walking if(rightPressed){ if(isGrounded){ addParticle(-1); @@ -261,6 +284,9 @@ public class Player extends GenericSprite { xVelocity -= 1; } } + + //Checks if the player can jump + //Conditions: They press up, they are on the ground, they are not holding steel if(upPressed&&isGrounded&&!holdingSteel){ y-=1; isGrounded = false; @@ -278,6 +304,7 @@ public class Player extends GenericSprite { } xVelocity *= 0.93; + //Adds gravity, and allows player to fall down faster. if(!isGrounded) { yVelocity += 0.3; if(downPressed){ @@ -285,14 +312,17 @@ public class Player extends GenericSprite { } } + //If the player is dead, reset map if(!alive){ alive = true; reset(); } + //Speed limit to player capSpeed(); } + //Spawn the player with the death sound public void reset() throws UnsupportedAudioFileException, LineUnavailableException, IOException { SoundWrapper.playSound("sound/OOF.wav"); holdingSteel = false; @@ -303,6 +333,8 @@ public class Player extends GenericSprite { LevelManager.setBombs(); } + + //Spawns the player without sound public void resetNoSound() throws IOException { holdingSteel = false; LevelManager.setLevel(GameFrame.game.level, true); @@ -311,8 +343,11 @@ public class Player extends GenericSprite { GameFrame.game.bombs.clear(); LevelManager.setBombs(); } + + //Handles events when the player presses a mouse button. + //Left for throwing bombs, and right for picking and placing steel public void mousePressed(MouseEvent e) throws SpriteException, IOException { - canReach(1,1); + //canReach(1,1); mouseX = e.getX(); mouseY = e.getY(); if(e.getButton()==MouseEvent.BUTTON1) { diff --git a/src/SoundWrapper.java b/src/SoundWrapper.java index f1e0c26..b9e6924 100644 --- a/src/SoundWrapper.java +++ b/src/SoundWrapper.java @@ -6,19 +6,6 @@ public class SoundWrapper implements Serializable { transient public Sound sound; public String soundString; - public static Sound grass; - - static { - try { - grass = new Sound("sound/grass.wav"); - } catch (UnsupportedAudioFileException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (LineUnavailableException e) { - throw new RuntimeException(e); - } - } // please note that not as many constructors were implemented as BufferedImage, as this class was created before most sounds were added; // as such, backwards compatibility was not needed