From: fred-boy Date: Fri, 20 Apr 2018 15:26:25 +0000 (+0700) Subject: Add pigs X-Git-Tag: alpha0.2~6 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=385255cc7b49fbfd3290497367cbc69919b24d4f;p=cavedroid.git Add pigs --- diff --git a/android/assets/mobs/pig.png b/android/assets/mobs/pig.png new file mode 100644 index 0000000..826d725 Binary files /dev/null and b/android/assets/mobs/pig.png differ diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java index 7dedb4b..acdebdf 100644 --- a/core/src/ru/deadsoftware/cavecraft/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/Assets.java @@ -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"))); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 8e12e72..3bcbc9b 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -131,7 +131,6 @@ public class GamePhysics { } public void update(float delta) { - for (Mob mob : gameProc.mobs) { mob.ai(); mobPhy(mob); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 47b3100..7ded79f 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -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(); + for (int i=0; i<1024/64; i++) { + mobs.add(new Pig(i*16*64, 0, world)); + } if (!CaveGame.TOUCH) ctrlMode = 1; } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 7eed8a7..d104b2f 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -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(); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java index e0ff0e2..c52e78f 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java @@ -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 index 0000000..0400be0 --- /dev/null +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -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); + } +} diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index 92c8171..415ed3d 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -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;