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
sssssssssssssssssd ! b qe qe
sssssssssssssssssd bbbbb ad ! ad
sssssssssssssssssd qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe
sssssssssssssssssd asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc
sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv
sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv
sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv
sssssssssssssssssdlllllad bbb qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv
sssssssssssssssssdllllladbb ooqwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv +
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3
sssssssssssssssssd bbbbb qwe ad ! ad qre
sssssssssssssssssd a d qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe ad
sssssssssssssssssd zxc asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc ad
sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv ad
sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv ad
sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv ad
sssssssssssssssssdlllllad bbb qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv ad
sssssssssssssssssdllllladbb ooqwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv + ad
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3

View File

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

View File

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

View File

@ -138,7 +138,10 @@ public class Player extends GenericSprite {
canPlaceSteel = true;
boolean adjacent = false;
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}};
for(int[]a: check){
try{
@ -152,6 +155,7 @@ public class Player extends GenericSprite {
}
if(!adjacent){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 {
// mouseX = MouseInfo.getPointerInfo().getLocation().x;