Make stickybomb have sprites
parent
5e2edc9e99
commit
c63246cdb9
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -49,6 +49,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||||
public BufferedImage backgroundImage = getImage("img/backgrounds/pointyMountains.png");
|
public BufferedImage backgroundImage = getImage("img/backgrounds/pointyMountains.png");
|
||||||
public BufferedImage box = getImage("img/tiles/boxes/box.png");
|
public BufferedImage box = getImage("img/tiles/boxes/box.png");
|
||||||
public BufferedImage boxCoin = getImage("img/tiles/boxes/boxCoin.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 {
|
public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
||||||
this.gameFrame = gameFrame;
|
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
|
//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(){
|
public void run(){
|
||||||
b = new StickyBomb(600, 100, 20, 1,-5);
|
b = new StickyBomb(600, 100, 20, 1,-5, bomb);
|
||||||
LevelManager.setLevel(1);
|
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.
|
//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.
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
public class StickyBomb extends GenericSprite{
|
public class StickyBomb extends GenericSprite{
|
||||||
public int length;
|
public int length;
|
||||||
|
|
||||||
public int xVelocity;
|
public int xVelocity;
|
||||||
|
|
||||||
public int yVelocity;
|
public int yVelocity;
|
||||||
|
|
||||||
public boolean isMove;
|
public boolean isMove;
|
||||||
|
|
||||||
public int realX;
|
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);
|
super(x,y,length,length);
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.xVelocity = xVelocity;
|
this.xVelocity = xVelocity;
|
||||||
this.yVelocity = yVelocity;
|
this.yVelocity = yVelocity;
|
||||||
|
this.sprite = sprite;
|
||||||
isMove = true;
|
isMove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,11 +74,10 @@ public class StickyBomb extends GenericSprite{
|
||||||
public void mousePressed(MouseEvent e){
|
public void mousePressed(MouseEvent e){
|
||||||
int xx = e.getX();
|
int xx = e.getX();
|
||||||
int yy = e.getY();
|
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){
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue