WOrking o n steel

master
bob 2022-06-13 13:53:58 -04:00
parent 0f69b3595a
commit 4b4b89dc89
4 changed files with 29 additions and 5 deletions

View File

@ -223,9 +223,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
} else { } else {
filePath = "img/tiles/boxes/redSteel.png"; filePath = "img/tiles/boxes/redSteel.png";
} }
double x = ((player.mouseX-(Tile.length/2)) / Tile.length)*Tile.length + (camera.x/Tile.length)*Tile.length; int x = (player.mouseX + camera.x + GAME_WIDTH / 2) / Tile.length;
double y = ((player.mouseY / Tile.length))*Tile.length; double y = ((player.mouseY / Tile.length))*Tile.length;
g.drawImage(getImage(filePath),(int)x-camera.x+Tile.length/2+1,(int)y,Tile.length,Tile.length,null); g.drawImage(getImage(filePath),x*Tile.length - (GamePanel.GAME_WIDTH/2)-camera.x,(int)y,Tile.length,Tile.length,null);
} }
// 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);

View File

@ -87,6 +87,7 @@ public class MapReader {
} else if(file.charAt(i)=='v'){ } else if(file.charAt(i)=='v'){
newTile("img/tiles/background/wall.png"); newTile("img/tiles/background/wall.png");
GamePanel.map[x][y].collision = false; GamePanel.map[x][y].collision = false;
GamePanel.map[x][y].replaceAble = true;
} else if(file.charAt(i)=='l'){ } else if(file.charAt(i)=='l'){
newTile("img/tiles/terrain/lava.png"); newTile("img/tiles/terrain/lava.png");
GamePanel.map[x][y].nonBombCollide = true; GamePanel.map[x][y].nonBombCollide = true;

View File

@ -15,6 +15,8 @@ public class Player extends GenericSprite {
public final int SPEED = 5; public final int SPEED = 5;
public static final int PLAYER_WIDTH = 52; public static final int PLAYER_WIDTH = 52;
public static final int PLAYER_HEIGHT = 94; public static final int PLAYER_HEIGHT = 94;
public static final int steelReachRange = 3*Tile.length;
public int lastXDirection, lastYDirection, lastFrame; public int lastXDirection, lastYDirection, lastFrame;
public int upKey, downKey, rightKey, leftKey; public int upKey, downKey, rightKey, leftKey;
@ -214,6 +216,7 @@ public class Player extends GenericSprite {
LevelManager.setLevel(LevelManager.level); LevelManager.setLevel(LevelManager.level);
GamePanel.camera.x = LevelManager.xSpawn; GamePanel.camera.x = LevelManager.xSpawn;
y = LevelManager.ySpawn; y = LevelManager.ySpawn;
holdingSteel = false;
} }
public void mousePressed(MouseEvent e) throws SpriteException, IOException { public void mousePressed(MouseEvent e) throws SpriteException, IOException {
@ -228,12 +231,23 @@ public class Player extends GenericSprite {
rightMouseDown = true; rightMouseDown = true;
if (!holdingSteel) { if (!holdingSteel) {
if (GamePanel.map[x][y] != null&&GamePanel.map[x][y].movable) { if (GamePanel.map[x][y] != null&&GamePanel.map[x][y].movable) {
holdingSteel = true; double xDis = (this.x+WIDTH/2) - (GamePanel.map[x][y].realX+Tile.length/2);
GamePanel.map[x][y] = null; double yDis = (this.y+HEIGHT/2) - (GamePanel.map[x][y].y+Tile.length/2);
double hypo = Math.sqrt(xDis*xDis+yDis*yDis);
if(hypo<steelReachRange) {
holdingSteel = true;
if (GamePanel.map[x][y].previousBlock != null) {
GamePanel.map[x][y] = GamePanel.map[x][y].previousBlock;
} else {
GamePanel.map[x][y] = null;
}
}
} }
} else if(GamePanel.map[x][y] == null){ } else if(GamePanel.map[x][y] == null||GamePanel.map[x][y].replaceAble){
Tile temp = GamePanel.map[x][y];
GamePanel.map[x][y] = new SingleTile(x*Tile.length - (GamePanel.GAME_WIDTH/2), y*Tile.length, GamePanel.getImage("img/tiles/boxes/steel.png")); GamePanel.map[x][y] = new SingleTile(x*Tile.length - (GamePanel.GAME_WIDTH/2), y*Tile.length, GamePanel.getImage("img/tiles/boxes/steel.png"));
GamePanel.map[x][y].movable = true; GamePanel.map[x][y].movable = true;
GamePanel.map[x][y].previousBlock = temp;
holdingSteel = false; holdingSteel = false;
} }
} }
@ -274,6 +288,9 @@ public class Player extends GenericSprite {
} }
public int draw(Graphics g, int frame) { public int draw(Graphics g, int frame) {
frame %= spriteArray[0][0].length; frame %= spriteArray[0][0].length;
// if(rightMouseDown){
// g.drawOval(mouseX,mouseY, steelReachRange,steelReachRange);
// }
if (!upPressed && !downPressed && !leftPressed && !rightPressed) { if (!upPressed && !downPressed && !leftPressed && !rightPressed) {
g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-10, y, null); g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-10, y, null);
return 0; return 0;

View File

@ -17,6 +17,10 @@ public class Tile {
public boolean movable; public boolean movable;
public int realX; public int realX;
public static final int length = 35; public static final int length = 35;
public boolean replaceAble;
public Tile previousBlock;
public Tile(int x, int y){ public Tile(int x, int y){
isFinish = false; isFinish = false;
collision = true; collision = true;
@ -26,6 +30,8 @@ public class Tile {
nonBombCollide = false; nonBombCollide = false;
breakable = false; breakable = false;
movable = false; movable = false;
replaceAble = false;
previousBlock = null;
} }
public void update(){ public void update(){
realX = x-GamePanel.camera.x; realX = x-GamePanel.camera.x;