From 149b6898934dca6716df62003b5d7998bb6f78b1 Mon Sep 17 00:00:00 2001 From: bob Date: Thu, 16 Jun 2022 13:32:58 -0400 Subject: [PATCH] Working on moving steel --- src/FileManager.java | 2 +- src/GamePanel.java | 2 +- src/Player.java | 64 +++++++++++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/FileManager.java b/src/FileManager.java index 36afdd5..d9bd032 100644 --- a/src/FileManager.java +++ b/src/FileManager.java @@ -41,6 +41,6 @@ public class FileManager { FileOutputStream fileStream = new FileOutputStream(fileLocation); ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); objectStream.writeObject(o); - System.out.println(o + " " + fileLocation); + //System.out.println(o + " " + fileLocation); } } diff --git a/src/GamePanel.java b/src/GamePanel.java index c23e04d..261e913 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -161,7 +161,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ //make this class run at the same time as other classes (without this each class would "pause" while another class runs). By using threading we can remove lag, and also allows us to do features like display timers in real time! gameThread = new Thread(this); gameThread.start(); - System.out.println(gameThread); + //System.out.println(gameThread); } //paint is a method in java.awt library that we are overriding. It is a special method - it is called automatically in the background in order to update what appears in the window. You NEVER call paint() yourself diff --git a/src/Player.java b/src/Player.java index 15dc504..190db2b 100644 --- a/src/Player.java +++ b/src/Player.java @@ -18,7 +18,7 @@ public class Player extends GenericSprite { public static final int PLAYER_WIDTH = 52; public static final int PLAYER_HEIGHT = 94; - public static final int steelReachRange = 3*Tile.length; + public static final int steelReachRange = 4*Tile.length; public int lastXDirection, lastYDirection, lastFrame; public static final int walkSpeedCap = 5; @@ -132,13 +132,35 @@ public class Player extends GenericSprite { // return false; // } public void updatePlaceSteel(int x, int y){ + if(this.y<0){ + canPlaceSteel = false; + return; + } canPlaceSteel = true; boolean adjacent = false; int realX = x*Tile.length-GameFrame.game.camera.x; double xDis = (realX - GamePanel.GAME_WIDTH/2+ Tile.length/2) - (this.x+WIDTH/2); double yDis = (y*Tile.length + Tile.length/2) - (this.y+HEIGHT/2); double hypo = Math.sqrt(xDis*xDis+yDis*yDis); + int xx = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length; + int yy = (mouseY / Tile.length); //System.out.println(hypo +" "+xDis + " "+ realX); + + + for(NonPlayer e: GameFrame.game.enemy){ + System.out.println((xx*Tile.length)+" "+(yy*Tile.length)+" "); + System.out.print(" "+ (e.x+GamePanel.GAME_WIDTH/2) + " "+e.y+" "); +// if(){ +// +// } else { +// canPlaceSteel = false; +// return; +// } + } + if(Math.abs(xDis)<(WIDTH+Tile.length)/2&&Math.abs(yDis)<(HEIGHT+Tile.length)/2){ + canPlaceSteel = false; return; + } + int[][]check = {{1,0},{0,1},{-1,0},{0,-1}}; for(int[]a: check){ try{ @@ -151,10 +173,13 @@ public class Player extends GenericSprite { } } if(!adjacent){canPlaceSteel = false; return;} - if(hypo>3*Tile.length){canPlaceSteel = false; return;} + if(hypo>steelReachRange){canPlaceSteel = false; return;} if(GameFrame.game.map[x][y]!=null&&!GameFrame.game.map[x][y].replaceAble){canPlaceSteel = false; return;} - ; + if(!canReach(xx,yy)){canPlaceSteel = false; return;}; + //System.out.println(realX); } + + public void move() throws IOException { // mouseX = MouseInfo.getPointerInfo().getLocation().x; // mouseY = MouseInfo.getPointerInfo().getLocation().y; @@ -265,12 +290,13 @@ public class Player extends GenericSprite { int x = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length; int y = (mouseY / Tile.length); rightMouseDown = true; + if (!holdingSteel) { - if (GameFrame.game.map[x][y] != null&&GameFrame.game.map[x][y].movable) { - double xDis = (this.x+WIDTH/2) - (GameFrame.game.map[x][y].realX+Tile.length/2); - double yDis = (this.y+HEIGHT/2) - (GameFrame.game.map[x][y].y+Tile.length/2); - double hypo = Math.sqrt(xDis*xDis+yDis*yDis); - if(hypo