DEADSOFTWARE

Add more blocks
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameRenderer.java
index cc3bcdee8c9f849e89f1d8184bb68b397c4660e8..84060ca2b804d6749702257f1faa5aa2cf8b8829 100644 (file)
@@ -61,7 +61,8 @@ public class GameRenderer {
         if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight();
         for (int y=minY; y<maxY; y++) {
             for (int x=minX; x<maxX; x++) {
-                if (gameProc.world.getForeMap(x,y)>0) {
+                if (gameProc.world.getForeMap(x,y)>0 &&
+                        !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {
                     spriteBatch.draw(
                             Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
                             x * 16 - camera.position.x,y * 16 - camera.position.y);
@@ -76,6 +77,27 @@ public class GameRenderer {
         }
     }
 
+    private void drawWorldForeground(){
+        int minX = (int) (camera.position.x/16);
+        int minY = (int) (camera.position.y/16);
+        int maxX = (int) ((camera.position.x+camera.viewportWidth)/16)+1;
+        int maxY = (int) ((camera.position.y+camera.viewportHeight)/16)+1;
+        if (minX<0) minX=0;
+        if (minY<0) minY=0;
+        if (maxX>gameProc.world.getWidth()) maxX = gameProc.world.getWidth();
+        if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight();
+        for (int y=minY; y<maxY; y++) {
+            for (int x=minX; x<maxX; x++) {
+                if (gameProc.world.getForeMap(x,y)>0 &&
+                        Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {
+                    spriteBatch.draw(
+                            Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
+                            x * 16 - camera.position.x,y * 16 - camera.position.y);
+                }
+            }
+        }
+    }
+
     private void drawMob(Mob mob) {
         mob.draw(spriteBatch,
                 mob.position.x-camera.position.x, mob.position.y-camera.position.y);
@@ -121,7 +143,7 @@ public class GameRenderer {
 
     private void drawGUI() {
         spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0);
-        for (int i=0; i<8; i++) {
+        for (int i=0; i<9; i++) {
             if (gameProc.player.inventory[i]>0) {
                 spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
                         camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2+3+i*20,
@@ -155,6 +177,7 @@ public class GameRenderer {
         drawWorld();
         for (Mob mob : gameProc.mobs) drawMob(mob);
         drawPlayer(gameProc.player);
+        drawWorldForeground();
         drawGUI();
         spriteBatch.end();
 
@@ -175,7 +198,7 @@ public class GameRenderer {
         drawString("Y: "+(int)(gameProc.player.position.y/16), 0, 60);
         drawString("Block: "+
                 Items.BLOCKS.keys().toArray().get(gameProc.world.getForeMap(
-                        (int)(gameProc.player.position.x/16),
+                        (int)((gameProc.player.position.x+gameProc.player.texWidth/2)/16),
                         (int)(gameProc.player.position.y/16+2))),
                 0, 80);
         fontBatch.end();