From 8430e3ef7e2fa7991d0ee0e1178ea75c6e2579ea Mon Sep 17 00:00:00 2001 From: Chara1236 Date: Sun, 19 Jun 2022 15:57:22 -0400 Subject: [PATCH 1/2] Working on fireball --- img/misc/flame/flameLeft.png | Bin 1226 -> 359 bytes src/FireBall.java | 19 ++++++-- src/GamePanel.java | 24 +++++++--- src/Main.java | 2 +- src/MenuPanel.java | 11 +++++ src/Player.java | 90 +++++++++++++++++++---------------- src/Tile.java | 2 + 7 files changed, 97 insertions(+), 51 deletions(-) diff --git a/img/misc/flame/flameLeft.png b/img/misc/flame/flameLeft.png index 661a64c99f478adf54d67427a4303b75059e7821..2e670d3d0dd2e05be392958e00bbec0fab9a99dc 100644 GIT binary patch literal 359 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~c!3-piujpS2q*&4&eH|GXHuiJ>Nn{1`8H!2^IV|i{bA~F!vaU zgdmVcAleO8^M4z|f1vuA4DJO!K-BuzWedqtf$yv z1s>)A(b)}+6D-gEsQDk=)|Rz=|AYm`Pv_kB$lm^CRhP;=iT+8;mgWWQIPmyHw1IuI zcf;R354D<}@o#fFlB=`X)_Lwi&dHzu>7MvFyQ)=hdWVJ8HKQKGBibQV{c?-a;OG>?f?J;CP_p=RA@uxn$K?2KoG`1 z+eu3iB^4kfxU>=y5)u;S3FsTpHy|8aA?T4C;l?pSrGGgR-XM<Skkp(#YPeS~Xv0c4ueDz?2;AV?AqP%P_DZ!>!KjSgPvT#r6Kp z9X4TKdWwb`E(8+^NYR!o`< zEJVmcqk&>nX!`;(*Rw2?{h27PiCq=T_@n8em=u*F^Z7?ib78sRNGg;MOV&FAj#~RH zv40z4^tz;Ii~Sa(sC6+4t0DA8YX{HO(8plfvb5|Ui-uVdyD2uS*G&qA{2@j$8TuN* zwNXTTsD>~zS!}EKVXljvwRnWy&Qir~F)kfTVw%8{nNz}RHH0Y^UW%gk%{v?9m&Y&h zmKcT91d7OggYQPXutY zo*^90Jl4KAP(-FvI$&ZuT0osiGNqc3#S~B@7E?fta>KShl1{9Hk`~uq z4XZGOp4V((tGBr7Zz7^%bTO45>VsGk;mq))m($aD$;b_Y-lm~=vR4!{JGeVonf5)9 zJum075o=*Dm&JID8dc68gd&lk5`P_3pfxR;4nnV!4P!5=b;K8tI3+wYO%&8{JPhqH z=sgQ~_b~{|`0!B3?Bb1@3Z*L`iG8t@V(4+aBOWJQK%amk%lj#ZrFtgDlXiLa2}oky z(4_<>!y;T|nvR5kApuG20QW2dl{AJkL)74<`HVd=0igntG&LE~)8xQVJ%26HdWjT} zs2;(J?9Op}ptV4q@2l*;PP%h-q<{g=D?AZTEa>Qsen@s&eeJe**=hCt#U+-2M0w+$ z{KDQmgrrv)2I>-yHXF{Fr=7J}VZ;`&7j|+P7PdWLbC!0vo@ViYPH9c%**MPEq(g94 nrV?-v?%L{gB)W?+Ily0nFcOK&Z`&-L00000NkvXXu0mjfsroV7 diff --git a/src/FireBall.java b/src/FireBall.java index 683557d..5a456e6 100644 --- a/src/FireBall.java +++ b/src/FireBall.java @@ -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); } } diff --git a/src/GamePanel.java b/src/GamePanel.java index be33eff..bb6a205 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -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; i0&&!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")); } } } diff --git a/src/Main.java b/src/Main.java index a87b5bc..84f982f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -8,6 +8,6 @@ class Main { public static void main(String[] args) { new GameFrame(); - + } } \ No newline at end of file diff --git a/src/MenuPanel.java b/src/MenuPanel.java index 73ba335..f53bb87 100644 --- a/src/MenuPanel.java +++ b/src/MenuPanel.java @@ -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){ diff --git a/src/Player.java b/src/Player.java index aabb64c..e109f73 100644 --- a/src/Player.java +++ b/src/Player.java @@ -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 xx = new LinkedList<>(); - LinkedList 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 xx = new LinkedList<>(); + LinkedList 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)); diff --git a/src/Tile.java b/src/Tile.java index bff8c06..60dca6d 100644 --- a/src/Tile.java +++ b/src/Tile.java @@ -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; From d071e51c5bead8c14e37f087e44d134bc540d38b Mon Sep 17 00:00:00 2001 From: Chara1236 Date: Sun, 19 Jun 2022 16:20:31 -0400 Subject: [PATCH 2/2] ignore --- saves/Level1.txt | 4 ++-- src/FireBall.java | 16 +++++++++++++++- src/GamePanel.java | 2 +- src/Player.java | 7 +------ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/saves/Level1.txt b/saves/Level1.txt index 77da5e2..da9ae01 100644 --- a/saves/Level1.txt +++ b/saves/Level1.txt @@ -12,7 +12,7 @@ sssssssssssssssssd sssssssssssssssssd zxc asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc ad sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv ad sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv ad -sssssssssssssssssdlllllad 2 hqwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv ad +sssssssssssssssssdlllllad 2 qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv ad sssssssssssssssssdlllllad bbb s qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv ad -sssssssssssssssssdllllladbb s ooqwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv + ad +sssssssssssssssssdllllladbb s ooqwwrssssllssssstwe ! b h !!! qwe vvvvvvvvvvvvvvvvvvvvv + ad ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3 \ No newline at end of file diff --git a/src/FireBall.java b/src/FireBall.java index 5a456e6..f40b0bd 100644 --- a/src/FireBall.java +++ b/src/FireBall.java @@ -6,7 +6,10 @@ public class FireBall extends GenericSprite{ private int realX; public boolean dead; - public FireBall(int x, int y, int height, int width, int xv, int yv, String dir) { + + public static final int height = 8; + public static final int width = 16; + public FireBall(int x, int y, int xv, int yv, String dir) { super(x, y, height, width); xVelocity = xv; yVelocity = yv; @@ -20,6 +23,13 @@ public class FireBall extends GenericSprite{ public void update(){ realX = x-GameFrame.game.camera.x; } + + public boolean collidePlayer(Player p){ + if(realX+width>p.x&&realXtile.realX&&x