summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8acb72a)
raw | patch | inline | side by side (parent: 8acb72a)
author | fred-boy <fred-boy@protonmail.com> | |
Sun, 9 Sep 2018 11:10:31 +0000 (18:10 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sun, 9 Sep 2018 11:10:31 +0000 (18:10 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java
index d359fe92030420e7baa1abf591848bf946143b4e..dc7bb60c9cb746795b3ce40245dde99c6705252c 100644 (file)
public class GameScreen implements Screen {
public static int FPS;
+ public static boolean SHOW_DEBUG = false;
private GameProc gameProc;
private Renderer renderer;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java
index 9aa90f2b1d335a64d16e1e49ac8bbf3f39366e80..e44e0053376122e474bda26fe04002fbadea1484 100644 (file)
import com.badlogic.gdx.Input;
import com.badlogic.gdx.utils.TimeUtils;
import ru.deadsoftware.cavecraft.CaveGame;
+import ru.deadsoftware.cavecraft.GameScreen;
import ru.deadsoftware.cavecraft.game.mobs.Pig;
import ru.deadsoftware.cavecraft.misc.AppState;
import ru.deadsoftware.cavecraft.misc.Assets;
case Input.Keys.ESCAPE: case Input.Keys.BACK:
CaveGame.STATE = AppState.GOTO_MENU;
break;
+
+ case Input.Keys.F1:
+ GameScreen.SHOW_DEBUG = !GameScreen.SHOW_DEBUG;
+ break;
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index 34c4df111304a96557ee12ec0f767b3e8bfef40f..c335908a26b41ce274c4e72ec58f80e01f553a19 100644 (file)
switch (dir) {
case 0:
bl = gameProc.world.getForeMap((int)((rect.x-8)/16),(int)((rect.y+rect.height-8)/16));
+ if (checkColl(new Rectangle(rect.x-16, rect.y-18, rect.width, rect.height))) bl=0;
break;
case 1:
bl = gameProc.world.getForeMap((int)((rect.x+rect.width+8)/16),(int)((rect.y+rect.height-8)/16));
+ if (checkColl(new Rectangle(rect.x+16, rect.y-18, rect.width, rect.height))) bl=0;
break;
default:
bl=0;
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.canJump) mob.changeDir();
}
}
if (mob.position.x+mob.width/2<0) mob.position.x+=gameProc.world.getWidth()*16;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 38680f94db6ddf347491736c18872f5c80e544b1..b528972d71e342a39227b1a8bb65fb02b132fed1 100644 (file)
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.CaveGame;
+import ru.deadsoftware.cavecraft.GameScreen;
import ru.deadsoftware.cavecraft.game.mobs.Mob;
import ru.deadsoftware.cavecraft.game.objects.Player;
import ru.deadsoftware.cavecraft.misc.Assets;
private void drawGamePlay() {
drawWorldBackground();
- Mob.animateMobs();
+ //Mob.animateMobs();
for (Mob mob : gameProc.mobs) drawMob(mob);
drawPlayer(gameProc.player);
drawWorldForeground();
if (CaveGame.TOUCH) drawTouchGui();
+ if (GameScreen.SHOW_DEBUG) {
+ drawString("FPS: "+GameScreen.FPS,0, 0);
+ drawString("X: "+(int)(gameProc.player.position.x/16),0, 10);
+ drawString("Y: "+(int)(gameProc.player.position.y/16),0, 20);
+ drawString("Mobs: "+gameProc.mobs.size(), 0, 30);
+ }
+
spriteBatch.end();
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java
index 7b773d0928f9b759747c3fa21fd5458dd63a4a7a..0b0f9b3ec5e0fcfc2ab858a6a663208876e7e625 100644 (file)
public abstract class Mob implements Serializable{
- public static int ANIM_SPEED = 6;
- public static int ANIMATION = 0;
+ public int ANIM_SPEED = 6;
public Vector2 position;
public Vector2 moveX, moveY;
- public int width, height, dir;
+ public int width, height, dir, animation;
public boolean canJump;
public boolean agressive;
- 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 changeDir();
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
index aaa301998beeb1130f215f4447486cbcb6e23f33..10c4242429f221641c1e0ec501545b1311127350 100644 (file)
public class Pig extends Mob{
public Pig(int x, int y) {
+ dir = MathUtils.random(1);
position = new Vector2(x, y);
- moveX = new Vector2(0, 0);
+ moveX = new Vector2(-1+dir*2, 0);
moveY = new Vector2(0, 0);
width = 25;
height = 18;
- dir = 0;
canJump = false;
agressive = false;
}
@Override
- public void ai() {
- if (MathUtils.randomBoolean(.0025f)) dir=-dir+1;
+ public void changeDir() {
+ dir=-dir+1;
moveX.set(-1+2*dir,0);
+ if (MathUtils.randomBoolean(.0025f)) {
+ moveX.set(0, 0);
+ }
+ }
+
+ @Override
+ public void ai() {
+ if (MathUtils.randomBoolean(.0025f)) changeDir();
+ if (moveX.x != 0f) animation+=ANIM_SPEED; else animation=0;
+ if (animation>=60 || animation<=-60) {
+ ANIM_SPEED = -ANIM_SPEED;
+ }
}
@Override
public void draw(SpriteBatch spriteBatch, float x, float y) {
+ Assets.pigSprite[0][1].setRotation(animation);
+ Assets.pigSprite[1][1].setRotation(-animation);
//back legs
Assets.pigSprite[1][1].setPosition(x-4+(9-dir*9),y+6);
Assets.pigSprite[1][1].draw(spriteBatch);