Forráskód Böngészése

hero death animation, hero respawn on death, color overlay when healed or damaged

Kajetan Johannes Hammerle 5 éve
szülő
commit
6a07252484

+ 2 - 1
src/me/hammerle/supersnuvi/entity/Entity.java

@@ -199,7 +199,6 @@ public final class Entity
         lastPosY = posY;
         
         controller.tick();
-        health.tick();
         energy.tick();
         
         preMotionX = motionX;
@@ -352,6 +351,8 @@ public final class Entity
         {
             motionX = 0.0f;
         }
+        
+        health.tick();
     }
     
     public void renderTick(float lag)

+ 3 - 2
src/me/hammerle/supersnuvi/entity/components/DefaultHealth.java

@@ -2,6 +2,7 @@ package me.hammerle.supersnuvi.entity.components;
 
 import me.hammerle.supersnuvi.Game;
 import me.hammerle.supersnuvi.entity.Entity;
+import me.hammerle.supersnuvi.tiles.Tile;
 import me.hammerle.supersnuvi.util.SoundUtils;
 import me.hammerle.supersnuvi.util.SoundUtils.Sound;
 
@@ -63,7 +64,7 @@ public class DefaultHealth extends Health
     @Override
     public boolean shouldDespawn() 
     {
-        return isDead() && !ent.isAnimated();
+        return (isDead() && !ent.isAnimated()) || (ent.getY() > ent.getLevel().getHeight() * Tile.SIZE);
     }
     
     @Override
@@ -105,7 +106,7 @@ public class DefaultHealth extends Health
         }
         else
         {
-            hurtTicks = -Game.getTicksForMillis(500);
+            hurtTicks = -Game.getTicksForMillis(250);
             SoundUtils.playSound(soundHeal);
         }
         health += h;

+ 66 - 2
src/me/hammerle/supersnuvi/entity/components/ai/HumanController.java

@@ -32,7 +32,9 @@ public class HumanController extends Controller
     };
     
     private int walkFrame = 0;
+    private int idleCounter = 0;
     private int idleFrame = 0;
+    private int deathFrame = 0;
 
     public HumanController(Entity ent) 
     {
@@ -41,21 +43,42 @@ public class HumanController extends Controller
     
     private void nextWalkFrame()
     {
-        walkFrame = (walkFrame + 1) % 9;
+        deathFrame = 0;
         idleFrame = 0;
+        walkFrame = (walkFrame + 1) % 9;
     }
     
     private void nextIdleFrame()
     {
+        deathFrame = 0;
         walkFrame = 0;
-        idleFrame = (idleFrame + 1) % 14;   
+        idleCounter++;
+        if(idleCounter >= 3)
+        {
+            idleCounter = 0;
+            idleFrame = (idleFrame + 1) % 14;   
+        }
+    }
+    
+    private void nextDeathFrame()
+    {
+        walkFrame = 0;
+        idleFrame = 0;
+        deathFrame++;
     }
     
     private void resetFrames()
     {
+        deathFrame = 0;
         walkFrame = 0;
         idleFrame = 0;   
     }
+
+    @Override
+    public boolean isAnimated()
+    {
+        return deathFrame < 17;
+    }
     
     @Override
     public void tick() 
@@ -65,6 +88,28 @@ public class HumanController extends Controller
             tp.draw = false;
         }
         
+        if(ent.getHealth().isDead())
+        {
+            body.draw = true;
+            body.ox = ent.getFace() == Face.RIGHT ? 0.0f: -32.0f;
+            body.oy = 0.0f;
+            body.h = 64.0f;
+            body.w = 64.0f;
+            
+            body.tx = (deathFrame * 64.0f) / SIZE;
+            if(deathFrame < 16)
+            {
+                body.ty = 192.0f / SIZE;
+            }
+            else
+            {
+                body.ty = 256.0f / SIZE;
+            }
+            
+            nextDeathFrame();
+            return;
+        }
+        
         float speed = ent.getMovement().getVelocityX();
         if(Keys.RUN.isDown())
         {
@@ -118,6 +163,19 @@ public class HumanController extends Controller
     @Override
     public void renderTick(float lag)
     {
+        if(ent.getHealth().wasHurt())
+        {
+            Shader.setColorEnabled(true);
+            Shader.setMixColorEnabled(true);
+            Shader.setMixColor(1.0f, 0.0f, 0.0f, 1.0f);
+        }
+        if(ent.getHealth().wasHealed())
+        {
+            Shader.setColorEnabled(true);
+            Shader.setMixColorEnabled(true);
+            Shader.setMixColor(0.0f, 1.0f, 0.0f, 1.0f);
+        }
+        
         HERO.bind();
         float x = Utils.interpolate(ent.getLastX(), ent.getX(), lag);
         float y = Utils.interpolate(ent.getLastY(), ent.getY(), lag);
@@ -144,5 +202,11 @@ public class HumanController extends Controller
                         tp.tx + (tp.w / SIZE), tp.ty + (tp.h / SIZE));
             }
         }
+        
+        if(ent.getHealth().wasHurt() || ent.getHealth().wasHealed())
+        {
+            Shader.setColorEnabled(false);
+            Shader.setMixColorEnabled(false);
+        }
     }
 }

+ 21 - 1
src/me/hammerle/supersnuvi/gamelogic/Level.java

@@ -236,6 +236,17 @@ public final class Level
         hero = h;
         entities.clear();
         entities.put(entityCounter++, h);
+        
+        for(int l = 0; l < meshLayers; l++)
+        {
+            for(int x = 0; x < meshWidth; x++)
+            {
+                for(int y = 0; y < meshHeight; y++)
+                {
+                    meshes[l][x][y].clear();
+                }
+            }
+        }
         return false;
     }
     
@@ -262,7 +273,16 @@ public final class Level
                 p = spawns.first();
             }
         }
-        return EntityBuilder.buildHero(this, Utils.toCoord(p.getX()), Utils.toCoord(p.getY()));
+        
+        Entity newHero = EntityBuilder.buildHero(this, Utils.toCoord(p.getX()), Utils.toCoord(p.getY()));
+        
+        // reset the camera
+        oldCameraX = -getViewX(newHero.getCenterX());
+        oldCameraY = -getViewY(newHero.getCenterY());
+        cameraX = oldCameraX;
+        cameraY = oldCameraY;
+        
+        return newHero;
     }
     
     public void increaseSouls(int score)