DEADSOFTWARE

Add pigs
authorfred-boy <fred-boy@protonmail.com>
Fri, 20 Apr 2018 15:26:25 +0000 (22:26 +0700)
committerfred-boy <fred-boy@protonmail.com>
Fri, 20 Apr 2018 15:26:25 +0000 (22:26 +0700)
android/assets/mobs/pig.png [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/Assets.java
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java
core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/game/objects/Player.java

diff --git a/android/assets/mobs/pig.png b/android/assets/mobs/pig.png
new file mode 100644 (file)
index 0000000..826d725
Binary files /dev/null and b/android/assets/mobs/pig.png differ
index 7dedb4b3fce4ca1c4f72193d411e4d8e7be14c50..acdebdffafdba033f4d3f887fcf8f8ec62a9a097 100644 (file)
@@ -13,7 +13,10 @@ public class Assets {
     public static BitmapFont minecraftFont;
 
     public static Texture charTexture;
-    public static Sprite[][] playerSkin = new Sprite[2][4];
+    public static Sprite[][] playerSprite = new Sprite[2][4];
+
+    public static Texture pigTexture;
+    public static Sprite[][] pigSprite = new Sprite[2][2];
 
     public static Sprite shade;
 
@@ -35,36 +38,53 @@ public class Assets {
     public static TextureRegion touchToggleMode;
     public static TextureRegion touchSpace;
 
-    public static void load() {
-        minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
+    private static void loadPlayer() {
         charTexture = new Texture(Gdx.files.internal("mobs/char.png"));
         //LOOK TO LEFT
         //head
-        playerSkin[0][0] = new Sprite(new TextureRegion(charTexture, 0,0,12,12));
-        playerSkin[0][0].flip(false,true);
+        playerSprite[0][0] = new Sprite(new TextureRegion(charTexture, 0,0,12,12));
+        playerSprite[0][0].flip(false,true);
         //body
-        playerSkin[0][1] = new Sprite(new TextureRegion(charTexture, 0,13,12,12));
-        playerSkin[0][1].flip(false,true);
+        playerSprite[0][1] = new Sprite(new TextureRegion(charTexture, 0,13,12,12));
+        playerSprite[0][1].flip(false,true);
         //hand
-        playerSkin[0][2] = new Sprite(new TextureRegion(charTexture, 25,5,20,20));
-        playerSkin[0][2].flip(false,true);
+        playerSprite[0][2] = new Sprite(new TextureRegion(charTexture, 25,5,20,20));
+        playerSprite[0][2].flip(false,true);
         //leg
-        playerSkin[0][3] = new Sprite(new TextureRegion(charTexture, 25,27,20,20));
-        playerSkin[0][3].flip(false,true);
+        playerSprite[0][3] = new Sprite(new TextureRegion(charTexture, 25,27,20,20));
+        playerSprite[0][3].flip(false,true);
         //LOOK TO RIGHT
         //head
-        playerSkin[1][0] = new Sprite(new TextureRegion(charTexture, 13,0,12,12));
-        playerSkin[1][0].flip(false,true);
+        playerSprite[1][0] = new Sprite(new TextureRegion(charTexture, 13,0,12,12));
+        playerSprite[1][0].flip(false,true);
         //body
-        playerSkin[1][1] = new Sprite(new TextureRegion(charTexture, 13,13,12,12));
-        playerSkin[1][1].flip(false,true);
+        playerSprite[1][1] = new Sprite(new TextureRegion(charTexture, 13,13,12,12));
+        playerSprite[1][1].flip(false,true);
         //hand
-        playerSkin[1][2] = new Sprite(new TextureRegion(charTexture, 37,5,20,20));
-        playerSkin[1][2].flip(false,true);
+        playerSprite[1][2] = new Sprite(new TextureRegion(charTexture, 37,5,20,20));
+        playerSprite[1][2].flip(false,true);
         //leg
-        playerSkin[1][3] = new Sprite(new TextureRegion(charTexture, 37,27,20,20));
-        playerSkin[1][3].flip(false,true);
+        playerSprite[1][3] = new Sprite(new TextureRegion(charTexture, 37,27,20,20));
+        playerSprite[1][3].flip(false,true);
+    }
+
+    private static void loadPig() {
+        pigTexture = new Texture(Gdx.files.internal("mobs/pig.png"));
+        pigSprite[0][0] = new Sprite(new TextureRegion(pigTexture, 0, 0, 25, 12));
+        pigSprite[0][0].flip(false,true);
+        pigSprite[1][0] = new Sprite(new TextureRegion(pigTexture, 0, 12, 25, 12));
+        pigSprite[1][0].flip(false,true);
+        pigSprite[0][1] = new Sprite(new TextureRegion(pigTexture, 4, 26, 12, 12));
+        pigSprite[0][1].flip(false,true);
+        pigSprite[1][1] = new Sprite(new TextureRegion(pigTexture, 16, 26, 12, 12));
+        pigSprite[1][1].flip(false,true);
+    }
+
+    public static void load() {
+        minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
 
+        loadPlayer();
+        loadPig();
 
         shade = new Sprite(new Texture(Gdx.files.internal("shade.png")));
 
index 8e12e7292a3dca7bd37a790a97f27aba9e264576..3bcbc9b2bcf0b4b163c2a81a9d768c9e9cf2c99b 100644 (file)
@@ -131,7 +131,6 @@ public class GamePhysics {
 }
 
     public void update(float delta) {
-
         for (Mob mob : gameProc.mobs) {
             mob.ai();
             mobPhy(mob);
index 47b3100aa9164e3f5d4cd22060d46deebc0331b1..7ded79faf697495940d013d2092fb44857ad2dde 100644 (file)
@@ -6,8 +6,8 @@ import com.badlogic.gdx.math.RandomXS128;
 import com.badlogic.gdx.utils.Array;
 import com.badlogic.gdx.utils.TimeUtils;
 import ru.deadsoftware.cavecraft.*;
-import ru.deadsoftware.cavecraft.game.mobs.Human;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
+import ru.deadsoftware.cavecraft.game.mobs.Pig;
 import ru.deadsoftware.cavecraft.game.objects.Player;
 
 public class GameProc {
@@ -37,6 +37,9 @@ public class GameProc {
         physics = new GamePhysics(this);
         player = new Player(world.getSpawnPoint());
         mobs = new Array<Mob>();
+        for (int i=0; i<1024/64; i++) {
+            mobs.add(new Pig(i*16*64, 0, world));
+        }
         if (!CaveGame.TOUCH) ctrlMode = 1;
     }
 
index 7eed8a7d85884890c8cbc87eb8b11ebd90646707..d104b2f2056a873d781118decc40d4b0867be7d6 100644 (file)
@@ -6,7 +6,6 @@ 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;
@@ -108,47 +107,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() {
@@ -199,6 +198,7 @@ public class GameRenderer {
 
     private void drawGamePlay() {
         drawWorld();
+        Mob.animateMobs();
         for (Mob mob : gameProc.mobs) drawMob(mob);
         drawPlayer(gameProc.player);
         drawWorldForeground();
@@ -239,6 +239,7 @@ public class GameRenderer {
         drawString("X: "+(int)(gameProc.player.position.x/16), 0, 40);
         drawString("Y: "+(int)(gameProc.player.position.y/16), 0, 60);
         drawString("Seed: "+WorldGen.getSeed(), 0, 80);
+        drawString("Mobs: "+gameProc.mobs.size, 0, 100);
         fontBatch.end();
     }
 
index e0ff0e2afc125d7be02029661ff242068197e669..c52e78ff47dac0b895b4586182375464027d0f72 100644 (file)
@@ -3,16 +3,27 @@ package ru.deadsoftware.cavecraft.game.mobs;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.utils.Array;
+import ru.deadsoftware.cavecraft.Assets;
 
 public abstract class Mob {
 
     public static int ANIM_SPEED = 6;
-
+    public static int ANIMATION = 0;
     public Vector2 position;
     public Vector2 moveX, moveY;
-    public int width, height, dir, animation, anim_d;
+    public int width, height, dir;
     public boolean canJump;
 
+    public static void animateMobs() {
+        Assets.pigSprite[0][1].setRotation(ANIMATION);
+        Assets.pigSprite[1][1].setRotation(-ANIMATION);
+        ANIMATION+=ANIM_SPEED;
+        if (ANIMATION>=60 || ANIMATION<=-60) {
+            ANIM_SPEED = -ANIM_SPEED;
+        }
+    }
+
     public abstract void ai();
     public abstract void draw(SpriteBatch spriteBatch, float x, float y);
     public abstract Rectangle getRect();
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java
new file mode 100644 (file)
index 0000000..0400be0
--- /dev/null
@@ -0,0 +1,56 @@
+package ru.deadsoftware.cavecraft.game.mobs;
+
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.math.MathUtils;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.Assets;
+import ru.deadsoftware.cavecraft.game.GameWorld;
+
+public class Pig extends Mob{
+
+    private GameWorld world;
+
+    public Pig(int x, int y, GameWorld world) {
+        this.world = world;
+        position = new Vector2(x, y);
+        moveX = new Vector2(0, 0);
+        moveY = new Vector2(0, 0);
+        width = 25;
+        height = 18;
+        dir = 0;
+        canJump = false;
+    }
+
+    @Override
+    public void ai() {
+        if (canJump && position.x>16 && position.x<(world.getWidth()-1)*16 &&
+                world.getForeMap((int)(position.x/16)+(dir*2-1), (int)((position.y+height)/16))>0 &&
+                world.getForeMap((int)(position.x/16)+(dir*2-1), (int)((position.y)/16))==0)
+            moveY.add(0, -8);
+        if (MathUtils.randomBoolean(.0001f)) dir++;
+        if (dir>1) dir = 0;
+        moveX.set(-1.5f+3*dir,0);
+    }
+
+    @Override
+    public void draw(SpriteBatch spriteBatch, float x, float y) {
+        //back legs
+        Assets.pigSprite[1][1].setPosition(x-4+(9-dir*9),y+6);
+        Assets.pigSprite[1][1].draw(spriteBatch);
+        Assets.pigSprite[1][1].setPosition(x+17-(9*dir),y+6);
+        Assets.pigSprite[1][1].draw(spriteBatch);
+        //front legs
+        Assets.pigSprite[0][1].setPosition(x-4+(9-dir*9),y+6);
+        Assets.pigSprite[0][1].draw(spriteBatch);
+        Assets.pigSprite[0][1].setPosition(x+17-(9*dir),y+6);
+        Assets.pigSprite[0][1].draw(spriteBatch);
+        //head & body
+        spriteBatch.draw(Assets.pigSprite[dir][0], x, y);
+    }
+
+    @Override
+    public Rectangle getRect() {
+        return new Rectangle(position.x, position.y, width, height);
+    }
+}
index 92c81716c3b13c1007e2b3758ae342f5aa3fb82d..415ed3d5d46cbef214ac6a847583b71fc15a33e6 100644 (file)
@@ -8,6 +8,8 @@ import ru.deadsoftware.cavecraft.game.WorldGen;
 
 public class Player {
 
+    public static int ANIM_SPEED = 6;
+
     public Vector2 position;
     public Vector2 moveX, moveY;
     public int width, height, dir, texWidth;