Working on fireball
parent
7a63db1349
commit
8430e3ef7e
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 359 B |
|
@ -3,6 +3,9 @@ import java.io.IOException;
|
|||
|
||||
public class FireBall extends GenericSprite{
|
||||
public String spritePath;
|
||||
private int realX;
|
||||
|
||||
public boolean dead;
|
||||
public FireBall(int x, int y, int height, int width, int xv, int yv, String dir) {
|
||||
super(x, y, height, width);
|
||||
xVelocity = xv;
|
||||
|
@ -10,13 +13,23 @@ public class FireBall extends GenericSprite{
|
|||
if(dir.equals("left")){
|
||||
spritePath = "img/misc/flame/flameLeft.png";
|
||||
}
|
||||
realX = 0;
|
||||
dead = false;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
realX = x-GameFrame.game.camera.x;
|
||||
}
|
||||
public void move(){
|
||||
// x += xVelocity;
|
||||
// y += yVelocity;
|
||||
update();
|
||||
if(canUpdate(xVelocity,yVelocity)) {
|
||||
x += xVelocity;
|
||||
y += yVelocity;
|
||||
} else {
|
||||
dead = true;
|
||||
}
|
||||
}
|
||||
public void draw(Graphics g) throws IOException {
|
||||
//g.drawImage(GamePanel.getImage(spritePath),x-GameFrame.game.camera.x,y,null);
|
||||
g.drawImage(GamePanel.getImage(spritePath),x-GameFrame.game.camera.x,y,null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
//dimensions of window
|
||||
public static final int GAME_WIDTH = 1225;
|
||||
public static final int GAME_HEIGHT = 630;
|
||||
|
||||
public static final int fireballSpeed = 5;
|
||||
public int bombCount;
|
||||
|
||||
public transient JPanel gameFrame;
|
||||
|
@ -254,7 +256,14 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
}
|
||||
}
|
||||
for(int i=0; i<fireballs.size(); i++){
|
||||
fireballs.get(i).draw(g);
|
||||
if(fireballs.get(i)!=null) {
|
||||
fireballs.get(i).draw(g);
|
||||
}
|
||||
if(fireballs.get(i).dead){
|
||||
fireballs.remove(i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for(int i=0; i<particles.size(); i++){
|
||||
|
@ -267,7 +276,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
}
|
||||
}
|
||||
}
|
||||
if(player.leftMouseDown){
|
||||
if(player.leftMouseDown&&LevelManager.bombs>0&&!player.holdingSteel){
|
||||
|
||||
bombDir = new BombDirectionShow(this.player.x + this.camera.x + WIDTH/2, this.player.y+HEIGHT/2,
|
||||
(player.mouseX - this.player.x) / 20, (player.mouseY - this.player.y) / 10);
|
||||
|
@ -395,8 +404,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
now = System.nanoTime();
|
||||
delta = delta + (now-lastTime)/ns;
|
||||
lastTime = now;
|
||||
// if(fireballCounter<0){fireballCounter = 20;}
|
||||
// fireballCounter--;
|
||||
|
||||
//only move objects around and update screen if enough time has passed
|
||||
if(delta >= 1){
|
||||
if ((!isPaused && !isDialogue) && MenuPanel.gameStart) {
|
||||
|
@ -408,7 +416,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
}
|
||||
checkCollision();
|
||||
updateEnemy();
|
||||
//wwwwwwww
|
||||
if(fireballCounter<0){fireballCounter = 100;}
|
||||
fireballCounter--;
|
||||
if(fireballCounter == 0){
|
||||
updateShootingBlock();
|
||||
}
|
||||
try {
|
||||
updateParticle();
|
||||
} catch (IOException e) {
|
||||
|
@ -455,7 +467,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
public void updateShootingBlock(){
|
||||
for(Tile i: shootingTiles){
|
||||
if(i.shootingDir.equals("left")){
|
||||
//fireballs.add(new FireBall(i.x,i.y,80,41,-1,0,"left"));
|
||||
fireballs.add(new FireBall(i.x-20,i.y+Tile.length/2,8,16,-fireballSpeed,0,"left"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ Implements Runnable interface to use "threading" - let the game do two things at
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
|
@ -180,6 +181,16 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
|
|||
}
|
||||
}
|
||||
|
||||
public static void deleteFiles(File dirPath) {
|
||||
File filesList[] = dirPath.listFiles();
|
||||
for(File file : filesList) {
|
||||
if(file.isFile()) {
|
||||
file.delete();
|
||||
} else {
|
||||
deleteFiles(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
//if a key is released, we'll send it over to the Player class for processing
|
||||
public void keyReleased(KeyEvent e){
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.util.Arrays;
|
|||
import java.util.LinkedList;
|
||||
|
||||
public class Player extends GenericSprite {
|
||||
public final int SPEED = 5;
|
||||
public static final int PLAYER_WIDTH = 52;
|
||||
public static final int PLAYER_HEIGHT = 94;
|
||||
|
||||
|
@ -50,6 +49,11 @@ public class Player extends GenericSprite {
|
|||
leftMouseDown = false;
|
||||
holdingSteel = false;
|
||||
canPlaceSteel = false;
|
||||
rightPressed = false;
|
||||
leftPressed = false;
|
||||
upPressed= false;
|
||||
downPressed = false;
|
||||
isGrounded = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -248,7 +252,7 @@ public class Player extends GenericSprite {
|
|||
xVelocity -= 1;
|
||||
}
|
||||
}
|
||||
if(upPressed&isGrounded){
|
||||
if(upPressed&&isGrounded&&!holdingSteel){
|
||||
y-=1;
|
||||
isGrounded = false;
|
||||
if(canUpdate(0,-8)) {
|
||||
|
@ -326,49 +330,53 @@ public class Player extends GenericSprite {
|
|||
|
||||
//TODO
|
||||
public boolean canReach(int x, int y){
|
||||
int pX = (int)(((double)GameFrame.game.camera.x + GamePanel.GAME_WIDTH) / Tile.length);
|
||||
int pY = (int)(((double)this.y+HEIGHT/2)/Tile.length);
|
||||
//System.out.println(pX+" "+pY);
|
||||
if(pY<0){
|
||||
return false;
|
||||
}
|
||||
//BFS
|
||||
int[][]check = {{0,1},{1,0},{-1,0},{0,-1}};
|
||||
int[][]dis = new int[1000][18];
|
||||
for(int[]a: dis){
|
||||
Arrays.fill(a, Integer.MAX_VALUE);
|
||||
}
|
||||
boolean[][]vis = new boolean[1000][18];
|
||||
LinkedList<Integer> xx = new LinkedList<>();
|
||||
LinkedList<Integer> yy = new LinkedList<>();
|
||||
xx.add(pX);
|
||||
yy.add(pY);
|
||||
dis[pX][pY] = 0;
|
||||
vis[pX][pY] = true;
|
||||
while(!xx.isEmpty()){
|
||||
int tempX = xx.poll();
|
||||
int tempY = yy.poll();
|
||||
for(int[]a: check){
|
||||
try{
|
||||
int newX = tempX + a[0];
|
||||
int newY = tempY + a[1];
|
||||
if(dis[tempX][tempY]+1<(Math.min(6,dis[newX][newY]))) {
|
||||
dis[newX][newY] = dis[tempX][tempY]+1;
|
||||
if(GameFrame.game.map[newX][newY]==null||GameFrame.game.map[newX][newY].replaceAble) {
|
||||
xx.add(newX);
|
||||
yy.add(newY);
|
||||
try {
|
||||
int pX = (int) (((double) GameFrame.game.camera.x + GamePanel.GAME_WIDTH) / Tile.length);
|
||||
int pY = (int) (((double) this.y + HEIGHT / 2) / Tile.length);
|
||||
//System.out.println(pX+" "+pY);
|
||||
if (pY < 0) {
|
||||
return false;
|
||||
}
|
||||
//BFS
|
||||
int[][] check = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
|
||||
int[][] dis = new int[1000][18];
|
||||
for (int[] a : dis) {
|
||||
Arrays.fill(a, Integer.MAX_VALUE);
|
||||
}
|
||||
boolean[][] vis = new boolean[1000][18];
|
||||
LinkedList<Integer> xx = new LinkedList<>();
|
||||
LinkedList<Integer> yy = new LinkedList<>();
|
||||
xx.add(pX);
|
||||
yy.add(pY);
|
||||
dis[pX][pY] = 0;
|
||||
vis[pX][pY] = true;
|
||||
while (!xx.isEmpty()) {
|
||||
int tempX = xx.poll();
|
||||
int tempY = yy.poll();
|
||||
for (int[] a : check) {
|
||||
try {
|
||||
int newX = tempX + a[0];
|
||||
int newY = tempY + a[1];
|
||||
if (dis[tempX][tempY] + 1 < (Math.min(6, dis[newX][newY]))) {
|
||||
dis[newX][newY] = dis[tempX][tempY] + 1;
|
||||
if (GameFrame.game.map[newX][newY] == null || GameFrame.game.map[newX][newY].replaceAble) {
|
||||
xx.add(newX);
|
||||
yy.add(newY);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(dis[x][y]<=6){
|
||||
return true;
|
||||
}
|
||||
if (dis[x][y] <= 6) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}catch(Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
|
||||
|
@ -386,7 +394,7 @@ public class Player extends GenericSprite {
|
|||
mouseY = e.getY();
|
||||
if(e.getButton()==MouseEvent.BUTTON1) {
|
||||
leftMouseDown = false;
|
||||
if (GameFrame.game.bombs.size() < 3 && LevelManager.bombs>0) {
|
||||
if (GameFrame.game.bombs.size() < 3 && LevelManager.bombs>0 && !holdingSteel) {
|
||||
LevelManager.bombs--;
|
||||
GameFrame.game.bombs.add(new StickyBomb(GameFrame.game.player.x + GameFrame.game.camera.x + WIDTH/2, GameFrame.game.player.y+HEIGHT/2,
|
||||
(mouseX - GameFrame.game.player.x) / 20, (mouseY - GameFrame.game.player.y) / 10, GameFrame.game.bomb, GameFrame.game.explosionArray));
|
||||
|
|
|
@ -24,6 +24,8 @@ public class Tile implements Serializable {
|
|||
public Tile previousBlock;
|
||||
|
||||
public String shootingDir;
|
||||
|
||||
|
||||
public Tile(int x, int y){
|
||||
isFinish = false;
|
||||
collision = true;
|
||||
|
|
Loading…
Reference in New Issue