diff --git a/src/main/java/al/tonikolaba/audio/JukeBox.java b/src/main/java/al/tonikolaba/audio/JukeBox.java index 7d6bd01..a7ea4a3 100644 --- a/src/main/java/al/tonikolaba/audio/JukeBox.java +++ b/src/main/java/al/tonikolaba/audio/JukeBox.java @@ -1,6 +1,7 @@ package al.tonikolaba.audio; import java.util.HashMap; +import java.util.Objects; import java.util.logging.Level; import javax.sound.sampled.AudioFormat; @@ -32,13 +33,13 @@ public static void init() { public static void load(String s, String n) { // if (clips.get(s) != null) // return; - Clip clip; + final Clip clip; try { - AudioInputStream ais = AudioSystem.getAudioInputStream(JukeBox.class.getResourceAsStream(s)); - AudioFormat baseFormat = ais.getFormat(); - AudioFormat decodeFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, + final AudioInputStream ais = AudioSystem.getAudioInputStream(Objects.requireNonNull(JukeBox.class.getResourceAsStream(s))); + final AudioFormat baseFormat = ais.getFormat(); + final AudioFormat decodeFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false); - AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais); + final AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais); clip = AudioSystem.getClip(); clip.open(dais); clips.put(n, clip); diff --git a/src/main/java/al/tonikolaba/entity/Player.java b/src/main/java/al/tonikolaba/entity/Player.java index 9d43e75..ee6ca93 100644 --- a/src/main/java/al/tonikolaba/entity/Player.java +++ b/src/main/java/al/tonikolaba/entity/Player.java @@ -10,6 +10,7 @@ import javax.imageio.ImageIO; import al.tonikolaba.audio.JukeBox; +import al.tonikolaba.entity.enemies.Enemy; import al.tonikolaba.handlers.LoggingHelper; import al.tonikolaba.tilemap.TileMap; @@ -105,8 +106,8 @@ public Player(TileMap tm) { facingRight = true; - lives = 3; - health = maxHealth = 5; + lives = PlayerSave.getLives(); + health = maxHealth = PlayerSave.getHeath(); // load sprites try { diff --git a/src/main/java/al/tonikolaba/entity/PlayerSave.java b/src/main/java/al/tonikolaba/entity/PlayerSave.java index af1c092..d1db3e9 100644 --- a/src/main/java/al/tonikolaba/entity/PlayerSave.java +++ b/src/main/java/al/tonikolaba/entity/PlayerSave.java @@ -7,42 +7,45 @@ public class PlayerSave { - private static int lives = 3; - private static int health = 5; - private static long time = 0; + private static int lives; + private static int heath; + private static long time; public PlayerSave() { // throw new IllegalStateException("Utility Class"); - } - - public static void init() { lives = 3; - health = 5; + heath = 20; time = 0; } +// public static void init() { +// LIVES = 3; +// HEATH = 20; +// TIME = 0; +// } + public static int getLives() { return lives; } - public static void setLives(int i) { - lives = i; + public static void setLives(int lives) { + PlayerSave.lives = lives; } - public static int getHealth() { - return health; + public static int getHeath() { + return heath; } - public static void setHealth(int i) { - health = i; + public static void setHeath(int heath) { + PlayerSave.heath = heath; } public static long getTime() { return time; } - public static void setTime(long t) { - time = t; + public static void setTime(long time) { + PlayerSave.time = time; } } diff --git a/src/main/java/al/tonikolaba/entity/Teleport.java b/src/main/java/al/tonikolaba/entity/Teleport.java index e3930ec..bb39f74 100644 --- a/src/main/java/al/tonikolaba/entity/Teleport.java +++ b/src/main/java/al/tonikolaba/entity/Teleport.java @@ -5,6 +5,7 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; +import java.util.Objects; import java.util.logging.Level; /** @@ -22,7 +23,7 @@ public Teleport(TileMap tm) { cwidth = 20; cheight = 40; try { - BufferedImage spritesheet = ImageIO.read(getClass().getResourceAsStream("/Sprites/Player/Teleport.gif")); + BufferedImage spritesheet = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/Sprites/Player/Teleport.gif"))); sprites = new BufferedImage[9]; for (int i = 0; i < sprites.length; i++) { sprites[i] = spritesheet.getSubimage(i * width, 0, width, height); diff --git a/src/main/java/al/tonikolaba/entity/Enemy.java b/src/main/java/al/tonikolaba/entity/enemies/Enemy.java similarity index 93% rename from src/main/java/al/tonikolaba/entity/Enemy.java rename to src/main/java/al/tonikolaba/entity/enemies/Enemy.java index 8ec134c..9b0cf21 100644 --- a/src/main/java/al/tonikolaba/entity/Enemy.java +++ b/src/main/java/al/tonikolaba/entity/enemies/Enemy.java @@ -1,6 +1,7 @@ -package al.tonikolaba.entity; +package al.tonikolaba.entity.enemies; import al.tonikolaba.audio.JukeBox; +import al.tonikolaba.entity.MapObject; import al.tonikolaba.tilemap.TileMap; /** diff --git a/src/main/java/al/tonikolaba/entity/enemies/Flyer.java b/src/main/java/al/tonikolaba/entity/enemies/Flyer.java index 621b7ca..0536918 100644 --- a/src/main/java/al/tonikolaba/entity/enemies/Flyer.java +++ b/src/main/java/al/tonikolaba/entity/enemies/Flyer.java @@ -1,6 +1,5 @@ package al.tonikolaba.entity.enemies; -import al.tonikolaba.entity.Enemy; import al.tonikolaba.tilemap.TileMap; /** diff --git a/src/main/java/al/tonikolaba/entity/enemies/RedEnergy.java b/src/main/java/al/tonikolaba/entity/enemies/RedEnergy.java index 70e6e14..f845d73 100644 --- a/src/main/java/al/tonikolaba/entity/enemies/RedEnergy.java +++ b/src/main/java/al/tonikolaba/entity/enemies/RedEnergy.java @@ -1,6 +1,5 @@ package al.tonikolaba.entity.enemies; -import al.tonikolaba.entity.Enemy; import al.tonikolaba.handlers.Content; import al.tonikolaba.tilemap.TileMap; diff --git a/src/main/java/al/tonikolaba/entity/Spirit.java b/src/main/java/al/tonikolaba/entity/enemies/Spirit.java similarity index 97% rename from src/main/java/al/tonikolaba/entity/Spirit.java rename to src/main/java/al/tonikolaba/entity/enemies/Spirit.java index fbaed6d..e70e7a8 100644 --- a/src/main/java/al/tonikolaba/entity/Spirit.java +++ b/src/main/java/al/tonikolaba/entity/enemies/Spirit.java @@ -1,13 +1,13 @@ -package al.tonikolaba.entity; +package al.tonikolaba.entity.enemies; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.util.ArrayList; +import al.tonikolaba.entity.Explosion; +import al.tonikolaba.entity.Player; +import al.tonikolaba.tilemap.TileMap; import javax.imageio.ImageIO; - -import al.tonikolaba.entity.enemies.RedEnergy; -import al.tonikolaba.tilemap.TileMap; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.ArrayList; /** * @author N. Kolaba diff --git a/src/main/java/al/tonikolaba/entity/enemies/Ufo.java b/src/main/java/al/tonikolaba/entity/enemies/Ufo.java index 3e1e8de..1ce9243 100644 --- a/src/main/java/al/tonikolaba/entity/enemies/Ufo.java +++ b/src/main/java/al/tonikolaba/entity/enemies/Ufo.java @@ -1,6 +1,5 @@ package al.tonikolaba.entity.enemies; -import al.tonikolaba.entity.Enemy; import al.tonikolaba.entity.Player; import al.tonikolaba.handlers.Content; import al.tonikolaba.tilemap.TileMap; diff --git a/src/main/java/al/tonikolaba/entity/enemies/Zogu.java b/src/main/java/al/tonikolaba/entity/enemies/Zogu.java index 65b26b9..f58c371 100644 --- a/src/main/java/al/tonikolaba/entity/enemies/Zogu.java +++ b/src/main/java/al/tonikolaba/entity/enemies/Zogu.java @@ -1,6 +1,5 @@ package al.tonikolaba.entity.enemies; -import al.tonikolaba.entity.Enemy; import al.tonikolaba.handlers.Content; import al.tonikolaba.tilemap.TileMap; diff --git a/src/main/java/al/tonikolaba/gamestate/BasicState.java b/src/main/java/al/tonikolaba/gamestate/BasicState.java index 979fc34..e717e48 100644 --- a/src/main/java/al/tonikolaba/gamestate/BasicState.java +++ b/src/main/java/al/tonikolaba/gamestate/BasicState.java @@ -7,6 +7,7 @@ import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; +import java.util.Objects; import java.util.logging.Level; import javax.imageio.ImageIO; @@ -40,11 +41,11 @@ public BasicState(GameStateManager gsm) { this.gsm = gsm; try { - bg = ImageIO.read(getClass().getResourceAsStream("/Backgrounds/sfondi1.gif")).getSubimage(0, 0, + bg = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/Backgrounds/sfondi1.gif"))).getSubimage(0, 0, GamePanel.WIDTH, GamePanel.HEIGHT); // load floating head - head = ImageIO.read(getClass().getResourceAsStream("/HUD/Hud.gif")).getSubimage(0, 12, 12, 11); + head = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/HUD/Hud.gif"))).getSubimage(0, 12, 12, 11); // titles and fonts fontMenu = new Font("Arial", Font.BOLD, 18); diff --git a/src/main/java/al/tonikolaba/gamestate/GameState.java b/src/main/java/al/tonikolaba/gamestate/GameState.java index 29030f4..7c94173 100644 --- a/src/main/java/al/tonikolaba/gamestate/GameState.java +++ b/src/main/java/al/tonikolaba/gamestate/GameState.java @@ -10,8 +10,8 @@ import javax.imageio.ImageIO; import al.tonikolaba.audio.JukeBox; -import al.tonikolaba.entity.Enemy; -import al.tonikolaba.entity.Enemy.EnemyType; +import al.tonikolaba.entity.enemies.Enemy; +import al.tonikolaba.entity.enemies.Enemy.EnemyType; import al.tonikolaba.entity.EnemyProjectile; import al.tonikolaba.entity.EnergyParticle; import al.tonikolaba.entity.Explosion; @@ -19,7 +19,7 @@ import al.tonikolaba.entity.Player; import al.tonikolaba.entity.PlayerSave; import al.tonikolaba.entity.Portal; -import al.tonikolaba.entity.Spirit; +import al.tonikolaba.entity.enemies.Spirit; import al.tonikolaba.entity.Teleport; import al.tonikolaba.entity.Title; import al.tonikolaba.entity.enemies.RedEnergy; @@ -156,7 +156,7 @@ protected void setupGameObjects(int playerX, int playerY, int goalX, int goalY, playerYStart = playerY; player = new Player(tileMap); player.setPosition(playerX, playerY); - player.setHealth(PlayerSave.getHealth()); + player.setHealth(PlayerSave.getHeath()); player.setLives(PlayerSave.getLives()); player.setTime(PlayerSave.getTime()); @@ -453,7 +453,7 @@ protected void eventFinishFunc() { JukeBox.stop(TELEPORT_MUSIC_NAME); } if (eventCount == 180) { - PlayerSave.setHealth(player.getHealth()); + PlayerSave.setHeath(player.getHealth()); PlayerSave.setLives(player.getLives()); PlayerSave.setTime(player.getTime()); gsm.setState(nextLevelState); diff --git a/src/main/java/al/tonikolaba/gamestate/GameStateManager.java b/src/main/java/al/tonikolaba/gamestate/GameStateManager.java index bceb24b..789ef5d 100644 --- a/src/main/java/al/tonikolaba/gamestate/GameStateManager.java +++ b/src/main/java/al/tonikolaba/gamestate/GameStateManager.java @@ -16,7 +16,7 @@ public class GameStateManager { public static final int LEVEL2STATE = 3; public static final int LEVEL3STATE = 4; public static final int LEVEL4STATE = 5; - // public static final int LEVELTEST = 6; +// public static final int LEVELTEST = 6; public static final int HOWTOPLAY = 7; public static final int ACIDSTATE = 15; public BasicState[] gameStates; @@ -39,24 +39,35 @@ public GameStateManager() { } public void loadState(int state) { - if (state == MENUSTATE) - gameStates[state] = new MenuState(this); - else if (state == OPTIONSSTATE) - gameStates[state] = new OptionsState(this); - else if (state == HOWTOPLAY) - gameStates[state] = new HowtoPlay(this); - else if (state == LEVEL1STATE) - gameStates[state] = new Level1State(this); - else if (state == LEVEL2STATE) - gameStates[state] = new Level2State(this); - else if (state == LEVEL3STATE) - gameStates[state] = new Level3State(this); - else if (state == LEVEL4STATE) - gameStates[state] = new Level4State(this); - // else if (state == LEVELTEST) - // gameStates[state] = new LevelTest(this); - else if (state == ACIDSTATE) - gameStates[state] = new AcidState(this); + switch (state) { + case (MENUSTATE): + gameStates[state] = new MenuState(this); + break; + case (OPTIONSSTATE): + gameStates[state] = new OptionsState(this); + break; + case(HOWTOPLAY): + gameStates[state] = new HowtoPlay(this); + break; + case (LEVEL1STATE): + gameStates[state] = new Level1State(this); + break; + case (LEVEL2STATE): + gameStates[state] = new Level2State(this); + break; + case (LEVEL3STATE): + gameStates[state] = new Level3State(this); + break; + case(LEVEL4STATE): + gameStates[state] = new Level4State(this); + break; +// case(LEVELTEST): +// gameStates[state] = new LevelTest(this); +// break; + case(ACIDSTATE): + gameStates[state] = new AcidState(this); + break; + } } private void unloadState(int state) { diff --git a/src/main/java/al/tonikolaba/gamestate/HowtoPlay.java b/src/main/java/al/tonikolaba/gamestate/HowtoPlay.java index 90c8b0a..87492dc 100644 --- a/src/main/java/al/tonikolaba/gamestate/HowtoPlay.java +++ b/src/main/java/al/tonikolaba/gamestate/HowtoPlay.java @@ -27,11 +27,11 @@ public void draw(Graphics2D h) { h.fillRect(200, 160, 280, 200); // Fills a square h.drawRoundRect(190, 150, 300, 220, 50, 50); h.setColor(Color.RED); - h.drawString("< > - MOVE LEFT OR RIGHT", 230, 200); - h.drawString("W+R - JUMP AND HIT ", 230, 220); - h.drawString("R - SINGLE HIT ", 230, 240); + h.drawString("<- -> - MOVE LEFT OR RIGHT", 230, 200); + h.drawString("LEFT SHIFT - RUN", 230, 220); + h.drawString("D - SINGLE HIT ", 230, 240); h.drawString("F - BIG HIT ", 230, 260); - h.drawString("W - JUMP UP ", 230, 280); + h.drawString("SPACE - JUMP UP ", 230, 280); h.drawString("ESC - PAUSE ", 230, 300); h.setFont(font); h.drawString(" * Press any key to go Back ", 240, 330); diff --git a/src/main/java/al/tonikolaba/gamestate/Level1State.java b/src/main/java/al/tonikolaba/gamestate/Level1State.java index 7440157..d3416d4 100644 --- a/src/main/java/al/tonikolaba/gamestate/Level1State.java +++ b/src/main/java/al/tonikolaba/gamestate/Level1State.java @@ -1,6 +1,6 @@ package al.tonikolaba.gamestate; -import al.tonikolaba.entity.Enemy.EnemyType; +import al.tonikolaba.entity.enemies.Enemy.EnemyType; import al.tonikolaba.tilemap.Background; /** diff --git a/src/main/java/al/tonikolaba/gamestate/Level2State.java b/src/main/java/al/tonikolaba/gamestate/Level2State.java index 240d28c..3111f0d 100644 --- a/src/main/java/al/tonikolaba/gamestate/Level2State.java +++ b/src/main/java/al/tonikolaba/gamestate/Level2State.java @@ -1,6 +1,6 @@ package al.tonikolaba.gamestate; -import al.tonikolaba.entity.Enemy.EnemyType; +import al.tonikolaba.entity.enemies.Enemy.EnemyType; import al.tonikolaba.tilemap.Background; /** diff --git a/src/main/java/al/tonikolaba/gamestate/Level3State.java b/src/main/java/al/tonikolaba/gamestate/Level3State.java index 8632353..e40ce3b 100644 --- a/src/main/java/al/tonikolaba/gamestate/Level3State.java +++ b/src/main/java/al/tonikolaba/gamestate/Level3State.java @@ -4,7 +4,7 @@ package al.tonikolaba.gamestate; -import al.tonikolaba.entity.Enemy.EnemyType; +import al.tonikolaba.entity.enemies.Enemy.EnemyType; import al.tonikolaba.entity.Player; import al.tonikolaba.tilemap.Background; diff --git a/src/main/java/al/tonikolaba/gamestate/Level4State.java b/src/main/java/al/tonikolaba/gamestate/Level4State.java index 8627907..eabefb6 100644 --- a/src/main/java/al/tonikolaba/gamestate/Level4State.java +++ b/src/main/java/al/tonikolaba/gamestate/Level4State.java @@ -5,14 +5,14 @@ import java.util.ArrayList; import al.tonikolaba.audio.JukeBox; -import al.tonikolaba.entity.Enemy; +import al.tonikolaba.entity.enemies.Enemy; import al.tonikolaba.entity.EnergyParticle; import al.tonikolaba.entity.Explosion; import al.tonikolaba.entity.HUD; import al.tonikolaba.entity.Player; import al.tonikolaba.entity.PlayerSave; import al.tonikolaba.entity.Portal; -import al.tonikolaba.entity.Spirit; +import al.tonikolaba.entity.enemies.Spirit; import al.tonikolaba.entity.Teleport; import al.tonikolaba.entity.batbat.Piece; import al.tonikolaba.entity.enemies.RedEnergy; @@ -68,16 +68,16 @@ public void init(int nextLevel) { // player player = new Player(tileMap); player.setPosition(50, 190); - player.setHealth(PlayerSave.getHealth()); + player.setHealth(PlayerSave.getHeath()); player.setLives(PlayerSave.getLives()); player.setTime(PlayerSave.getTime()); // player - player = new Player(tileMap); - player.setPosition(50, 190); - player.setHealth(PlayerSave.getHealth()); - player.setLives(PlayerSave.getLives()); - player.setTime(PlayerSave.getTime()); +// player = new Player(tileMap); +// player.setPosition(50, 190); +// player.setHealth(PlayerSave.getHealth()); +// player.setLives(PlayerSave.getLives()); +// player.setTime(PlayerSave.getTime()); // explosions explosions = new ArrayList(); @@ -341,7 +341,7 @@ private void eventFinish() { tb.get(0).height += 8; } if (eventCount == 60) { - PlayerSave.setHealth(player.getHealth()); + PlayerSave.setHeath(player.getHealth()); PlayerSave.setLives(player.getLives()); PlayerSave.setTime(player.getTime()); gsm.setState(GameStateManager.ACIDSTATE); diff --git a/src/main/java/al/tonikolaba/gamestate/LevelTest.java b/src/main/java/al/tonikolaba/gamestate/LevelTest.java index 9226b79..bfef55b 100644 --- a/src/main/java/al/tonikolaba/gamestate/LevelTest.java +++ b/src/main/java/al/tonikolaba/gamestate/LevelTest.java @@ -7,8 +7,8 @@ import al.tonikolaba.entity.EnergyParticle; import al.tonikolaba.entity.Player; -import al.tonikolaba.entity.Spirit; -import al.tonikolaba.entity.Enemy.EnemyType; +import al.tonikolaba.entity.enemies.Spirit; +import al.tonikolaba.entity.enemies.Enemy.EnemyType; import al.tonikolaba.entity.batbat.Piece; import al.tonikolaba.tilemap.Background; diff --git a/src/main/java/al/tonikolaba/gamestate/MenuState.java b/src/main/java/al/tonikolaba/gamestate/MenuState.java index 983cdcc..5f0a11f 100644 --- a/src/main/java/al/tonikolaba/gamestate/MenuState.java +++ b/src/main/java/al/tonikolaba/gamestate/MenuState.java @@ -41,7 +41,8 @@ protected void select() { switch (currentChoice) { case 0: JukeBox.play("menuselect"); - PlayerSave.init(); +// PlayerSave.init(); + new PlayerSave(); gsm.setState(GameStateManager.LEVEL1STATE); // start this level entrance break; case 1: diff --git a/src/main/java/al/tonikolaba/handlers/Content.java b/src/main/java/al/tonikolaba/handlers/Content.java index 7f89534..bea8299 100644 --- a/src/main/java/al/tonikolaba/handlers/Content.java +++ b/src/main/java/al/tonikolaba/handlers/Content.java @@ -2,6 +2,7 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; +import java.util.Objects; import java.util.logging.Level; /** @@ -25,16 +26,16 @@ private Content() { throw new IllegalStateException("Utility Class"); } - public static BufferedImage[][] load(String s, int w, int h) { - BufferedImage[][] ret; + public static BufferedImage[][] load(final String s, final int w, final int h) { try { - BufferedImage spritesheet = ImageIO.read(Content.class.getResourceAsStream(s)); - int width = spritesheet.getWidth() / w; - int height = spritesheet.getHeight() / h; - ret = new BufferedImage[height][width]; + final BufferedImage spritesHeat = ImageIO.read(Objects.requireNonNull(Content.class.getResourceAsStream(s))); + final int width = spritesHeat.getWidth() / w; + final int height = spritesHeat.getHeight() / h; + final BufferedImage[][] ret = new BufferedImage[height][width]; + for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { - ret[i][j] = spritesheet.getSubimage(j * w, i * h, w, h); + ret[i][j] = spritesHeat.getSubimage(j * w, i * h, w, h); } } return ret; diff --git a/src/main/java/al/tonikolaba/handlers/Keys.java b/src/main/java/al/tonikolaba/handlers/Keys.java index 58587f4..f15f8fd 100644 --- a/src/main/java/al/tonikolaba/handlers/Keys.java +++ b/src/main/java/al/tonikolaba/handlers/Keys.java @@ -26,27 +26,39 @@ public Keys() { // throw new IllegalStateException("Utility Class"); } - public static void keySet(int i, boolean b) { - if (i == KeyEvent.VK_UP) - getKeyState()[UP] = b; - else if (i == KeyEvent.VK_LEFT) - getKeyState()[LEFT] = b; - else if (i == KeyEvent.VK_DOWN) - getKeyState()[DOWN] = b; - else if (i == KeyEvent.VK_RIGHT) - getKeyState()[RIGHT] = b; - else if (i == KeyEvent.VK_W) - getKeyState()[BUTTON1] = b; - else if (i == KeyEvent.VK_E) - getKeyState()[BUTTON2] = b; - else if (i == KeyEvent.VK_R) - getKeyState()[BUTTON3] = b; - else if (i == KeyEvent.VK_F) - getKeyState()[BUTTON4] = b; - else if (i == KeyEvent.VK_ENTER) - getKeyState()[ENTER] = b; - else if (i == KeyEvent.VK_ESCAPE) - getKeyState()[ESCAPE] = b; + public static void keySet(int key, boolean b) { + switch (key) { + case (KeyEvent.VK_UP): + getKeyState()[UP] = b; + break; + case (KeyEvent.VK_LEFT): + getKeyState()[LEFT] = b; + break; + case (KeyEvent.VK_DOWN): + getKeyState()[DOWN] = b; + break; + case (KeyEvent.VK_RIGHT): + getKeyState()[RIGHT] = b; + break; + case (KeyEvent.VK_SPACE): + getKeyState()[BUTTON1] = b; + break; + case (KeyEvent.VK_SHIFT): + getKeyState()[BUTTON2] = b; + break; + case (KeyEvent.VK_D): + getKeyState()[BUTTON3] = b; + break; + case (KeyEvent.VK_F): + getKeyState()[BUTTON4] = b; + break; + case (KeyEvent.VK_ENTER): + getKeyState()[ENTER] = b; + break; + case (KeyEvent.VK_ESCAPE): + getKeyState()[ESCAPE] = b; + break; + } } public static void update() { diff --git a/src/main/java/al/tonikolaba/main/BatBatSpring.java b/src/main/java/al/tonikolaba/main/BatBatSpring.java index 4b800a7..800cc86 100644 --- a/src/main/java/al/tonikolaba/main/BatBatSpring.java +++ b/src/main/java/al/tonikolaba/main/BatBatSpring.java @@ -15,7 +15,7 @@ public class BatBatSpring { public static void main(String[] args) { - ConfigurableApplicationContext context = new SpringApplicationBuilder(BatBatSpring.class).headless(false) + final ConfigurableApplicationContext context = new SpringApplicationBuilder(BatBatSpring.class).headless(false) .run(args); EventQueue.invokeLater(() -> { diff --git a/src/main/java/al/tonikolaba/tilemap/Background.java b/src/main/java/al/tonikolaba/tilemap/Background.java index 617fba9..25682ff 100644 --- a/src/main/java/al/tonikolaba/tilemap/Background.java +++ b/src/main/java/al/tonikolaba/tilemap/Background.java @@ -6,6 +6,7 @@ import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; +import java.util.Objects; import java.util.logging.Level; /** @@ -38,7 +39,7 @@ public Background(String s, double d) { public Background(String s, double d1, double d2) { try { image = ImageIO.read( - getClass().getResourceAsStream(s) + Objects.requireNonNull(getClass().getResourceAsStream(s)) ); width = image.getWidth(); height = image.getHeight(); @@ -52,7 +53,7 @@ public Background(String s, double d1, double d2) { public Background(String s, double ms, int x, int y, int w, int h) { try { image = ImageIO.read( - getClass().getResourceAsStream(s) + Objects.requireNonNull(getClass().getResourceAsStream(s)) ); image = image.getSubimage(x, y, w, h); width = image.getWidth(); diff --git a/src/test/java/al/tonikolaba/entity/PlayerSaveTest.java b/src/test/java/al/tonikolaba/entity/PlayerSaveTest.java index 4304731..700c0da 100644 --- a/src/test/java/al/tonikolaba/entity/PlayerSaveTest.java +++ b/src/test/java/al/tonikolaba/entity/PlayerSaveTest.java @@ -44,8 +44,8 @@ public void init() { int expectLives = PlayerSave.getLives(); assertEquals(expectLives, 3); - PlayerSave.setHealth(5); - int expectHealth = PlayerSave.getHealth(); + PlayerSave.setHeath(5); + int expectHealth = PlayerSave.getHeath(); assertEquals(expectHealth, 5); PlayerSave.setTime(0); @@ -82,25 +82,25 @@ public void getHealth() { PlayerSave ps = new PlayerSave(); assertNotNull(ps); - PlayerSave.setHealth(5); + PlayerSave.setHeath(5); int expectHealth; - expectHealth = PlayerSave.getHealth(); + expectHealth = PlayerSave.getHeath(); assertEquals(expectHealth, 5); - PlayerSave.setHealth(10); - int expectHealth2 = PlayerSave.getHealth(); + PlayerSave.setHeath(10); + int expectHealth2 = PlayerSave.getHeath(); assertEquals(expectHealth2, 10); - PlayerSave.setHealth(15); - int expectHealth3 = PlayerSave.getHealth(); + PlayerSave.setHeath(15); + int expectHealth3 = PlayerSave.getHeath(); assertEquals(expectHealth3, 15); - PlayerSave.setHealth(0); - int expectHealth4 = PlayerSave.getHealth(); + PlayerSave.setHeath(0); + int expectHealth4 = PlayerSave.getHeath(); assertEquals(expectHealth4, 0); - PlayerSave.setHealth(3); - int expectHealth5 = PlayerSave.getHealth(); + PlayerSave.setHeath(3); + int expectHealth5 = PlayerSave.getHeath(); assertEquals(expectHealth5, 3); }