Changed Mouse Click
parent
64f99d66b0
commit
6bee3d58f7
|
@ -121,6 +121,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
player.mousePressed(e);
|
player.mousePressed(e);
|
||||||
}
|
}
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
player.mouseReleased(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
|
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) {
|
if (isPaused) {
|
||||||
g.setColor(new Color(255, 255, 255, 100));
|
g.setColor(new Color(255, 255, 255, 100));
|
||||||
|
|
|
@ -53,7 +53,9 @@ public class GenericSprite extends Rectangle{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
public void move() throws IOException {
|
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 lowY = Math.max(0,(this.y/Tile.length)-6);
|
||||||
int highY = Math.min(lowY + 12, GamePanel.map[0].length);
|
int highY = Math.min(lowY + 12, GamePanel.map[0].length);
|
||||||
for(int i=lowX; i<highX; i++) {
|
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 (GamePanel.map[i][j] != null) {
|
||||||
if (collide(GamePanel.map[i][j], this.x + x, this.y + y)) {
|
if (collide(GamePanel.map[i][j], this.x + x, this.y + y)) {
|
||||||
if (GamePanel.map[i][j].isFinish&&isPlayer) {
|
if (GamePanel.map[i][j].isFinish&&isPlayer) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class NonPlayer extends GenericSprite {
|
||||||
|
|
||||||
public int health;
|
public int health;
|
||||||
|
|
||||||
|
public int fadeCounter;
|
||||||
// private final Sound bump;
|
// private final Sound bump;
|
||||||
|
|
||||||
public BufferedImage[][][] spriteArray;
|
public BufferedImage[][][] spriteArray;
|
||||||
|
@ -36,6 +36,7 @@ public class NonPlayer extends GenericSprite {
|
||||||
HEIGHT = npcHeight;
|
HEIGHT = npcHeight;
|
||||||
|
|
||||||
xVelocity = 3;
|
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);
|
g.drawImage(spriteArray[currentXDirection][currentYDirection][frame], x-GamePanel.camera.x, y, null);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ public class Player extends GenericSprite {
|
||||||
public static final int walkSpeedCap = 5;
|
public static final int walkSpeedCap = 5;
|
||||||
public boolean alive;
|
public boolean alive;
|
||||||
private final Sound jump;
|
private final Sound jump;
|
||||||
|
|
||||||
|
public boolean leftMouseDown;
|
||||||
// sA[0] is -x, -y
|
// sA[0] is -x, -y
|
||||||
// sA[1] is x, -y
|
// sA[1] is x, -y
|
||||||
// sA[2] is -x, y
|
// sA[2] is -x, y
|
||||||
|
@ -36,6 +38,7 @@ public class Player extends GenericSprite {
|
||||||
spriteArray = sprites;
|
spriteArray = sprites;
|
||||||
alive = true;
|
alive = true;
|
||||||
isPlayer = true;
|
isPlayer = true;
|
||||||
|
leftMouseDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,11 +208,19 @@ public class Player extends GenericSprite {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
|
if(e.getButton()==MouseEvent.BUTTON1) {
|
||||||
|
leftMouseDown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
int xx = e.getX();
|
int xx = e.getX();
|
||||||
int yy = e.getY();
|
int yy = e.getY();
|
||||||
if (GamePanel.bombs.size() < 3) {
|
if(e.getButton()==MouseEvent.BUTTON1) {
|
||||||
GamePanel.bombs.add(new StickyBomb(GamePanel.player.x + GamePanel.camera.x, GamePanel.player.y, 25,
|
leftMouseDown = false;
|
||||||
(xx - GamePanel.player.x) / 20, (yy - GamePanel.player.y) / 10, GamePanel.bomb, GamePanel.explosionArray));
|
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 {
|
public void addParticle(int x) throws IOException {
|
||||||
|
|
|
@ -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 disY = GamePanel.enemy.get(i).y+GamePanel.enemy.get(i).npcHeight/2 - (y+length/2);
|
||||||
double eHypo = Math.sqrt(disX*disX+disY*disY);
|
double eHypo = Math.sqrt(disX*disX+disY*disY);
|
||||||
if(eHypo<200){
|
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(){
|
public void move(){
|
||||||
|
if(yVelocity>50){yVelocity=50;}
|
||||||
update();
|
update();
|
||||||
if(fuse>0) {
|
if(fuse>0) {
|
||||||
fuse-=1;
|
fuse-=1;
|
||||||
|
@ -114,6 +121,7 @@ public class StickyBomb extends GenericSprite{
|
||||||
}
|
}
|
||||||
yVelocity+=3;
|
yVelocity+=3;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue