summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e37c627)
raw | patch | inline | side by side (parent: e37c627)
author | fred-boy <fred-boy@protonmail.com> | |
Wed, 25 Apr 2018 09:07:49 +0000 (16:07 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Wed, 25 Apr 2018 13:06:58 +0000 (20:06 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java
index bded5818b071d57a703cba3a9dc7a4af1fec2bba..c0fc292329e7af3909ed7ea52a9d9c5d38ce1854 100644 (file)
import com.badlogic.gdx.Input;
import com.badlogic.gdx.utils.TimeUtils;
+import ru.deadsoftware.cavecraft.game.mobs.Pig;
import ru.deadsoftware.cavecraft.misc.AppState;
import ru.deadsoftware.cavecraft.misc.Assets;
import ru.deadsoftware.cavecraft.CaveGame;
else CaveGame.STATE = AppState.GAME_PLAY;
break;
+ case Input.Keys.G:
+ gameProc.mobs.add(new Pig(gameProc.cursorX*16, gameProc.cursorY*16));
+ break;
+
case Input.Keys.ESCAPE: case Input.Keys.BACK:
CaveGame.STATE = AppState.GOTO_MENU;
break;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index 5677c2426fa5f8e1ef47e959870ae8dfb0038e38..34c4df111304a96557ee12ec0f767b3e8bfef40f 100644 (file)
}
private boolean checkJump(Rectangle rect, int dir) {
- int bl = 0;
+ int bl;
switch (dir) {
case 0:
- bl = gameProc.world.getForeMap(
- (int)((rect.x+(rect.width/2))/16) - 1,
- (int)(rect.y/16)+1);
- if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)-1,(int)(rect.y/16))>0) bl=0;
- if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)-1,(int)(rect.y/16)-1)>0) bl=0;
+ bl = gameProc.world.getForeMap((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16));
break;
case 1:
- bl = gameProc.world.getForeMap(
- (int)((rect.x+(rect.width/2))/16) + 1,
- (int)(rect.y/16)+1);
- if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)+1,(int)(rect.y/16))>0) bl=0;
- if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)+1,(int)(rect.y/16)-1)>0) bl=0;
+ bl = gameProc.world.getForeMap((int)((rect.x+rect.width+8)/16),(int)((rect.y+rect.height-8)/16));
break;
default:
bl=0;
pl.position.add(pl.moveY);
if (checkColl(pl.getRect())) {
int d = -1;
- if (pl.moveY.y<0) d=1; else if (pl.moveY.y>0) d=-1;
+ if (pl.moveY.y<0) d=1;
if (d==-1) {
pl.flyMode = false;
pl.canJump = true;
private void mobPhy(Mob mob) {
mob.position.add(mob.moveY);
if (checkColl(mob.getRect())) {
- mob.canJump = true;
int d = -1;
- if (mob.moveY.y<0) d=1; else if (mob.moveY.y>0) d=-1;
+ if (mob.moveY.y<0) d=1;
+ if (d==-1) mob.canJump = true;
mob.position.y = MathUtils.round(mob.position.y);
while (checkColl(mob.getRect())) mob.position.y+=d;
mob.moveY.setZero();
} else {
mob.canJump = false;
}
- mob.moveY.add(gravity);
+ if (mob.moveY.y<18) mob.moveY.add(gravity);
mob.position.add(mob.moveX);
+ if (checkColl(mob.getRect())) {
+ if (mob.canJump) {
+ mob.position.y-=8;
+ }
+ if (checkColl(mob.getRect())) {
+ if (mob.canJump) mob.position.y+=8;
+ int d = 0;
+ if (mob.moveX.x < 0) d = 1;
+ else if (mob.moveX.x > 0) d = -1;
+ mob.position.x = MathUtils.round(mob.position.x);
+ while (checkColl(mob.getRect())) mob.position.x += d;
+ }
+ }
if (mob.position.x+mob.width/2<0) mob.position.x+=gameProc.world.getWidth()*16;
if (mob.position.x+mob.width/2>gameProc.world.getWidth()*16) mob.position.x-=gameProc.world.getWidth()*16;
- if (checkColl(mob.getRect())) {
- int d = 0;
- if (mob.moveX.x<0) d=1; else if (mob.moveX.x>0) d=-1;
- mob.position.x = MathUtils.round(mob.position.x);
- while (checkColl(mob.getRect())) mob.position.x+=d;
+ if (mob.position.y > gameProc.world.getHeight()*16) {
+ mob.position.y = 0;
+ }
+ if (checkJump(mob.getRect(), mob.dir) && mob.canJump && !mob.moveX.equals(Vector2.Zero)) {
+ mob.moveY.add(0, -8);
+ mob.canJump = false;
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java
index ccf5e2bb6546981c52e141820f80d408c3ec0dc6..ce88856ca4d4c086c93a92464e5b5525ab7eb323 100644 (file)
player = new Player(world.getSpawnPoint());
mobs = new ArrayList<Mob>();
for (int i=0; i<16; i++) {
- mobs.add(new Pig(i*256, 128&16, this));
+ mobs.add(new Pig(i*256, 196*16));
}
physics = new GamePhysics(this);
if (!CaveGame.TOUCH) ctrlMode = 1;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java
index cfa932a84822a6f87a2bb7269ca3e25ef23fc5a3..7b773d0928f9b759747c3fa21fd5458dd63a4a7a 100644 (file)
public Vector2 moveX, moveY;
public int width, height, dir;
public boolean canJump;
+ public boolean agressive;
public static void animateMobs() {
Assets.pigSprite[0][1].setRotation(ANIMATION);
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java
index 879b66760cc082b0c0ee751f651da49092a22931..aaa301998beeb1130f215f4447486cbcb6e23f33 100644 (file)
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.game.GameWorld;
import ru.deadsoftware.cavecraft.misc.Assets;
import ru.deadsoftware.cavecraft.game.GameProc;
public class Pig extends Mob{
- private GameProc gameProc;
-
- public Pig(int x, int y, GameProc gameProc) {
- this.gameProc = gameProc;
+ public Pig(int x, int y) {
position = new Vector2(x, y);
moveX = new Vector2(0, 0);
moveY = new Vector2(0, 0);
height = 18;
dir = 0;
canJump = false;
+ agressive = false;
}
@Override
public void ai() {
- 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;
- moveX.set(-1.5f+3*dir,0);
+ if (MathUtils.randomBoolean(.0025f)) dir=-dir+1;
+ moveX.set(-1+2*dir,0);
}
@Override