Allow left click to place steel

master
John 2022-06-19 18:02:55 -07:00
parent bbadd99a6f
commit 06e81d4646
1 changed files with 15 additions and 5 deletions

View File

@ -40,6 +40,8 @@ public class Player extends GenericSprite {
// sA[2] is -x, y // sA[2] is -x, y
// sA[3] is x, y // sA[3] is x, y
public BufferedImageWrapper[][][] spriteArray; public BufferedImageWrapper[][][] spriteArray;
public boolean leftClickPlacedSteel;
public Player(int x, int y, BufferedImageWrapper[][][] sprites) throws UnsupportedAudioFileException, LineUnavailableException, IOException { public Player(int x, int y, BufferedImageWrapper[][][] sprites) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
super(x, y, PLAYER_HEIGHT, PLAYER_WIDTH); super(x, y, PLAYER_HEIGHT, PLAYER_WIDTH);
// jump = new Sound("sound/jump.wav"); // jump = new Sound("sound/jump.wav");
@ -306,13 +308,17 @@ public class Player extends GenericSprite {
mouseX = e.getX(); mouseX = e.getX();
mouseY = e.getY(); mouseY = e.getY();
if(e.getButton()==MouseEvent.BUTTON1) { if(e.getButton()==MouseEvent.BUTTON1) {
leftMouseDown = true; int x = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
int y = (mouseY / Tile.length);
if (holdingSteel && ((GameFrame.game.map[x][y] == null || GameFrame.game.map[x][y].replaceAble) && canPlaceSteel)) { if (holdingSteel && ((GameFrame.game.map[x][y] == null || GameFrame.game.map[x][y].replaceAble) && canPlaceSteel)) {
Tile temp = GameFrame.game.map[x][y]; Tile temp = GameFrame.game.map[x][y];
GameFrame.game.map[x][y] = new SingleTile(x * Tile.length - (GamePanel.GAME_WIDTH / 2), y * Tile.length, new BufferedImageWrapper(("img/tiles/boxes/steel.png"))); GameFrame.game.map[x][y] = new SingleTile(x * Tile.length - (GamePanel.GAME_WIDTH / 2), y * Tile.length, new BufferedImageWrapper(("img/tiles/boxes/steel.png")));
GameFrame.game.map[x][y].movable = true; GameFrame.game.map[x][y].movable = true;
GameFrame.game.map[x][y].previousBlock = temp; GameFrame.game.map[x][y].previousBlock = temp;
holdingSteel = false; holdingSteel = false;
leftClickPlacedSteel = true;
} else {
leftMouseDown = true;
} }
} }
if(e.getButton()==MouseEvent.BUTTON3) { if(e.getButton()==MouseEvent.BUTTON3) {
@ -414,12 +420,16 @@ public class Player extends GenericSprite {
mouseY = e.getY(); mouseY = e.getY();
if(e.getButton()==MouseEvent.BUTTON1) { if(e.getButton()==MouseEvent.BUTTON1) {
leftMouseDown = false; leftMouseDown = false;
if (GameFrame.game.bombs.size() < 2 && LevelManager.bombs>0 && !holdingSteel) { if (leftClickPlacedSteel) {
leftClickPlacedSteel = false;
} else {
if (GameFrame.game.bombs.size() < 2 && LevelManager.bombs > 0 && !holdingSteel) {
LevelManager.bombs--; LevelManager.bombs--;
GameFrame.game.bombs.add(new StickyBomb(GameFrame.game.player.x + GameFrame.game.camera.x + WIDTH/2, GameFrame.game.player.y+HEIGHT/2, GameFrame.game.bombs.add(new StickyBomb(GameFrame.game.player.x + GameFrame.game.camera.x + WIDTH / 2, GameFrame.game.player.y + HEIGHT / 2,
(mouseX - GameFrame.game.player.x) / 20, (mouseY - GameFrame.game.player.y) / 10, GameFrame.game.bomb, GameFrame.game.explosionArray)); (mouseX - GameFrame.game.player.x) / 20, (mouseY - GameFrame.game.player.y) / 10, GameFrame.game.bomb, GameFrame.game.explosionArray));
} }
} }
}
if(e.getButton()==MouseEvent.BUTTON3){ if(e.getButton()==MouseEvent.BUTTON3){
rightMouseDown = false; rightMouseDown = false;