Make stickybomb have sprites

master
John 2022-06-07 13:19:54 -04:00
parent 5e2edc9e99
commit c63246cdb9
3 changed files with 9 additions and 9 deletions

BIN
img/misc/bomb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -49,6 +49,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
public BufferedImage backgroundImage = getImage("img/backgrounds/pointyMountains.png");
public BufferedImage box = getImage("img/tiles/boxes/box.png");
public BufferedImage boxCoin = getImage("img/tiles/boxes/boxCoin.png");
public BufferedImage bomb = getImage("img/misc/bomb.png");
public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
this.gameFrame = gameFrame;
@ -181,7 +183,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
//run() method is what makes the game continue running without end. It calls other methods to move objects, check for collision, and update the screen
public void run(){
b = new StickyBomb(600, 100, 20, 1,-5);
b = new StickyBomb(600, 100, 20, 1,-5, bomb);
LevelManager.setLevel(1);
//the CPU runs our game code too quickly - we need to slow it down! The following lines of code "force" the computer to get stuck in a loop for short intervals between calling other methods to update the screen.

View File

@ -1,23 +1,22 @@
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public class StickyBomb extends GenericSprite{
public int length;
public int xVelocity;
public int yVelocity;
public boolean isMove;
public int realX;
BufferedImage sprite;
public StickyBomb(int x, int y, int length, int xVelocity, int yVelocity){
public StickyBomb(int x, int y, int length, int xVelocity, int yVelocity, BufferedImage sprite){
super(x,y,length,length);
this.length = length;
this.xVelocity = xVelocity;
this.yVelocity = yVelocity;
this.sprite = sprite;
isMove = true;
}
@ -75,11 +74,10 @@ public class StickyBomb extends GenericSprite{
public void mousePressed(MouseEvent e){
int xx = e.getX();
int yy = e.getY();
GamePanel.b = new StickyBomb(GamePanel.player.x+GamePanel.camera.x,GamePanel.player.y,35, (xx-GamePanel.player.x-GamePanel.camera.x)/20, (yy-GamePanel.player.y)/10);
GamePanel.b = new StickyBomb(GamePanel.player.x+GamePanel.camera.x,GamePanel.player.y,35, (xx-GamePanel.player.x-GamePanel.camera.x)/20, (yy-GamePanel.player.y)/10, sprite);
}
public void draw(Graphics g){
g.drawRect(x-GamePanel.camera.x,y,length,length);
g.drawImage(sprite,x-GamePanel.camera.x,y, length, length, null);
}
}