Changed Mouse Click

master
bob 2022-06-09 14:19:23 -04:00
parent 64f99d66b0
commit 6bee3d58f7
5 changed files with 33 additions and 8 deletions

View File

@ -121,6 +121,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
public void mousePressed(MouseEvent e) {
player.mousePressed(e);
}
public void mouseReleased(MouseEvent e) {
player.mouseReleased(e);
}
});
this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
@ -181,7 +184,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
}
}
}
g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length),100,100);
g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100);
if (isPaused) {
g.setColor(new Color(255, 255, 255, 100));

View File

@ -53,7 +53,9 @@ public class GenericSprite extends Rectangle{
}
public void mouseReleased(MouseEvent e) {
}
public void move() throws IOException {
}
@ -88,7 +90,7 @@ public class GenericSprite extends Rectangle{
int lowY = Math.max(0,(this.y/Tile.length)-6);
int highY = Math.min(lowY + 12, GamePanel.map[0].length);
for(int i=lowX; i<highX; i++) {
for (int j = lowY; j < highY; j++) {
for (int j = 0; j < GamePanel.map[0].length; j++) {
if (GamePanel.map[i][j] != null) {
if (collide(GamePanel.map[i][j], this.x + x, this.y + y)) {
if (GamePanel.map[i][j].isFinish&&isPlayer) {

View File

@ -20,7 +20,7 @@ public class NonPlayer extends GenericSprite {
public int health;
public int fadeCounter;
// private final Sound bump;
public BufferedImage[][][] spriteArray;
@ -36,6 +36,7 @@ public class NonPlayer extends GenericSprite {
HEIGHT = npcHeight;
xVelocity = 3;
fadeCounter = GlobalState.second*3;;
}
@ -91,7 +92,7 @@ public class NonPlayer extends GenericSprite {
g.drawImage(spriteArray[currentXDirection][currentYDirection][frame], x-GamePanel.camera.x, y, null);
return 1;
} else {
g.drawImage(spriteArray[currentXDirection][currentYDirection][spriteArray[0][0].length-1], x-GamePanel.camera.x, y, null);
g.drawImage(spriteArray[currentXDirection][currentYDirection][spriteArray[0][0].length-1], x-GamePanel.camera.x, (int)(y+HEIGHT/1.7), null);
return 0;
}
}

View File

@ -21,6 +21,8 @@ public class Player extends GenericSprite {
public static final int walkSpeedCap = 5;
public boolean alive;
private final Sound jump;
public boolean leftMouseDown;
// sA[0] is -x, -y
// sA[1] is x, -y
// sA[2] is -x, y
@ -36,6 +38,7 @@ public class Player extends GenericSprite {
spriteArray = sprites;
alive = true;
isPlayer = true;
leftMouseDown = false;
}
@ -205,11 +208,19 @@ public class Player extends GenericSprite {
}
public void mousePressed(MouseEvent e) {
if(e.getButton()==MouseEvent.BUTTON1) {
leftMouseDown = true;
}
}
public void mouseReleased(MouseEvent e) {
int xx = e.getX();
int yy = e.getY();
if (GamePanel.bombs.size() < 3) {
GamePanel.bombs.add(new StickyBomb(GamePanel.player.x + GamePanel.camera.x, GamePanel.player.y, 25,
(xx - GamePanel.player.x) / 20, (yy - GamePanel.player.y) / 10, GamePanel.bomb, GamePanel.explosionArray));
if(e.getButton()==MouseEvent.BUTTON1) {
leftMouseDown = false;
if (GamePanel.bombs.size() < 3) {
GamePanel.bombs.add(new StickyBomb(GamePanel.player.x + GamePanel.camera.x, GamePanel.player.y, 25,
(xx - GamePanel.player.x) / 20, (yy - GamePanel.player.y) / 10, GamePanel.bomb, GamePanel.explosionArray));
}
}
}
public void addParticle(int x) throws IOException {

View File

@ -58,12 +58,19 @@ public class StickyBomb extends GenericSprite{
double disY = GamePanel.enemy.get(i).y+GamePanel.enemy.get(i).npcHeight/2 - (y+length/2);
double eHypo = Math.sqrt(disX*disX+disY*disY);
if(eHypo<200){
GamePanel.enemy.remove(i);
GamePanel.enemy.get(i).isDead = true;
}
if(GamePanel.enemy.get(i).isDead){
GamePanel.enemy.get(i).fadeCounter--;
if(GamePanel.enemy.get(i).fadeCounter<=0){
GamePanel.enemy.remove(i);
}
}
}
}
public void move(){
if(yVelocity>50){yVelocity=50;}
update();
if(fuse>0) {
fuse-=1;
@ -114,6 +121,7 @@ public class StickyBomb extends GenericSprite{
}
yVelocity+=3;
}
}