DEADSOFTWARE

Ciclic worlds
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameRenderer.java
index e119487ee12355a107125409e99e15927cf9eea7..944093826043bbd51204107b89fabddd04e193c9 100644 (file)
@@ -5,12 +5,11 @@ import com.badlogic.gdx.graphics.GL20;
 import com.badlogic.gdx.graphics.OrthographicCamera;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavecraft.Assets;
 import ru.deadsoftware.cavecraft.CaveGame;
-import ru.deadsoftware.cavecraft.Items;
 import ru.deadsoftware.cavecraft.GameScreen;
+import ru.deadsoftware.cavecraft.Items;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
 import ru.deadsoftware.cavecraft.game.objects.Player;
 
@@ -53,22 +52,16 @@ public class GameRenderer {
         Assets.minecraftFont.draw(fontBatch, str, x, y);
     }
 
-    private void drawWorld() {
-        int minX = (int) (camera.position.x/16);
-        int minY = (int) (camera.position.y/16);
+    private void drawWorldBackground() {
+        int minX = (int) (camera.position.x/16)-1;
+        int minY = (int) (camera.position.y/16)-1;
         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);*/
+                if (gameProc.world.getForeMap(x,y)>0){
                 } else if (gameProc.world.getBackMap(x,y)>0) {
                     spriteBatch.draw(
                             Items.BLOCKS.getValueAt(gameProc.world.getBackMap(x,y)).getTexture(),
@@ -81,18 +74,15 @@ public class GameRenderer {
     }
 
     private void drawWorldForeground(){
-        int minX = (int) (camera.position.x/16);
-        int minY = (int) (camera.position.y/16);
+        int minX = (int) (camera.position.x/16)-1;
+        int minY = (int) (camera.position.y/16)-1;
         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) {*/
+                if (gameProc.world.getForeMap(x,y)>0) {
                     spriteBatch.draw(
                             Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
                             x * 16 - camera.position.x,y * 16 - camera.position.y);
@@ -107,47 +97,47 @@ public class GameRenderer {
     }
 
     private void drawPlayer(Player pl) {
-        if (!pl.moveX.equals(Vector2.Zero) || Assets.playerSkin[0][2].getRotation()!=0) {
-            Assets.playerSkin[0][2].rotate(Mob.ANIM_SPEED);
-            Assets.playerSkin[1][2].rotate(-Mob.ANIM_SPEED);
-            Assets.playerSkin[0][3].rotate(-Mob.ANIM_SPEED);
-            Assets.playerSkin[1][3].rotate(Mob.ANIM_SPEED);
+        if (!pl.moveX.equals(Vector2.Zero) || Assets.playerSprite[0][2].getRotation()!=0) {
+            Assets.playerSprite[0][2].rotate(Player.ANIM_SPEED);
+            Assets.playerSprite[1][2].rotate(-Player.ANIM_SPEED);
+            Assets.playerSprite[0][3].rotate(-Player.ANIM_SPEED);
+            Assets.playerSprite[1][3].rotate(Player.ANIM_SPEED);
         } else {
-            Assets.playerSkin[0][2].setRotation(0);
-            Assets.playerSkin[1][2].setRotation(0);
-            Assets.playerSkin[0][3].setRotation(0);
-            Assets.playerSkin[1][3].setRotation(0);
+            Assets.playerSprite[0][2].setRotation(0);
+            Assets.playerSprite[1][2].setRotation(0);
+            Assets.playerSprite[0][3].setRotation(0);
+            Assets.playerSprite[1][3].setRotation(0);
         }
-        if (Assets.playerSkin[0][2].getRotation()>=60 || Assets.playerSkin[0][2].getRotation()<=-60)
-            Mob.ANIM_SPEED = -Mob.ANIM_SPEED;
+        if (Assets.playerSprite[0][2].getRotation()>=60 || Assets.playerSprite[0][2].getRotation()<=-60)
+            Player.ANIM_SPEED = -Player.ANIM_SPEED;
 
         //back hand
-        Assets.playerSkin[1][2].setPosition(
+        Assets.playerSprite[1][2].setPosition(
                 pl.position.x - camera.position.x - 6,
                 pl.position.y - camera.position.y);
-        Assets.playerSkin[1][2].draw(spriteBatch);
+        Assets.playerSprite[1][2].draw(spriteBatch);
         //back leg
-        Assets.playerSkin[1][3].setPosition(
+        Assets.playerSprite[1][3].setPosition(
                 pl.position.x - camera.position.x - 6,
                 pl.position.y - camera.position.y + 10);
-        Assets.playerSkin[1][3].draw(spriteBatch);
+        Assets.playerSprite[1][3].draw(spriteBatch);
         //front leg
-        Assets.playerSkin[0][3].setPosition(
+        Assets.playerSprite[0][3].setPosition(
                 pl.position.x - camera.position.x - 6,
                 pl.position.y - camera.position.y + 10);
-        Assets.playerSkin[0][3].draw(spriteBatch);
+        Assets.playerSprite[0][3].draw(spriteBatch);
         //head
-        spriteBatch.draw(Assets.playerSkin[pl.dir][0],
+        spriteBatch.draw(Assets.playerSprite[pl.dir][0],
                 pl.position.x - camera.position.x - 2,
                 pl.position.y - camera.position.y - 2);
         //body
-        spriteBatch.draw(Assets.playerSkin[pl.dir][1],
+        spriteBatch.draw(Assets.playerSprite[pl.dir][1],
                 pl.position.x - camera.position.x - 2, pl.position.y - camera.position.y + 8);
         //front hand
-        Assets.playerSkin[0][2].setPosition(
+        Assets.playerSprite[0][2].setPosition(
                 pl.position.x - camera.position.x - 6,
                 pl.position.y - camera.position.y);
-        Assets.playerSkin[0][2].draw(spriteBatch);
+        Assets.playerSprite[0][2].draw(spriteBatch);
     }
 
     private void drawCreative() {
@@ -162,7 +152,7 @@ public class GameRenderer {
         for (int i=0; i<9; i++) {
             if (gameProc.player.inventory[i]>0)
                 spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
-                        x+8+i*18, y+184);
+                        x+8+i*18, y+Assets.creativeInv.getRegionHeight()-24);
         }
     }
 
@@ -197,7 +187,8 @@ public class GameRenderer {
     }
 
     private void drawGamePlay() {
-        drawWorld();
+        drawWorldBackground();
+        Mob.animateMobs();
         for (Mob mob : gameProc.mobs) drawMob(mob);
         drawPlayer(gameProc.player);
         drawWorldForeground();
@@ -230,7 +221,9 @@ public class GameRenderer {
         drawString("CaveCraft "+CaveGame.VERSION, 0, 0);
         drawString("FPS: "+GameScreen.FPS, 0, 20);
         drawString("X: "+(int)(gameProc.player.position.x/16), 0, 40);
-        drawString("Y: "+(int)(gameProc.player.position.y/16), 0, 60);
+        drawString("Y: "+(gameProc.world.getHeight()-(int)(gameProc.player.position.y/16)), 0, 60);
+        drawString("Seed: "+WorldGen.getSeed(), 0, 80);
+        drawString("Mobs: "+gameProc.mobs.size, 0, 100);
         fontBatch.end();
     }