Browse Source

animated clock, tries per level, no further respawn without tries, ai improvements, sound tests / bugfixes

Kajetan Johannes Hammerle 6 years ago
parent
commit
38b48dda35
37 changed files with 142 additions and 24 deletions
  1. BIN
      resources/gui/health_num/health_num_0.png
  2. BIN
      resources/gui/health_num/health_num_1.png
  3. BIN
      resources/gui/health_num/health_num_2.png
  4. BIN
      resources/gui/health_num/health_num_3.png
  5. BIN
      resources/gui/health_num/health_num_4.png
  6. BIN
      resources/gui/health_num/health_num_5.png
  7. BIN
      resources/gui/health_num/health_num_6.png
  8. BIN
      resources/gui/health_num/health_num_7.png
  9. BIN
      resources/gui/time_icon/time_f1.png
  10. BIN
      resources/gui/time_icon/time_f10.png
  11. BIN
      resources/gui/time_icon/time_f11.png
  12. BIN
      resources/gui/time_icon/time_f12.png
  13. BIN
      resources/gui/time_icon/time_f2.png
  14. BIN
      resources/gui/time_icon/time_f3.png
  15. BIN
      resources/gui/time_icon/time_f4.png
  16. BIN
      resources/gui/time_icon/time_f5.png
  17. BIN
      resources/gui/time_icon/time_f6.png
  18. BIN
      resources/gui/time_icon/time_f7.png
  19. BIN
      resources/gui/time_icon/time_f8.png
  20. BIN
      resources/gui/time_icon/time_f9.png
  21. BIN
      sounds/dash.wav
  22. BIN
      sounds/dodge.wav
  23. BIN
      sounds/londoner_jump.wav
  24. BIN
      sounds/mirror_break.wav
  25. BIN
      sounds/mirror_crack.wav
  26. BIN
      sounds/sword_pull.wav
  27. BIN
      sounds/sword_sheath.wav
  28. BIN
      sounds/sword_slash.wav
  29. 14 0
      src/me/hammerle/supersnuvi/entity/components/DefaultHealth.java
  30. 2 0
      src/me/hammerle/supersnuvi/entity/components/ai/FollowHeroController.java
  31. 5 0
      src/me/hammerle/supersnuvi/entity/components/ai/HumanController.java
  32. 6 1
      src/me/hammerle/supersnuvi/entity/components/ai/LondonerController.java
  33. 77 22
      src/me/hammerle/supersnuvi/gamelogic/Level.java
  34. 4 1
      src/me/hammerle/supersnuvi/gamelogic/StateRenderer.java
  35. 16 0
      src/me/hammerle/supersnuvi/tiles/BottledSoulTile.java
  36. 5 0
      src/me/hammerle/supersnuvi/tiles/Tile.java
  37. 13 0
      src/me/hammerle/supersnuvi/util/SoundUtils.java

BIN
resources/gui/health_num/health_num_0.png


BIN
resources/gui/health_num/health_num_1.png


BIN
resources/gui/health_num/health_num_2.png


BIN
resources/gui/health_num/health_num_3.png


BIN
resources/gui/health_num/health_num_4.png


BIN
resources/gui/health_num/health_num_5.png


BIN
resources/gui/health_num/health_num_6.png


BIN
resources/gui/health_num/health_num_7.png


BIN
resources/gui/time_icon/time_f1.png


BIN
resources/gui/time_icon/time_f10.png


BIN
resources/gui/time_icon/time_f11.png


BIN
resources/gui/time_icon/time_f12.png


BIN
resources/gui/time_icon/time_f2.png


BIN
resources/gui/time_icon/time_f3.png


BIN
resources/gui/time_icon/time_f4.png


BIN
resources/gui/time_icon/time_f5.png


BIN
resources/gui/time_icon/time_f6.png


BIN
resources/gui/time_icon/time_f7.png


BIN
resources/gui/time_icon/time_f8.png


BIN
resources/gui/time_icon/time_f9.png


BIN
sounds/dash.wav


BIN
sounds/dodge.wav


BIN
sounds/londoner_jump.wav


BIN
sounds/mirror_break.wav


BIN
sounds/mirror_crack.wav


BIN
sounds/sword_pull.wav


BIN
sounds/sword_sheath.wav


BIN
sounds/sword_slash.wav


+ 14 - 0
src/me/hammerle/supersnuvi/entity/components/DefaultHealth.java

@@ -1,6 +1,7 @@
 package me.hammerle.supersnuvi.entity.components;
 
 import me.hammerle.supersnuvi.entity.Entity;
+import me.hammerle.supersnuvi.util.SoundUtils;
 
 public class DefaultHealth extends Health
 {
@@ -119,11 +120,24 @@ public class DefaultHealth extends Health
         }
         else if(health < 0.0)
         {
+            health = 0.0;
             if(deathTicks == -1)
             {
                 deathTicks = 0;
                 ent.getAnimator().resetFrames();
             }
         }
+        
+        if(h < 0 && ent.getItemCollector().isHero())
+        {
+            if(health == 0.0)
+            {
+                SoundUtils.playSound(SoundUtils.Sound.MIRROR_BREAK);
+            }
+            else
+            {
+                SoundUtils.playSound(SoundUtils.Sound.MIRROR_CRACK);
+            }
+        }
     }
 }

+ 2 - 0
src/me/hammerle/supersnuvi/entity/components/ai/FollowHeroController.java

@@ -3,6 +3,7 @@ package me.hammerle.supersnuvi.entity.components.ai;
 import me.hammerle.supersnuvi.entity.Entity;
 import me.hammerle.supersnuvi.tiles.Location;
 import me.hammerle.supersnuvi.util.Face;
+import me.hammerle.supersnuvi.util.SoundUtils;
 
 public class FollowHeroController extends EntityController
 {
@@ -29,6 +30,7 @@ public class FollowHeroController extends EntityController
             if(jump)
             {
                 jump = false;
+                SoundUtils.playSound(SoundUtils.Sound.LONDONER_JUMP);
                 ent.getMovement().jump();
             }
             double distance = ent.signedDistanceX(hero);

+ 5 - 0
src/me/hammerle/supersnuvi/entity/components/ai/HumanController.java

@@ -76,11 +76,13 @@ public class HumanController extends EntityController
             {
                 combatMode = false;
                 combatTimer = -ent.getAnimator().getCombatStartTicks();
+                SoundUtils.playSound(SoundUtils.Sound.SWORD_SHEATH);               
             }
             else
             {
                 combatMode = true;
                 combatTimer = ent.getAnimator().getCombatStartTicks();
+                SoundUtils.playSound(SoundUtils.Sound.SWORD_PULL);
             }
         }
         
@@ -166,15 +168,18 @@ public class HumanController extends EntityController
             }
             else if(KeyHandler.COMBAT_ATTACK.wasJustReleased() && attackTimer == -1)
             {
+                SoundUtils.playSound(SoundUtils.Sound.SWORD_SLASH);
                 attackTimer = 0;
             }
             else if(KeyHandler.COMBAT_DASH.wasJustReleased() && dashTimer == -1 && ent.getEnergy().getEnergyPercent() >= 0.3)
             {
+                SoundUtils.playSound(SoundUtils.Sound.DASH);
                 dashTimer = 0;
                 ent.getEnergy().addEnergyPercent(-0.3);
             }
             else if(KeyHandler.COMBAT_DODGE.wasJustReleased() && dodgeTimer == -1 && ent.getEnergy().getEnergyPercent() >= 0.1)
             {
+                SoundUtils.playSound(SoundUtils.Sound.DODGE);
                 dodgeTimer = 0;
                 ent.getEnergy().addEnergyPercent(-0.10);
             }

+ 6 - 1
src/me/hammerle/supersnuvi/entity/components/ai/LondonerController.java

@@ -4,6 +4,7 @@ import me.hammerle.supersnuvi.entity.Entity;
 import me.hammerle.supersnuvi.rendering.Game;
 import me.hammerle.supersnuvi.tiles.Location;
 import me.hammerle.supersnuvi.util.Face;
+import me.hammerle.supersnuvi.util.SoundUtils;
 
 public class LondonerController extends EntityController
 {
@@ -159,6 +160,7 @@ public class LondonerController extends EntityController
         }
         if(jump)
         {
+            SoundUtils.playSound(SoundUtils.Sound.LONDONER_JUMP);
             ent.getMovement().jump();
             jump = false;
         }
@@ -176,7 +178,10 @@ public class LondonerController extends EntityController
     @Override
     public void onCollideWithTile(Location loc, Face face) 
     {
-        switchDirection(face);
+        if(loc.getTile().shouldAiUseCollisionBox(loc.getX(), loc.getY()))
+        {
+            switchDirection(face);
+        }
     }
     
     private void switchDirection(Face face)

+ 77 - 22
src/me/hammerle/supersnuvi/gamelogic/Level.java

@@ -28,20 +28,23 @@ public final class Level
     
     private final String name;
     
-    private final HashMap<Integer, Entity> entities;
+    private final HashMap<Integer, Entity> entities = new HashMap<>();;
     private final LinkedList<Entity> spawnQueue = new LinkedList<>();
     private Entity hero;
-    private int entityCounter;
+    private int entityCounter = 0;
     
-    private boolean shouldReset;
-    private boolean done;
+    private boolean shouldReset = false;
+    private boolean done = true; // this will be reseted in resetLevel()
     
     private int souls;
     private int maxSouls;
     
-    private double time;
+    private double time = 0.0;
+    private double clockTick = 0.0;
     
-    private TreeSet<Point> spawns;
+    private int tries = 7;
+    
+    private TreeSet<Point> spawns = new TreeSet<>();
     
     public Level(StateRenderer state, File f)
     {
@@ -49,13 +52,6 @@ public final class Level
         this.renderer = state.getRenderer();
         this.data = new LevelData(f);
         this.worldLoaded = data.load();
-        this.entities = new HashMap<>();
-        this.entityCounter = 0;
-        this.shouldReset = false;
-        this.done = false;
-        this.time = 0.0;
-        
-        this.spawns = new TreeSet<>();
         
         if(worldLoaded)
         {
@@ -136,6 +132,7 @@ public final class Level
         {
             spawns.add(new Point(5, 5));
         }
+        spawns.add(new Point(15, 10));
 
         resetLevel();
         
@@ -173,18 +170,29 @@ public final class Level
         shouldReset = true;
     }
     
-    public void resetLevel()
+    public boolean resetLevel()
     {
+        boolean dead = false;
+        if(!done) // hero just died
+        {
+            tries--;
+            if(tries <= 0)
+            {
+                tries = 7;
+                dead = true;
+            }
+        }
         state.resetTiles();
         data.activateEntities();
         souls = 0;
         time = 0.0;
         shouldReset = false;
         done = false;
-        Entity h = spawnHero();
+        Entity h = spawnHero(dead);
         hero = h;
         entities.clear();
         entities.put(entityCounter++, h);
+        return dead;
     }
     
     public void spawnEntity(Entity ent)
@@ -192,11 +200,11 @@ public final class Level
         spawnQueue.add(ent);
     }
     
-    public Entity spawnHero()
+    public Entity spawnHero(boolean first)
     {
         Entity h = hero;
         Point p;
-        if(h == null || hero.getX() < 0)
+        if(h == null || hero.getX() < 0 || first)
         {
             // first spawn or out of map, use first spawn
             p = spawns.first();
@@ -353,6 +361,34 @@ public final class Level
         Utils.getImage("gui/health_bar/health_bar_7", true)
     };
     
+    private final static Image[] LIFE_OVERLAY = new Image[]
+    {
+        Utils.getImage("gui/health_num/health_num_0", true),
+        Utils.getImage("gui/health_num/health_num_1", true),
+        Utils.getImage("gui/health_num/health_num_2", true),
+        Utils.getImage("gui/health_num/health_num_3", true),
+        Utils.getImage("gui/health_num/health_num_4", true),
+        Utils.getImage("gui/health_num/health_num_5", true),
+        Utils.getImage("gui/health_num/health_num_6", true),
+        Utils.getImage("gui/health_num/health_num_7", true)
+    };
+    
+    private final static Image[] TIME_CLOCK = new Image[]
+    {
+        Utils.getImage("gui/time_icon/time_f1", true),
+        Utils.getImage("gui/time_icon/time_f2", true),
+        Utils.getImage("gui/time_icon/time_f3", true),
+        Utils.getImage("gui/time_icon/time_f4", true),
+        Utils.getImage("gui/time_icon/time_f5", true),
+        Utils.getImage("gui/time_icon/time_f6", true),
+        Utils.getImage("gui/time_icon/time_f7", true),
+        Utils.getImage("gui/time_icon/time_f8", true),
+        Utils.getImage("gui/time_icon/time_f9", true),
+        Utils.getImage("gui/time_icon/time_f10", true),
+        Utils.getImage("gui/time_icon/time_f11", true),
+        Utils.getImage("gui/time_icon/time_f12", true)
+    };
+    
     public void render()
     {
         if(worldLoaded)
@@ -412,7 +448,7 @@ public final class Level
                 // gui background
                 renderer.drawFixedImage(AROUND_BACKGROUND, x, y, w, h);
                 
-                // health mirror
+                // health mirror    
                 int hFrame = (int) (hero.getHealth().getHealthPercent() * (HEALTH_BAR.length - 1));
                 renderer.drawFixedImage(HEALTH_BAR[hFrame], x + 78 * scale, y + 8 * scale, 
                         HEALTH_BAR[hFrame].getWidth() * scale, HEALTH_BAR[hFrame].getHeight() * scale);
@@ -429,7 +465,12 @@ public final class Level
                         wEnergy * scale, ENERGY_FULL.getHeight() * scale);
                 
                 // gui foreground
-                renderer.drawFixedImage(AROUND_FOREGROUND, x, y, w, h);           
+                renderer.drawFixedImage(AROUND_FOREGROUND, x, y, w, h);   
+                
+                // tries go over foreground
+                renderer.drawFixedImage(LIFE_OVERLAY[tries], x + 89 * scale, y + 52 * scale,
+                        LIFE_OVERLAY[tries].getWidth() * scale, LIFE_OVERLAY[tries].getHeight() * scale);
+                
                 
                 // grey background
                 double boxHeight = renderer.getTextHeight(2) + 10;
@@ -442,12 +483,26 @@ public final class Level
                 }
                 renderer.restore();
 
+                // soul / time rendering
+                x = 5;
+                y = 5;
+                w = renderer.getTextWidth(1);
+                h = renderer.getTextHeight(1);
+                
                 // soul rendering
-                renderer.drawFixedImagePart(BottledSoulTile.IMAGE[0], 14, 8, 34, 52, 5, 5, renderer.getTextWidth(1), renderer.getTextHeight(1));
-                renderer.drawText(5 + renderer.getTextWidth(1), 5, formatBottles(souls));
+                renderer.drawFixedImagePart(BottledSoulTile.IMAGE[0], 14, 8, 34, 52, x, y, w, h);
+                renderer.drawText(x + renderer.getTextWidth(1), y, formatBottles(souls));
 
+                y += renderer.getTextHeight(1);
+                
                 // time rendering
-                renderer.drawText(5 + renderer.getTextWidth(1), 5 + renderer.getTextHeight(1), formatTime(time));
+                clockTick += 0.05;
+                if(clockTick >= TIME_CLOCK.length)
+                {
+                    clockTick = 0.0;
+                }
+                renderer.drawFixedImagePart(TIME_CLOCK[(int) clockTick], 0, 0, 32, 32, x, y, w, h);
+                renderer.drawText(x + renderer.getTextWidth(1), y, formatTime(time));
             }
             renderer.stopTextDrawing();
         }

+ 4 - 1
src/me/hammerle/supersnuvi/gamelogic/StateRenderer.java

@@ -388,7 +388,10 @@ public class StateRenderer
             
             if(currentLevel.shouldReset())
             {
-                currentLevel.resetLevel();
+                if(currentLevel.resetLevel())
+                {
+                    currentLevel = null;
+                }
             }
             
             if(KeyHandler.ESCAPE.wasJustReleased())

+ 16 - 0
src/me/hammerle/supersnuvi/tiles/BottledSoulTile.java

@@ -45,6 +45,22 @@ public class BottledSoulTile extends Tile
         }
     }
     
+    @Override
+    public CollisionBox getCollisionBox(int x, int y) 
+    {
+        if(states.contains(getKey(x, y)))
+        {
+            return CollisionBox.NULL_BOX;
+        }
+        return super.getCollisionBox(x, y);
+    }
+
+    @Override
+    public boolean shouldAiUseCollisionBox(int x, int y) 
+    {
+        return false;
+    }
+    
     @Override
     public Image getImage(int x, int y) 
     {

+ 5 - 0
src/me/hammerle/supersnuvi/tiles/Tile.java

@@ -83,6 +83,11 @@ public abstract class Tile
         return CollisionBox.NULL_BOX.reset();
     }
     
+    public boolean shouldAiUseCollisionBox(int x, int y)
+    {
+        return true;
+    }
+    
     public CollisionBox getMovementBox(int x, int y)
     {
         if(movementCollision != null)

+ 13 - 0
src/me/hammerle/supersnuvi/util/SoundUtils.java

@@ -18,6 +18,15 @@ public class SoundUtils
     
     public enum Sound
     {
+        DASH("dash", true),
+        DODGE("dodge", true), 
+        LONDONER_JUMP("londoner_jump", true), 
+        MIRROR_BREAK("mirror_break", true), 
+        MIRROR_CRACK("mirror_crack", true), 
+        SWORD_PULL("sword_pull", true),
+        SWORD_SHEATH("sword_sheath", true), 
+        SWORD_SLASH("sword_slash", true), 
+        
         COLLECT("collect", true), 
         JUMP("jump", true), 
         JUMP_ON_BOUNCE_SHROOM("jump_on_bounce_shroom", false), 
@@ -82,6 +91,10 @@ public class SoundUtils
     {
         if(StateRenderer.isSoundEnabled())
         {
+            /*if(sound != Sound.MENU_MUSIC && sound != Sound.SONG_1 && sound != Sound.WALK)
+            {
+                System.out.println("PLAYING " + sound);
+            }*/
             sound.play();
         }
     }