WOrking o n steel

master
bob 2022-06-14 13:34:18 -04:00
parent d73b2d20a2
commit 30779b1cc0
3 changed files with 44 additions and 6 deletions

View File

@ -298,7 +298,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
//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;
@ -313,7 +312,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
//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

@ -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

@ -127,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);
}
@ -243,7 +274,7 @@ public class Player extends GenericSprite {
}
}
}
} else if(GamePanel.map[x][y] == null||GamePanel.map[x][y].replaceAble){
} 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;
@ -288,9 +319,9 @@ public class Player extends GenericSprite {
}
public int draw(Graphics g, int frame) {
frame %= spriteArray[0][0].length;
// if(rightMouseDown){
// g.drawOval(mouseX,mouseY, steelReachRange,steelReachRange);
// }
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;
@ -304,4 +335,6 @@ public class Player extends GenericSprite {
}
//public int BfsDis()
}