Merge remote-tracking branch 'origin/master'

master
John 2022-06-14 14:55:05 -04:00
commit 3caa0b8c37
5 changed files with 69 additions and 7 deletions

View File

@ -224,9 +224,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
} else {
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;
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);
@ -299,7 +299,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
//run() method is what makes the game continue running without end. It calls other methods to move objects, check for collision, and update the screen
public void run(){
LevelManager.setLevel(1);
//the CPU runs our game code too quickly - we need to slow it down! The following lines of code "force" the computer to get stuck in a loop for short intervals between calling other methods to update the screen.
long lastTime = System.nanoTime();
double amountOfTicks = 60;
@ -314,7 +313,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
//only move objects around and update screen if enough time has passed
if(delta >= 1){
if (!isPaused) {
if (!isPaused && MenuPanel.gameStart) {
// only perform game functions if game is not paused
try {
move();

View File

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

View File

@ -36,6 +36,8 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
// keeps track of how many ticks has elapsed since last frame change
public int currentBox = 0;
public static boolean gameStart = false;
// image imports begin here
public BufferedImage backgroundImage = GamePanel.getImage("img/backgrounds/pointyMountains.png");
@ -145,8 +147,12 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
//if a key is pressed, we'll send it over to the Player class for processing
public void keyPressed(KeyEvent e) {
e = UtilityFunction.intercept(e, GamePanel.middlewareArray);
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if(textBoxArray.get(currentBox).id.equals("game")){
gameStart = true;
}
// logic for different screens starts here
CardLayout cardLayout = (CardLayout) gameFrame.getLayout();
cardLayout.show(gameFrame, textBoxArray.get(currentBox).id);

View File

@ -15,6 +15,8 @@ public class Player extends GenericSprite {
public final int SPEED = 5;
public static final int PLAYER_WIDTH = 52;
public static final int PLAYER_HEIGHT = 94;
public static final int steelReachRange = 3*Tile.length;
public int lastXDirection, lastYDirection, lastFrame;
public int upKey, downKey, rightKey, leftKey;
@ -125,9 +127,40 @@ public class Player extends GenericSprite {
}
return canUpdate;
}
// public boolean SteelCollide(GenericSprite g, int x, int y){
// if(x+WIDTH>tile.realX&&x<tile.realX+Tile.length&&y-tile.y<Tile.length&&tile.y-y<HEIGHT){
// return true;
// }
// return false;
// }
public void updatePlaceSteel(int x, int y){
canPlaceSteel = true;
boolean adjacent = false;
int realX = x*Tile.length-GamePanel.camera.x;
System.out.println(realX);
int[][]check = {{1,0},{0,1},{-1,0},{0,-1}};
for(int[]a: check){
try{
if(GamePanel.map[x+a[0]][y+a[1]]!=null&&!GamePanel.map[x+a[0]][y+a[1]].replaceAble){
adjacent = true;
break;
}
} catch(Exception e){
}
}
if(!adjacent){canPlaceSteel = false; return;}
if(GamePanel.map[x][y]!=null&&!GamePanel.map[x][y].replaceAble){canPlaceSteel = false; return;};
}
public void move() throws IOException {
// mouseX = MouseInfo.getPointerInfo().getLocation().x;
// mouseY = MouseInfo.getPointerInfo().getLocation().y;
int Tilex = (mouseX + GamePanel.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
int Tiley = (mouseY / Tile.length);
if(holdingSteel){
updatePlaceSteel(Tilex,Tiley);
}
if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){
GamePanel.camera.x += -Math.signum(xVelocity);
}
@ -214,6 +247,7 @@ public class Player extends GenericSprite {
LevelManager.setLevel(LevelManager.level);
GamePanel.camera.x = LevelManager.xSpawn;
y = LevelManager.ySpawn;
holdingSteel = false;
}
public void mousePressed(MouseEvent e) throws SpriteException, IOException {
@ -228,12 +262,23 @@ public class Player extends GenericSprite {
rightMouseDown = true;
if (!holdingSteel) {
if (GamePanel.map[x][y] != null&&GamePanel.map[x][y].movable) {
double xDis = (this.x+WIDTH/2) - (GamePanel.map[x][y].realX+Tile.length/2);
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)&&canPlaceSteel){
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].movable = true;
GamePanel.map[x][y].previousBlock = temp;
holdingSteel = false;
}
}
@ -274,6 +319,9 @@ public class Player extends GenericSprite {
}
public int draw(Graphics g, int frame) {
frame %= spriteArray[0][0].length;
if(rightMouseDown){
g.drawOval(x+WIDTH/2-steelReachRange,y+HEIGHT/2-steelReachRange, steelReachRange*2,steelReachRange*2);
}
if (!upPressed && !downPressed && !leftPressed && !rightPressed) {
g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-10, y, null);
return 0;
@ -287,4 +335,6 @@ public class Player extends GenericSprite {
}
//public int BfsDis()
}

View File

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