Procházet zdrojové kódy

gui rendering completed, dynamic clock hand, clock and bottle handled by size (8x8, 16x16, 24x24)

Kajetan Johannes Hammerle před 6 roky
rodič
revize
3619825494

binární
resources/gui.png


binární
resources/gui.xcf


+ 4 - 1
slot1.txt

@@ -1,6 +1,9 @@
 level.00-Tech_Demo.map=true
 level.00-Tech_Demo.map.bottles=9
-level.00-Tech_Demo.map.time=1.9124999999999952
+level.00-Tech_Demo.map.time=1.5374999999999965
 level.01-Parabola.map=true
 level.01-Parabola.map.bottles=1
 level.01-Parabola.map.time=1.6249999999999962
+level.02-Out_of_Reach.map=true
+level.02-Out_of_Reach.map.bottles=4
+level.02-Out_of_Reach.map.time=9.674999999999985

+ 4 - 3
src/me/hammerle/supersnuvi/Game.java

@@ -16,7 +16,8 @@ import me.hammerle.supersnuvi.util.SoundUtils;
 
 public class Game extends Engine
 {
-    private static final int MS_PER_TICK = 50;
+    public static final int MS_PER_TICK = 50;
+    public static final float SECS_PER_TICK = MS_PER_TICK / 1000.0f;
     
     public static int getTicksForMillis(int millis)
     {
@@ -528,14 +529,14 @@ public class Game extends Engine
                     Level l = levels[i];
                     fr.drawString(left, y, l.getName()); 
                     fr.drawString(secLeft, y, l.formatBottles(sc.getInt("level." + l.getFileName() + ".bottles", 0))); 
-                    y = fr.drawString(thirdLeft, y, l.formatTime(sc.getDouble("level." + l.getFileName() + ".time", 0))); 
+                    y = fr.drawString(thirdLeft, y, l.formatTime(sc.getFloat("level." + l.getFileName() + ".time", 0))); 
                 }
                 if(lastIndex == levels.length)
                 {
                     Level l = levels[lastIndex - 1];
                     fr.drawString(left, y, l.getName()); 
                     fr.drawString(secLeft, y, l.formatBottles(sc.getInt("level." + l.getFileName() + ".bottles", 0))); 
-                    fr.drawString(thirdLeft, y, l.formatTime(sc.getDouble("level." + l.getFileName() + ".time", 0))); 
+                    fr.drawString(thirdLeft, y, l.formatTime(sc.getFloat("level." + l.getFileName() + ".time", 0))); 
                 }
                 else
                 {

+ 4 - 1
src/me/hammerle/supersnuvi/entity/components/ai/HumanController.java

@@ -43,7 +43,10 @@ public class HumanController extends Controller
         
         if(Keys.JUMP.isDown())
         {
-            ent.getMovement().jump();
+            if(ent.getMovement().jump())
+            {
+                ent.getEnergy().addEnergyPercent(-0.3f);
+            }
         }
     }
     

+ 84 - 85
src/me/hammerle/supersnuvi/gamelogic/Level.java

@@ -23,6 +23,8 @@ public final class Level
     private final static float ERROR = 1f / 65536f;
     
     public final static Texture TILES = new Texture("resources/tiles.png");
+    private final static Texture GUI = new Texture("resources/gui.png");
+    private final static TextureRenderer GUI_RENDERER = new TextureRenderer(60);
     
     private final boolean worldLoaded;
     private final LevelData data;
@@ -41,8 +43,7 @@ public final class Level
     private int souls;
     private int maxSouls;
     
-    private double time = 0.0;
-    private double clockTick = 0.0;
+    private float time = 0.0f;
     
     private float cameraX = 0.0f;
     private float cameraY = 0.0f;
@@ -228,7 +229,7 @@ public final class Level
         Game.get().resetTiles();
         data.activateEntities();
         souls = 0;
-        time = 0.0;
+        time = 0.0f;
         shouldReset = false;
         done = false;
         Entity h = spawnHero(true);
@@ -284,7 +285,7 @@ public final class Level
         return data;
     }
     
-    public double getTime()
+    public float getTime()
     {
         return time;
     }  
@@ -307,8 +308,7 @@ public final class Level
     {
         if(worldLoaded)
         {
-            time += 0.0125;
-            
+            time += Game.SECS_PER_TICK;
             Game.get().tickTiles();
             
             // entity spawn layer
@@ -388,13 +388,13 @@ public final class Level
         return new String(c);
     }
     
-    public String formatTime(double time)
+    public String formatTime(float time)
     {
-        if(time == -1.0)
+        if(time == -1.0f)
         {
             return "-----";
         }
-        else if(time >= 999.9)
+        else if(time >= 999.9f)
         {
             return "999.9";
         }
@@ -526,10 +526,6 @@ public final class Level
     {
         if(worldLoaded)
         {
-            // setting the right view center
-            double rWidth = Shader.getViewWidth();
-            double rHeight = Shader.getViewHeight();
-            
             float camX = Utils.interpolate(oldCameraX, cameraX, lag);
             float camY = Utils.interpolate(oldCameraY, cameraY, lag);
             
@@ -598,81 +594,84 @@ public final class Level
                 }
             }
             
-            /*
             // menu rendering
-            // |-------------------------------------| 
-            // | B00/00 | ENERGYENERGY | HPHP | TIME |
-            // |-------------------------------------| 
-            renderer.prepareTextDrawing(255, 255, 255, 1.0, 40);
-            {
-                double scale = renderer.getHeight() / 300;
-                
-                double w = AROUND_BACKGROUND.getWidth() * scale;
-                double h = AROUND_BACKGROUND.getHeight() * scale;
-                
-                double x = renderer.getWidth() - w;
-                double y = 0;
-                
-                // gui background
-                renderer.drawFixedImage(AROUND_BACKGROUND, x, y, w, h);
-                
-                // 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);
-                
-                // energy
-                renderer.drawFixedImage(ENERGY_EMPTY, x + 8 * scale, y + 12 * scale, 
-                        ENERGY_EMPTY.getWidth() * scale, ENERGY_EMPTY.getHeight() * scale);
-                
-                double wEnergy = ENERGY_FULL.getWidth() * hero.getEnergy().getEnergyPercent();
-                double wEnergyOffset = ENERGY_FULL.getWidth() - wEnergy;
-                renderer.drawFixedImagePart(ENERGY_FULL, 
-                        wEnergyOffset, 0, wEnergy, ENERGY_FULL.getHeight(),
-                        x + (wEnergyOffset + 8) * scale, y + 12 * scale,
-                        wEnergy * scale, ENERGY_FULL.getHeight() * scale);
-                
-                // gui foreground
-                renderer.drawFixedImage(AROUND_FOREGROUND, x, y, w, h);   
-                
-                // tries / health go over foreground
-                renderer.drawFixedImage(LIFE_OVERLAY[hFrame], x + 89 * scale, y + 52 * scale,
-                        LIFE_OVERLAY[hFrame].getWidth() * scale, LIFE_OVERLAY[hFrame].getHeight() * scale);
-                
-                
-                // grey background
-                double boxHeight = renderer.getTextHeight(2) + 10;
-                double boxWidth = renderer.getTextWidth(6) + 10;
-                
-                renderer.save();
-                {
-                    renderer.setFillColor(0, 0, 0, 0.5);
-                    renderer.fillRectangle(0, 0, boxWidth, boxHeight);  
-                }
-                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, x, y, w, h);
-                renderer.drawText(x + renderer.getTextWidth(1), y, formatBottles(souls));
+            Shader.translateTo(0.0f, 0.0f);
+            Shader.updateMatrix();
+            
+            // grey background of clock and bottles
+            float lineHeight = Shader.getFontRenderer().getHeight();
+            float lineWidth = Shader.getFontRenderer().getWidth();
+            Shader.setColorEnabled(true);
+            Shader.setTextureEnabled(false);
+            Shader.getColorRenderer().drawRectangle(0.0f, 0.0f, (lineWidth * 6.0f) + 10.0f, (lineHeight * 2.0f + 10.0f), 0x77000000);
+            Shader.setTextureEnabled(true);
+            float y = 5.0f;
+            y = Shader.getFontRenderer().drawString(13.0f, y, formatBottles(souls));
+            Shader.getFontRenderer().drawString(13.0f, y, formatTime(time));
+            Shader.setColorEnabled(false);
+            
+            float w = Shader.getViewWidth();
 
-                y += renderer.getTextHeight(1);
-                
-                // time rendering
-                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));
+            GUI.bind();
+            GUI_RENDERER.clear();
+            
+            int scale = Shader.getViewScale();
+            
+            // bottles
+            switch(scale)
+            {
+                case 1: GUI_RENDERER.addRectangle(6.0f, 4.0f, 12.0f, 14.0f, 0.0f, 0.046875f, 0.01171875f, 0.068359375f); break;
+                case 2: GUI_RENDERER.addRectangle(6.0f, 4.0f, 12.0f, 14.0f, 0.01171875f, 0.046875f, 0.037109375f, 0.0859375f); break;
+                default: GUI_RENDERER.addRectangle(6.0f, 4.0f, 12.0f, 14.0f, 0.037109375f, 0.046875f, 0.06640625f, 0.10546875f); break;
+            }
+            
+            // clock
+            switch(scale)
+            {
+                case 1: GUI_RENDERER.addRectangle(4.0f, y, 13.0f, y + 9.0f, 0.0f, 0.265625f, 0.017578125f, 0.283203125f); break;
+                case 2: GUI_RENDERER.addRectangle(4.5f, y, 13.0f, y + 8.5f, 0.017578125f, 0.265625f, 0.05078125f, 0.298828125f); break;
+                default: GUI_RENDERER.addRectangle(4.666666666f, y, 13.0f, y + 8.333333333f, 0.05078125f, 0.265625f, 0.099609375f, 0.314453125f); break;
             }
-            renderer.stopTextDrawing();*/
+            
+            // gui background 
+            GUI_RENDERER.addRectangle(w - 111.0f, 0.0f, w - 44.0f, 24.0f, 0.0f, 0.0f, 0.130859375f, 0.046875f);
+            GUI_RENDERER.addRectangle(w - 44.0f, 0.0f, w - 18.0f, 16.0f, 0.130859375f, 0.0f, 0.181640625f, 0.03125f);
+            GUI_RENDERER.addRectangle(w - 76.0f, 24.0f, w - 45.0f, 57.0f, 0.068359375f, 0.046875f, 0.12890625f, 0.111328125f);
+            
+            // health mirror    
+            int healthFrame = (int) (hero.getHealth().getHealthPercent() * 7);
+            float leftMirror = (7 - healthFrame) * 0.0625f;
+            GUI_RENDERER.addRectangle(w - 39.0f, 8.0f, w - 7.0f, 46.0f, leftMirror, 0.15625f, leftMirror + 0.0625f, 0.23046875f);
+            
+            // energy
+            float energy = hero.getEnergy().getEnergyPercent();
+            float fullEnd =  w - 109.0f + 64.0f * energy;
+            GUI_RENDERER.addRectangle(w - 109.0f, 13.0f, fullEnd, 21.0f, 0.0f, 0.140625f, 0.125f * energy, 0.15625f);
+            GUI_RENDERER.addRectangle(fullEnd, 13.0f, w - 45.0f, 21.0f, 0.125f * energy, 0.125f, 0.125f, 0.140625f);
+            
+            // gui foreground
+            GUI_RENDERER.addRectangle(w - 49.0f, 0.0f, w, 64.0f, 0.201171875f, 0.0f, 0.296875f, 0.125f);
+            GUI_RENDERER.addRectangle(w - 109.0f, 15.0f, w - 106.0f, 18.0f, 0.15625f, 0.03125f, 0.162109375f, 0.037109375f);
+            GUI_RENDERER.addRectangle(w - 97.0f, 15.0f, w - 92.0f, 20.0f, 0.1796875f, 0.03125f, 0.189453125f, 0.041015625f);
+            
+            // health number overlay
+            GUI_RENDERER.addRectangle(w - 30.0f, 53.0f, w - 12.0f, 62.0f, leftMirror, 0.23828125f, leftMirror + 0.03515625f, 0.255859375f);
+            
+            GUI_RENDERER.build();
+            GUI_RENDERER.draw();
+            
+            // dynamic clock hand
+            Shader.setColorEnabled(true);
+            Shader.setTextureEnabled(false);
+            switch(scale)
+            {
+                case 1: Shader.translateTo(8.5f, y + 4.5f); break;
+                case 2: Shader.translateTo(8.75f, y + 4.25f); break;
+                default: Shader.translateTo(8.8333333333f, y + 4.16666667f); break;
+            }
+            Shader.rotate(-time * 72.0f);
+            Shader.updateMatrix();
+            Shader.getColorRenderer().drawRectangle(-0.5f / scale, -0.5f / scale, 0.5f / scale, 4.0f - 0.5f * scale, 0xFF000000);    
         }
     }