Working on moving block

master
Chara1236 2022-06-14 21:35:05 -04:00
parent 3caa0b8c37
commit a569a84a7e
4 changed files with 33 additions and 22 deletions

View File

@ -7,12 +7,12 @@ sssssssssssssssssd 1 1lllllllll1 1 1
sssssssssssssssssd 1 sssssssssssssssssd 1
sssssssssssssssssd sssssssssssssssssd
sssssssssssssssssd ! b qe qe sssssssssssssssssd ! b qe qe
sssssssssssssssssd bbbbb ad ! ad sssssssssssssssssd bbbbb qwe ad ! ad qre
sssssssssssssssssd qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe sssssssssssssssssd a d qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe ad
sssssssssssssssssd asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc sssssssssssssssssd zxc asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc ad
sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv ad
sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv ad
sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv ad
sssssssssssssssssdlllllad bbb qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv sssssssssssssssssdlllllad bbb qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv ad
sssssssssssssssssdllllladbb ooqwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv + sssssssssssssssssdllllladbb ooqwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv + ad
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3 ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3

View File

@ -251,9 +251,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
bombs.get(i).move(); bombs.get(i).move();
} }
for(int i=0; i<particles.size(); i++){ for(int i=0; i<particles.size(); i++){
if(particles.get(i)!=null) {
particles.get(i).move(); particles.get(i).move();
} }
} }
}
//handles all collision detection and responds accordingly //handles all collision detection and responds accordingly
public void checkCollision() { public void checkCollision() {
@ -332,11 +334,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
playerFrame = (playerFrame + 1) % 11; playerFrame = (playerFrame + 1) % 11;
playerFrameCounter -= 5; playerFrameCounter -= 5;
// if the player has moved enough to justify a frame change, a new save will also be made // if the player has moved enough to justify a frame change, a new save will also be made
try { // try {
FileManager.writeObjectToFile("local/game_state", this); // FileManager.writeObjectToFile("local/game_state", this);
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} }
} }
repaint(); repaint();

View File

@ -92,12 +92,17 @@ public class NonPlayer extends GenericSprite {
g.drawImage(spriteArray[currentXDirection][currentYDirection][frame], x-GamePanel.camera.x, y, null); g.drawImage(spriteArray[currentXDirection][currentYDirection][frame], x-GamePanel.camera.x, y, null);
return 1; return 1;
} else { } else {
try {
((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) fadeCounter)); ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) fadeCounter));
g.drawImage(spriteArray[currentXDirection][currentYDirection][spriteArray[0][0].length - 1], x - GamePanel.camera.x, (int) (y + HEIGHT / 1.7), null); g.drawImage(spriteArray[currentXDirection][currentYDirection][spriteArray[0][0].length - 1], x - GamePanel.camera.x, (int) (y + HEIGHT / 1.7), null);
// reset composite to not affect other sprites being drawn // reset composite to not affect other sprites being drawn
((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)); ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
fadeCounter -= 0.01; fadeCounter -= 0.01;
return 0; return 0;
}catch(Exception e){
return 0;
}
} }
} }
} }

View File

@ -138,7 +138,10 @@ public class Player extends GenericSprite {
canPlaceSteel = true; canPlaceSteel = true;
boolean adjacent = false; boolean adjacent = false;
int realX = x*Tile.length-GamePanel.camera.x; int realX = x*Tile.length-GamePanel.camera.x;
System.out.println(realX); 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);
//System.out.println(hypo +" "+xDis + " "+ realX);
int[][]check = {{1,0},{0,1},{-1,0},{0,-1}}; int[][]check = {{1,0},{0,1},{-1,0},{0,-1}};
for(int[]a: check){ for(int[]a: check){
try{ try{
@ -152,6 +155,7 @@ public class Player extends GenericSprite {
} }
if(!adjacent){canPlaceSteel = false; return;} if(!adjacent){canPlaceSteel = false; return;}
if(GamePanel.map[x][y]!=null&&!GamePanel.map[x][y].replaceAble){canPlaceSteel = false; return;}; if(GamePanel.map[x][y]!=null&&!GamePanel.map[x][y].replaceAble){canPlaceSteel = false; return;};
if(hypo>3*Tile.length){canPlaceSteel = false; return;}
} }
public void move() throws IOException { public void move() throws IOException {
// mouseX = MouseInfo.getPointerInfo().getLocation().x; // mouseX = MouseInfo.getPointerInfo().getLocation().x;