DEADSOFTWARE

Reimplement mobs
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameRenderer.java
index 389994636043d1b7985bb13a411977d82a8d1b00..e6ead52d5c2f25a8aee5572740c07d95646d09da 100644 (file)
@@ -9,13 +9,14 @@ import com.badlogic.gdx.math.Rectangle;
 import ru.deadsoftware.cavedroid.CaveGame;
 import ru.deadsoftware.cavedroid.GameScreen;
 import ru.deadsoftware.cavedroid.game.mobs.Mob;
+import ru.deadsoftware.cavedroid.game.mobs.Pig;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
+import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 import ru.deadsoftware.cavedroid.misc.Renderer;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
-import static ru.deadsoftware.cavedroid.misc.Assets.guiMap;
-import static ru.deadsoftware.cavedroid.misc.Assets.textureRegions;
+import static ru.deadsoftware.cavedroid.misc.Assets.*;
 
 public class GameRenderer extends Renderer {
 
@@ -33,10 +34,11 @@ public class GameRenderer extends Renderer {
     }
 
     private void drawWreck(int bl) {
-        if (GP.blockDmg > 0) {
-            int index = 10 * GP.blockDmg / GameItems.getBlock(bl).getHp();
+        if (GP.input.getBlockDamage() > 0) {
+            int index = 10 * GP.input.getBlockDamage() / GameItems.getBlock(bl).getHp();
             String key = "break_" + index;
-            spriter.draw(textureRegions.get(key), GP.curX * 16 - getCamX(), GP.curY * 16 - getCamY());
+            spriter.draw(textureRegions.get(key), GP.input.getCurX() * 16 - getCamX(),
+                    GP.input.getCurY() * 16 - getCamY());
         }
     }
 
@@ -45,14 +47,14 @@ public class GameRenderer extends Renderer {
             if ((!GP.world.hasForeAt(x, y) || GP.world.getForeMapBlock(x, y).isTransparent())
                     && GP.world.hasBackAt(x, y)) {
                 spriter.draw(GP.world.getBackMapBlock(x, y).getTex(), drawX(x), drawY(y));
-                if (!GP.world.hasForeAt(x, y) && x == GP.curX && y == GP.curY)
-                    drawWreck(GP.world.getBackMap(GP.curX, GP.curY));
+                if (!GP.world.hasForeAt(x, y) && x == GP.input.getCurX() && y == GP.input.getCurY())
+                    drawWreck(GP.world.getBackMap(GP.input.getCurX(), GP.input.getCurY()));
             }
         }
         if (GP.world.hasForeAt(x, y) && GP.world.getForeMapBlock(x, y).isBackground() == drawBG) {
             spriter.draw(GP.world.getForeMapBlock(x, y).getTex(), drawX(x), drawY(y));
-            if (x == GP.curX && y == GP.curY)
-                drawWreck(GP.world.getForeMap(GP.curX, GP.curY));
+            if (x == GP.input.getCurX() && y == GP.input.getCurY())
+                drawWreck(GP.world.getForeMap(GP.input.getCurX(), GP.input.getCurY()));
         }
     }
 
@@ -88,17 +90,9 @@ public class GameRenderer extends Renderer {
     }
 
     private void drawMob(Mob mob) {
-        float mobDrawX = mob.pos.x - getCamX();
-        float mobDrawY = mob.pos.y - getCamY();
-
-        if (mobDrawX + mob.getWidth() - GP.world.getWidthPx() >= 0 && mobDrawX - GP.world.getWidthPx() <= getWidth())
-            mob.draw(spriter, mobDrawX - GP.world.getWidthPx(), mobDrawY);
-
-        if (mobDrawX + mob.getWidth() >= 0 && mobDrawX <= getWidth())
-            mob.draw(spriter, mobDrawX, mobDrawY);
-
-        if (mobDrawX + mob.getWidth() + GP.world.getWidthPx() >= 0 && mobDrawX + GP.world.getWidthPx() <= getWidth())
-            mob.draw(spriter, mobDrawX + GP.world.getWidthPx(), mobDrawY);
+        float mobDrawX = mob.getX() - getCamX();
+        float mobDrawY = mob.getY() - getCamY();
+        mob.draw(spriter, mobDrawX, mobDrawY);
     }
 
     private void drawDrop(Drop drop) {
@@ -111,17 +105,17 @@ public class GameRenderer extends Renderer {
         float y = getHeight() / 2 - (float) creative.getRegionHeight() / 2;
         spriter.draw(creative, x, y);
         spriter.draw(textureRegions.get("handle"), x + 156,
-                y + 18 + (GP.creativeScroll * (72f / GameProc.MAX_CREATIVE_SCROLL)));
-        for (int i = GP.creativeScroll * 8; i < GP.creativeScroll * 8 + 40; i++) {
+                y + 18 + (GP.input.getCreativeScroll() * (72f / GameProc.MAX_CREATIVE_SCROLL)));
+        for (int i = GP.input.getCreativeScroll() * 8; i < GP.input.getCreativeScroll() * 8 + 40; i++) {
             if (i > 0 && i < GameItems.getItemsSize())
                 if (GameItems.getItem(i).isBlock()) {
                     spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(i)).getTex(),
-                            x + 8 + ((i - GP.creativeScroll * 8) % 8) * 18,
-                            y + 18 + ((i - GP.creativeScroll * 8) / 8) * 18);
+                            x + 8 + ((i - GP.input.getCreativeScroll() * 8) % 8) * 18,
+                            y + 18 + ((i - GP.input.getCreativeScroll() * 8) / 8) * 18);
                 } else {
                     spriter.draw(GameItems.getItem(i).getTex(),
-                            x + 8 + ((i - GP.creativeScroll * 8) % 8) * 18,
-                            y + 18 + ((i - GP.creativeScroll * 8) / 8) * 18);
+                            x + 8 + ((i - GP.input.getCreativeScroll() * 8) % 8) * 18,
+                            y + 18 + ((i - GP.input.getCreativeScroll() * 8) / 8) * 18);
                 }
         }
         for (int i = 0; i < 9; i++) {
@@ -142,13 +136,13 @@ public class GameRenderer extends Renderer {
         TextureRegion hotbar = textureRegions.get("hotbar");
         TextureRegion hotbarSelector = textureRegions.get("hotbar_selector");
 
-        if (GP.world.hasForeAt(GP.curX, GP.curY) ||
-                GP.world.hasBackAt(GP.curX, GP.curY) ||
+        if (GP.world.hasForeAt(GP.input.getCurX(), GP.input.getCurY()) ||
+                GP.world.hasBackAt(GP.input.getCurX(), GP.input.getCurY()) ||
                 GP.controlMode == ControlMode.CURSOR ||
                 !CaveGame.TOUCH)
             spriter.draw(cursor,
-                    GP.curX * 16 - getCamX(),
-                    GP.curY * 16 - getCamY());
+                    GP.input.getCurX() * 16 - getCamX(),
+                    GP.input.getCurY() * 16 - getCamY());
         spriter.draw(hotbar, getWidth() / 2 - (float) hotbar.getRegionWidth() / 2, 0);
         for (int i = 0; i < 9; i++) {
             if (GP.player.inventory[i] > 0) {
@@ -170,7 +164,7 @@ public class GameRenderer extends Renderer {
 
     private void drawTouchGui() {
         for (int i = 0; i < guiMap.size; i++) {
-            Rectangle touchKey = guiMap.getValueAt(i);
+            Rectangle touchKey = guiMap.getValueAt(i).getRect();
             spriter.draw(textureRegions.get(guiMap.getKeyAt(i)),
                     touchKey.x, touchKey.y, touchKey.width, touchKey.height);
         }
@@ -181,9 +175,9 @@ public class GameRenderer extends Renderer {
 
     private void drawGamePlay() {
         drawWorld(true);
-        GP.player.draw(spriter, GP.player.pos.x - getCamX() - 2, GP.player.pos.y - getCamY());
-        for (Mob mob : GP.mobs) drawMob(mob);
-        for (Drop drop : GP.drops) drawDrop(drop);
+        GP.player.draw(spriter, GP.player.getX() - getCamX() - 2, GP.player.getY() - getCamY());
+        GP.mobs.forEach(this::drawMob);
+        GP.drops.forEach(this::drawDrop);
         drawWorld(false);
         drawGUI();
     }
@@ -231,7 +225,7 @@ public class GameRenderer extends Renderer {
                 }
             }
             shaper.setColor(Color.OLIVE);
-            shaper.rect(GP.player.pos.x / 16, GP.player.pos.y / 16 - 128, 1, 2);
+            shaper.rect(GP.player.getMapX(), GP.player.getUpperMapY() - 128, 1, 2);
             shaper.end();
             //=================
         }
@@ -239,13 +233,13 @@ public class GameRenderer extends Renderer {
         if (GameScreen.SHOW_DEBUG) {
             spriter.begin();
             drawString("FPS: " + GameScreen.FPS, 0, 0);
-            drawString("X: " + (int) (GP.player.pos.x / 16), 0, 10);
-            drawString("Y: " + (int) (GP.player.pos.y / 16), 0, 20);
-            drawString("CurX: " + GP.curX, 0, 30);
-            drawString("CurY: " + GP.curY, 0, 40);
+            drawString("X: " + GP.player.getMapX(), 0, 10);
+            drawString("Y: " + GP.player.getUpperMapY() / 16, 0, 20);
+            drawString("CurX: " + GP.input.getCurX(), 0, 30);
+            drawString("CurY: " + GP.input.getCurY(), 0, 40);
             drawString("Mobs: " + GP.mobs.size(), 0, 50);
             drawString("Drops: " + GP.drops.size(), 0, 60);
-            drawString("Block: " + GameItems.getBlockKey(GP.world.getForeMap(GP.curX, GP.curY)), 0, 70);
+            drawString("Block: " + GameItems.getBlockKey(GP.world.getForeMap(GP.input.getCurX(), GP.input.getCurY())), 0, 70);
             drawString("Hand: " + GameItems.getItemKey(GP.player.inventory[GP.player.slot]), 0, 80);
             drawString("Game mode: " + GP.player.gameMode, 0, 90);
             spriter.end();