2022-06-07 18:12:48 +01:00
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import java.awt.event.MouseEvent;
|
2022-06-07 18:19:54 +01:00
|
|
|
import java.awt.image.BufferedImage;
|
2022-06-07 18:12:48 +01:00
|
|
|
|
|
|
|
public class StickyBomb extends GenericSprite{
|
|
|
|
public int length;
|
|
|
|
public int xVelocity;
|
|
|
|
public int yVelocity;
|
|
|
|
public boolean isMove;
|
|
|
|
public int realX;
|
2022-06-07 18:19:54 +01:00
|
|
|
BufferedImage sprite;
|
2022-06-07 18:12:48 +01:00
|
|
|
|
2022-06-07 18:19:54 +01:00
|
|
|
public StickyBomb(int x, int y, int length, int xVelocity, int yVelocity, BufferedImage sprite){
|
2022-06-07 18:12:48 +01:00
|
|
|
super(x,y,length,length);
|
|
|
|
this.length = length;
|
|
|
|
this.xVelocity = xVelocity;
|
|
|
|
this.yVelocity = yVelocity;
|
2022-06-07 18:19:54 +01:00
|
|
|
this.sprite = sprite;
|
2022-06-07 18:12:48 +01:00
|
|
|
isMove = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void update(){
|
|
|
|
realX = x - GamePanel.camera.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void move(){
|
|
|
|
update();
|
|
|
|
if(isMove) {
|
|
|
|
if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){
|
|
|
|
x += -Math.signum(xVelocity);
|
|
|
|
//isMove = false;
|
|
|
|
}
|
|
|
|
if(!canUpdate(xVelocity, 0)){
|
|
|
|
isMove = false;
|
|
|
|
int updateAmount = 0;
|
|
|
|
if(xVelocity>0){
|
|
|
|
while(canUpdate(updateAmount, 0)){
|
|
|
|
updateAmount++;
|
|
|
|
}
|
|
|
|
x+=updateAmount-1;
|
|
|
|
} else if(xVelocity<0){
|
|
|
|
while(canUpdate(updateAmount, 0)){
|
|
|
|
updateAmount--;
|
|
|
|
}
|
|
|
|
x+=updateAmount+1;
|
|
|
|
}
|
|
|
|
xVelocity = 0;
|
|
|
|
}
|
|
|
|
if(!canUpdate(0, yVelocity)){
|
|
|
|
isMove = false;
|
|
|
|
if(yVelocity>0){
|
|
|
|
while(canUpdate(0,1)){
|
|
|
|
y+=1;
|
|
|
|
}
|
|
|
|
isGrounded = true;
|
|
|
|
} else if(yVelocity<0){
|
|
|
|
while(canUpdate(0,-1)){
|
|
|
|
y-=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yVelocity = 0;
|
|
|
|
}
|
|
|
|
if(canUpdate(xVelocity, yVelocity)) {
|
|
|
|
y = y + (int) yVelocity;
|
|
|
|
x = x + (int) xVelocity;
|
|
|
|
} else {
|
|
|
|
isMove = false;
|
|
|
|
}
|
|
|
|
yVelocity+=3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mousePressed(MouseEvent e){
|
|
|
|
int xx = e.getX();
|
|
|
|
int yy = e.getY();
|
2022-06-07 18:48:31 +01:00
|
|
|
GamePanel.b = new StickyBomb(GamePanel.player.x+GamePanel.camera.x,GamePanel.player.y,35, (xx-GamePanel.player.x)/20, (yy-GamePanel.player.y)/10, sprite);
|
2022-06-07 18:12:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void draw(Graphics g){
|
2022-06-07 18:19:54 +01:00
|
|
|
g.drawImage(sprite,x-GamePanel.camera.x,y, length, length, null);
|
2022-06-07 18:12:48 +01:00
|
|
|
}
|
|
|
|
}
|