From d7666be4252d5f36969059d04c1c895dea6223d3 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Wed, 25 Apr 2018 02:47:58 +0700 Subject: [PATCH] Return pigs --- .../ru/deadsoftware/cavecraft/game/GameProc.java | 5 +++++ .../ru/deadsoftware/cavecraft/game/mobs/Mob.java | 4 +++- .../ru/deadsoftware/cavecraft/game/mobs/Pig.java | 14 +++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 6aef579..29b3d3b 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -2,9 +2,11 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; +import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.TimeUtils; import ru.deadsoftware.cavecraft.*; import ru.deadsoftware.cavecraft.game.mobs.Mob; +import ru.deadsoftware.cavecraft.game.mobs.Pig; import ru.deadsoftware.cavecraft.game.objects.Player; import java.io.Serializable; @@ -36,6 +38,9 @@ public class GameProc implements Serializable{ world.generate(1024,256); player = new Player(world.getSpawnPoint()); mobs = new ArrayList(); + for (int i=0; i<16; i++) { + mobs.add(new Pig(i*256, 128&16, this)); + } physics = new GamePhysics(this); if (!CaveGame.TOUCH) ctrlMode = 1; if (CaveGame.TOUCH) { diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java index c52e78f..61ab375 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java @@ -6,7 +6,9 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import ru.deadsoftware.cavecraft.Assets; -public abstract class Mob { +import java.io.Serializable; + +public abstract class Mob implements Serializable{ public static int ANIM_SPEED = 6; public static int ANIMATION = 0; diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java index 0400be0..7b92238 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -5,14 +5,14 @@ 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; +import ru.deadsoftware.cavecraft.game.GameProc; public class Pig extends Mob{ - private GameWorld world; + private GameProc gameProc; - public Pig(int x, int y, GameWorld world) { - this.world = world; + public Pig(int x, int y, GameProc gameProc) { + this.gameProc = gameProc; position = new Vector2(x, y); moveX = new Vector2(0, 0); moveY = new Vector2(0, 0); @@ -24,9 +24,9 @@ public class Pig extends Mob{ @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) + if (canJump && position.x>16 && position.x<(gameProc.world.getWidth()-1)*16 && + gameProc.world.getForeMap((int)(position.x/16)+(dir*2-1), (int)((position.y+height)/16))>0 && + gameProc.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; -- 2.29.2