diff --git a/src/GamePanel.java b/src/GamePanel.java index 947084b..a80b6a9 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -515,9 +515,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ public void updateParticle() throws IOException { if(particles.size()<10) { for (int i = 0; i < particleTiles.size(); i++) { - if (GlobalState.randInt(1, 20) == 1) { - particles.add(new Particle(particleTiles.get(i).x + GlobalState.randInt(0, Tile.length), particleTiles.get(i).y + GlobalState.randInt(0, Tile.length / 2), - GlobalState.randInt(-3, 3), GlobalState.randInt(-5, 2), GlobalState.randInt(5, 9), "img/particles/LavaParticle.png")); + if (UtilityFunction.randInt(1, 20) == 1) { + particles.add(new Particle(particleTiles.get(i).x + UtilityFunction.randInt(0, Tile.length), particleTiles.get(i).y + UtilityFunction.randInt(0, Tile.length / 2), + UtilityFunction.randInt(-3, 3), UtilityFunction.randInt(-5, 2), UtilityFunction.randInt(5, 9), "img/particles/LavaParticle.png")); } } } diff --git a/src/GlobalState.java b/src/GlobalState.java index 6134f76..e60f2be 100644 --- a/src/GlobalState.java +++ b/src/GlobalState.java @@ -2,7 +2,4 @@ import java.io.Serializable; public class GlobalState implements Serializable { 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/Player.java b/src/Player.java index dab9c4d..59729c1 100644 --- a/src/Player.java +++ b/src/Player.java @@ -7,8 +7,6 @@ import javax.sound.sampled.UnsupportedAudioFileException; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; -import java.awt.image.BufferedImage; -import java.awt.image.ImageObserver; import java.io.IOException; import java.util.Arrays; import java.util.LinkedList; @@ -412,9 +410,9 @@ public class Player extends GenericSprite { } } public void addParticle(int x) throws IOException { - if(GlobalState.randInt(1,3)==3) { - GameFrame.game.particles.add(new Particle(this.x + GameFrame.game.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")); + if(UtilityFunction.randInt(1,3)==3) { + GameFrame.game.particles.add(new Particle(this.x + GameFrame.game.camera.x + WIDTH / 2 + UtilityFunction.randInt(-PLAYER_WIDTH / 2, PLAYER_WIDTH / 2) + , (int) (y + HEIGHT * 0.95), UtilityFunction.randInt(-2, 2) + x, UtilityFunction.randInt(-4, 1), UtilityFunction.randInt(1, 7), "img/particles/GrassParticle.png")); } } public int draw(Graphics g, int frame) { diff --git a/src/UtilityFunction.java b/src/UtilityFunction.java index 764d65e..5bb6c46 100644 --- a/src/UtilityFunction.java +++ b/src/UtilityFunction.java @@ -29,4 +29,8 @@ public final class UtilityFunction { } return currentBox; } + + public static int randInt(int low, int high){ + return (int)(Math.random()*(high-low+1))+low; + } }