diff --git a/img/particles/GrassParticle.png b/img/particles/GrassParticle.png new file mode 100644 index 0000000..deb4654 Binary files /dev/null and b/img/particles/GrassParticle.png differ diff --git a/img/particles/LavaParticle.png b/img/particles/LavaParticle.png new file mode 100644 index 0000000..b14febd Binary files /dev/null and b/img/particles/LavaParticle.png differ diff --git a/src/GamePanel.java b/src/GamePanel.java index e1340f7..b5ed52f 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -42,6 +42,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ //public static ArrayListmap = new ArrayList(); public static Tile[][]map = new Tile[300][18]; + + public static ArrayListparticleTiles = new ArrayList(); public static ArrayListenemy = new ArrayList(); public static ArrayListparticles = new ArrayList(); @@ -142,10 +144,12 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ playerFrameCounter += player.draw(g, playerFrame); b.draw(g); for(int i=0; i= 1){ - move(); + try { + move(); + } catch (IOException e) { + throw new RuntimeException(e); + } checkCollision(); + try { + updateParticle(); + } catch (IOException e) { + throw new RuntimeException(e); + } repaint(); if (playerFrameCounter > 5) { // increment sprite image to be used and keeps it below 12 @@ -238,6 +251,12 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ } } + public void updateParticle() throws IOException { + for(Tile t: particleTiles){ + particles.add(new Particle(t.realX+Tile.length/2,t.y+Tile.length/2 ,GlobalState.randInt(-3,3),GlobalState.randInt(-3,3),GlobalState.randInt(1,5),"img/particles/LavaParticle.png")); + } + } + //if a key is pressed, we'll send it over to the Player class for processing public void keyPressed(KeyEvent e){ player.keyPressed(e); diff --git a/src/GenericSprite.java b/src/GenericSprite.java index 3eb57d7..9754617 100644 --- a/src/GenericSprite.java +++ b/src/GenericSprite.java @@ -6,6 +6,7 @@ In 2D GUI, basically everything is a rectangle even if it doesn't look like it! */ import java.awt.*; import java.awt.event.*; +import java.io.IOException; public class GenericSprite extends Rectangle{ @@ -22,6 +23,8 @@ public class GenericSprite extends Rectangle{ public boolean upPressed= false; public boolean downPressed = false; public boolean isGrounded = false; + + public boolean isPlayer = false; //constructor creates ball at given location with given dimensions // TODO: reverse order of height and width public GenericSprite(int x, int y, int height, int width){ @@ -51,7 +54,7 @@ public class GenericSprite extends Rectangle{ } - public void move(){ + public void move() throws IOException { } @@ -88,7 +91,7 @@ public class GenericSprite extends Rectangle{ for (int j = lowY; j < highY; j++) { if (GamePanel.map[i][j] != null) { if (collide(GamePanel.map[i][j], this.x + x, this.y + y)) { - if (GamePanel.map[i][j].isFinish) { + if (GamePanel.map[i][j].isFinish&&isPlayer) { LevelManager.nextLevel(); return true; } diff --git a/src/GlobalState.java b/src/GlobalState.java index a017071..ccb4148 100644 --- a/src/GlobalState.java +++ b/src/GlobalState.java @@ -1,3 +1,6 @@ public class GlobalState { public static final int second = 10; + public static int randInt(int low, int high){ + return (int)(Math.random()*(high-low+1))+low; + } } diff --git a/src/MapReader.java b/src/MapReader.java index f96a7db..3935400 100644 --- a/src/MapReader.java +++ b/src/MapReader.java @@ -28,6 +28,7 @@ public class MapReader { x = 0; y = 0; GamePanel.enemy.clear(); + GamePanel.particleTiles.clear(); for(int i=0; i-5) { xVelocity -= 1; } @@ -197,6 +201,13 @@ public class Player extends GenericSprite { GamePanel.camera.x = LevelManager.xSpawn; y = LevelManager.ySpawn; } + + public void addParticle(int x) throws IOException { + if(GlobalState.randInt(1,3)==3) { + GamePanel.particles.add(new Particle(this.x + GamePanel.camera.x + WIDTH / 2 + GlobalState.randInt(-PLAYER_WIDTH / 2, PLAYER_WIDTH / 2) + , (int) (y + HEIGHT * 0.95), GlobalState.randInt(-2, 2) + x, GlobalState.randInt(-4, 1), GlobalState.randInt(1, 7), "img/particles/GrassParticle.png")); + } + } public int draw(Graphics g, int frame) { frame %= spriteArray[0][0].length; if (!upPressed && !downPressed && !leftPressed && !rightPressed) {