diff --git a/img/tiles/boxes/steel.png b/img/tiles/boxes/steel.png new file mode 100644 index 0000000..eb0ae7d Binary files /dev/null and b/img/tiles/boxes/steel.png differ diff --git a/saves/Level1.txt b/saves/Level1.txt index e9667bd..aa82d53 100644 --- a/saves/Level1.txt +++ b/saves/Level1.txt @@ -13,6 +13,6 @@ sssssssssssssssssd asd a sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv -sssssssssssssssssdlllllad qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv -sssssssssssssssssdllllladbb qwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv + +sssssssssssssssssdlllllad bbb qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv +sssssssssssssssssdllllladbb ooqwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv + ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3 \ No newline at end of file diff --git a/src/GamePanel.java b/src/GamePanel.java index 3f3b9b7..b7ab94e 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -121,8 +121,14 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ //add the MousePressed method from the MouseAdapter - by doing this we can listen for mouse input. We do this differently from the KeyListener because MouseAdapter has SEVEN mandatory methods - we only need one of them, and we don't want to make 6 empty methods addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { - player.mousePressed(e); - } + try { + player.mousePressed(e); + } catch (SpriteException ex) { + throw new RuntimeException(ex); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } public void mouseReleased(MouseEvent e) { player.mouseReleased(e); } @@ -203,8 +209,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ (player.mouseX - GamePanel.player.x) / 20, (player.mouseY - GamePanel.player.y) / 10); bombDir.draw(g); } - // g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100); - + g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100); + g.drawString(camera.x+" "+((player.mouseX+camera.x+GAME_WIDTH/2)/Tile.length)+" "+player.leftMouseDown,100,200); g.drawImage(bomb,20,20,35,35,null); g.drawString("X"+LevelManager.bombs,60,40); if (isPaused) { diff --git a/src/GenericSprite.java b/src/GenericSprite.java index 024e9c1..03d40d4 100644 --- a/src/GenericSprite.java +++ b/src/GenericSprite.java @@ -49,7 +49,7 @@ public class GenericSprite extends Rectangle{ //called from GamePanel whenever a mouse click is detected //changes the current location of the ball to be wherever the mouse is located on the screen - public void mousePressed(MouseEvent e){ + public void mousePressed(MouseEvent e) throws SpriteException, IOException { } diff --git a/src/MapReader.java b/src/MapReader.java index 8585ad6..88de8c2 100644 --- a/src/MapReader.java +++ b/src/MapReader.java @@ -1,15 +1,13 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; import java.io.*; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Scanner; public class MapReader { private static int x = 0; private static int y = 0; - private static int TileX = 0; - private static int TileY = 0; + public static int TileX = 0; + public static int TileY = 0; //Input game map /* 1: Normal Grass @@ -23,6 +21,7 @@ public class MapReader { v= background Grass: */ + //o = steel public static void inputMap(String filePath) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException { x = 0; @@ -95,6 +94,9 @@ public class MapReader { if(y>0&&GamePanel.map[x][y-1]==null) { GamePanel.particleTiles.add(GamePanel.map[x][y]); } + } else if(file.charAt(i)=='o'){ + newTile("img/tiles/boxes/steel.png"); + GamePanel.map[x][y].movable = true; } x+=1; } diff --git a/src/NonPlayer.java b/src/NonPlayer.java index bfc261c..51f9aa7 100644 --- a/src/NonPlayer.java +++ b/src/NonPlayer.java @@ -53,8 +53,8 @@ public class NonPlayer extends GenericSprite { } public void move(){ if (isDead) { - // preemptively end move function if enemy is dead - return; + xVelocity = 0; + // return; } if(!canUpdate(xVelocity, 0)){ xVelocity*=-1; diff --git a/src/Player.java b/src/Player.java index 341cdc9..8d3a8ea 100644 --- a/src/Player.java +++ b/src/Player.java @@ -27,6 +27,9 @@ public class Player extends GenericSprite { public boolean leftMouseDown; + public boolean rightMouseDown; + boolean holdingSteel; + // sA[0] is -x, -y // sA[1] is x, -y @@ -44,6 +47,7 @@ public class Player extends GenericSprite { alive = true; isPlayer = true; leftMouseDown = false; + holdingSteel = false; } @@ -210,14 +214,31 @@ public class Player extends GenericSprite { y = LevelManager.ySpawn; } - public void mousePressed(MouseEvent e) { + public void mousePressed(MouseEvent e) throws SpriteException, IOException { mouseX = e.getX(); mouseY = e.getY(); if(e.getButton()==MouseEvent.BUTTON1) { leftMouseDown = true; - } - + if(e.getButton()==MouseEvent.BUTTON3) { + int x = (mouseX + GamePanel.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length; + int y = (mouseY / Tile.length); + if (GamePanel.map[x][y] != null) { + if (!holdingSteel) { + rightMouseDown = true; + if (GamePanel.map[x][y].movable) { + holdingSteel = true; + GamePanel.map[x][y] = null; + } + } else { + holdingSteel = false; + MapReader.TileX = x; + MapReader.TileY = y; + MapReader.newTile("img/tiles/boxes/steel.png"); + GamePanel.map[x][y].movable = true; + } + } + } } public void mouseDragged(MouseEvent e) { @@ -236,6 +257,9 @@ public class Player extends GenericSprite { (mouseX - GamePanel.player.x) / 20, (mouseY - GamePanel.player.y) / 10, GamePanel.bomb, GamePanel.explosionArray)); } } + if(e.getButton()==MouseEvent.BUTTON3){ + rightMouseDown = false; + } } public void addParticle(int x) throws IOException { if(GlobalState.randInt(1,3)==3) { @@ -246,6 +270,9 @@ public class Player extends GenericSprite { public int draw(Graphics g, int frame) { //g.drawString(mouseX+" "+mouseY, 300, 300); frame %= spriteArray[0][0].length; + if(rightMouseDown){ + g.drawRect(mouseX,mouseY,35,35); + } if (!upPressed && !downPressed && !leftPressed && !rightPressed) { g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-10, y, null); return 0; diff --git a/src/StickyBomb.java b/src/StickyBomb.java index 1472049..89b4df5 100644 --- a/src/StickyBomb.java +++ b/src/StickyBomb.java @@ -106,6 +106,11 @@ public class StickyBomb extends GenericSprite{ explode(); } } + if(canUpdate(1,1)&&canUpdate(-1,1)&&canUpdate(0,-1)&&isMove == false&&fuse>0){ + isMove = true; + xVelocity = 0; + yVelocity = 0; + } if(isMove) { if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){ checked = true; diff --git a/src/Tile.java b/src/Tile.java index 4c02e5c..48cac79 100644 --- a/src/Tile.java +++ b/src/Tile.java @@ -13,6 +13,8 @@ public class Tile { public boolean kills; public boolean breakable; + + public boolean movable; public int realX; public static final int length = 35; public Tile(int x, int y){ @@ -23,6 +25,7 @@ public class Tile { this.y = y; nonBombCollide = false; breakable = false; + movable = false; } public void update(){ realX = x-GamePanel.camera.x;