From 1c3ae30225a8c60eaa1b87e3b552fab41486ea50 Mon Sep 17 00:00:00 2001 From: Chara1236 Date: Sun, 12 Jun 2022 17:28:27 -0400 Subject: [PATCH] Moving Blocks ProtoType --- img/tiles/boxes/steel.png | Bin 0 -> 618 bytes saves/Level1.txt | 4 ++-- src/GamePanel.java | 14 ++++++++++---- src/GenericSprite.java | 2 +- src/MapReader.java | 10 ++++++---- src/NonPlayer.java | 4 ++-- src/Player.java | 33 ++++++++++++++++++++++++++++++--- src/StickyBomb.java | 5 +++++ src/Tile.java | 3 +++ 9 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 img/tiles/boxes/steel.png diff --git a/img/tiles/boxes/steel.png b/img/tiles/boxes/steel.png new file mode 100644 index 0000000000000000000000000000000000000000..eb0ae7d74f2a6a196fa9776506326ab2130ef05d GIT binary patch literal 618 zcmeAS@N?(olHy`uVBq!ia0vp^ZXnFT1|$ph9NbVS^b7^UA9?+SE#_-j$#7+$OL5(bEbetMq#o>WNeM3?|p;uA9EPSS?ad&dz*A z;4;_1s}tuI@2?Z>K73K`*}4kh@XTNO46Tw&Bl-WN@m{uhq936zA8LE>(2iG{%?BO) zGv$glpSoZc^+NM(Ro>@2a%@t%4p#z~$*bOa$=oZZ@Jgc~FW~X5>mGc+?9^OD-Wx1j zRME;Qc~sixg+^S0!2*l+gH4Y_*o3=`C2}Xck+?DIxrZi2>wh{FMn8=DrkB=I=&9_46L>Jn?y^3vu>6;b6W7188b z?2#~URg#1&lkxh!rS#TkhSrLJ3@I|P^Rd%W`Y-k?KgPHie}7m)6H+qYcE zZM#Ua(ptop;G=@PhHQs9|AFe&JkxJHx&=ckpFCl;kLBvtAq<>cq5 vq*Ur97gZLN0&&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;