summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f894e0e)
raw | patch | inline | side by side (parent: f894e0e)
author | fred-boy <fredboy@protonmail.com> | |
Sat, 21 Dec 2019 12:14:18 +0000 (19:14 +0700) | ||
committer | fred-boy <fredboy@protonmail.com> | |
Sat, 21 Dec 2019 12:14:18 +0000 (19:14 +0700) |
diff --git a/android/build.gradle b/android/build.gradle
index b8cfebe5ba54a0ea8532283c7840a3909f91543c..a5ed087df1b3458384d90a0ddf8b1bccd50ba73f 100644 (file)
--- a/android/build.gradle
+++ b/android/build.gradle
}
defaultConfig {
applicationId "ru.deadsoftware.cavedroid"
- minSdkVersion 14
+ minSdkVersion 24
targetSdkVersion 29
versionCode 10
versionName "alpha0.4"
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java
index 58d377885204430900497a5a5a5daf845e64b186..2fc38b7cb7bda064dd0935448d14bc027ac5404d 100644 (file)
private void goUpwards() {
if (checkSwim()) {
GP.player.swim = true;
- } else if (GP.player.canJump) {
- GP.player.mov.add(0, -7);
- } else if (!GP.player.flyMode && GP.player.gameMode == 1) {
- GP.player.flyMode = true;
- GP.player.mov.y = 0;
- } else if (GP.player.flyMode) {
- GP.player.mov.y = -GamePhysics.PL_SPEED;
+ } else if (GP.player.canJump()) {
+ GP.player.getMov().add(0, -7);
+ } else if (!GP.player.isFlyMode() && GP.player.gameMode == 1) {
+ GP.player.setFlyMode(true);
+ GP.player.getMov().y = 0;
+ } else if (GP.player.isFlyMode()) {
+ GP.player.getMov().y = -GamePhysics.PL_SPEED;
}
}
if (GP.controlMode == ControlMode.WALK || !CaveGame.TOUCH) {
switch (keycode) {
case Input.Keys.A:
- GP.player.mov.x = -GamePhysics.PL_SPEED;
+ GP.player.getMov().x = -GamePhysics.PL_SPEED;
GP.player.setDir(Mob.LEFT);
if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true;
break;
case Input.Keys.D:
- GP.player.mov.x = GamePhysics.PL_SPEED;
+ GP.player.getMov().x = GamePhysics.PL_SPEED;
GP.player.setDir(Mob.RIGHT);
if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true;
break;
break;
case Input.Keys.S:
case Input.Keys.CONTROL_LEFT:
- GP.player.mov.y = GamePhysics.PL_SPEED;
+ GP.player.getMov().y = GamePhysics.PL_SPEED;
break;
}
} else {
}
if (GP.controlMode == ControlMode.CURSOR) {
- if (curX * 16 + 8 < GP.player.pos.x + GP.player.getWidth() / 2) {
+ if (curX * 16 + 8 < GP.player.getX() + GP.player.getWidth() / 2) {
GP.player.setDir(Mob.LEFT);
} else {
GP.player.setDir(Mob.RIGHT);
switch (keycode) {
case Input.Keys.A:
case Input.Keys.D:
- GP.player.mov.x = 0;
+ GP.player.getMov().x = 0;
if (CaveGame.TOUCH && GP.player.swim) GP.player.swim = false;
break;
case Input.Keys.S:
case Input.Keys.SPACE:
case Input.Keys.CONTROL_LEFT:
- if (GP.player.flyMode) GP.player.mov.y = 0;
+ if (GP.player.isFlyMode()) GP.player.getMov().y = 0;
if (GP.player.swim) GP.player.swim = false;
break;
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index 7e12e53d375160d5285427b7985116c174190f5d..2d2e4a444563ebdf6997948021164484722e2766 100644 (file)
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
import ru.deadsoftware.cavedroid.game.objects.Drop;
-import ru.deadsoftware.cavedroid.game.objects.Player;
+import ru.deadsoftware.cavedroid.game.mobs.Player;
import java.util.Iterator;
static final int PL_SPEED = 2;
- private final Vector2 gravity = new Vector2(0, .9f);
+ private final Vector2 gravity = new Vector2(0, .9f);
private boolean checkJump(Rectangle rect, int dir) {
int bl;
private void mobXColl(Mob mob) {
if (checkColl(mob.getRect())) {
- if (mob.canJump && !mob.flyMode) {
- mob.pos.y -= 8;
+ if (mob.canJump() && !mob.isFlyMode()) {
+ mob.getPos().y -= 8;
}
if (checkColl(mob.getRect())) {
- if (mob.canJump && !mob.flyMode) mob.pos.y += 8;
+ if (mob.canJump() && !mob.isFlyMode()) mob.getPos().y += 8;
int d = 0;
- if (mob.mov.x < 0) d = 1;
- else if (mob.mov.x > 0) d = -1;
- mob.pos.x = MathUtils.round(mob.pos.x);
- while (checkColl(mob.getRect())) mob.pos.x += d;
- if (mob.canJump) mob.changeDir();
+ if (mob.getMov().x < 0) d = 1;
+ else if (mob.getMov().x > 0) d = -1;
+ mob.getPos().x = MathUtils.round(mob.getX());
+ while (checkColl(mob.getRect())) mob.getPos().x += d;
+ if (mob.canJump()) mob.changeDir();
}
}
- if (mob.pos.x + mob.getWidth() / 2 < 0) mob.pos.x += GP.world.getWidthPx();
- if (mob.pos.x + mob.getWidth() / 2 > GP.world.getWidthPx()) mob.pos.x -= GP.world.getWidthPx();
+ if (mob.getX() + mob.getWidth() / 2 < 0) mob.getPos().x += GP.world.getWidthPx();
+ if (mob.getX() + mob.getWidth() / 2 > GP.world.getWidthPx()) mob.getPos().x -= GP.world.getWidthPx();
}
private void mobYColl(Mob mob) {
if (checkColl(mob.getRect())) {
int d = -1;
- if (mob.mov.y < 0) d = 1;
+ if (mob.getMov().y < 0) d = 1;
if (d == -1) {
- mob.canJump = true;
- mob.flyMode = false;
+ mob.setCanJump(true);
+ mob.setFlyMode(false);
}
- mob.pos.y = MathUtils.round(mob.pos.y);
- while (checkColl(mob.getRect())) mob.pos.y += d;
- mob.mov.y = 0;
+ mob.getPos().y = MathUtils.round(mob.getY());
+ while (checkColl(mob.getRect())) mob.getPos().y += d;
+ mob.getMov().y = 0;
if (mob.getType() > 0) {
GP.world.setForeMap(mob.getMapX(), mob.getMiddleMapY(), mob.getType());
mob.kill();
}
} else {
- mob.canJump = false;
+ mob.setCanJump(false);
}
- if (mob.pos.y > GP.world.getHeightPx()) {
+ if (mob.getY() > GP.world.getHeightPx()) {
mob.kill();
}
}
private void playerPhy(Player pl) {
- pl.pos.y += pl.mov.y;
+ pl.getPos().y += pl.getMov().y;
mobYColl(pl);
if (pl.isDead()) return;
if (GameItems.isFluid(getBlock(pl.getRect()))) {
- if (CaveGame.TOUCH && pl.mov.x != 0 && !pl.swim && !pl.flyMode) pl.swim = true;
+ if (CaveGame.TOUCH && pl.getMov().x != 0 && !pl.swim && !pl.isFlyMode()) pl.swim = true;
if (!pl.swim) {
- if (!pl.flyMode && pl.mov.y < 4.5f) pl.mov.add(gravity.x / 4, gravity.y / 4);
- if (!pl.flyMode && pl.mov.y > 4.5f) pl.mov.add(0, -1f);
+ if (!pl.isFlyMode() && pl.getMov().y < 4.5f) pl.getMov().add(gravity.x / 4, gravity.y / 4);
+ if (!pl.isFlyMode() && pl.getMov().y > 4.5f) pl.getMov().add(0, -1f);
} else {
- pl.mov.add(0, -.5f);
- if (pl.mov.y < -3) pl.mov.y = -3;
+ pl.getMov().add(0, -.5f);
+ if (pl.getMov().y < -3) pl.getMov().y = -3;
}
} else {
- if (!pl.flyMode && pl.mov.y < 18) pl.mov.add(gravity);
+ if (!pl.isFlyMode() && pl.getMov().y < 18) pl.getMov().add(gravity);
}
- pl.pos.x += pl.mov.x * (pl.flyMode ? 1.5f : 1) * (GameItems.isFluid(getBlock(pl.getRect())) && !pl.flyMode ? .8f : 1);
+ pl.getPos().x += pl.getMov().x * (pl.isFlyMode() ? 1.5f : 1) * (GameItems.isFluid(getBlock(pl.getRect())) && !pl.isFlyMode() ? .8f : 1);
mobXColl(pl);
- if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.getDirection()) && !pl.flyMode && pl.canJump && pl.mov.x != 0) {
- pl.mov.add(0, -8);
- pl.canJump = false;
+ if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.getDirection()) && !pl.isFlyMode() && pl.canJump() && pl.getMov().x != 0) {
+ pl.getMov().add(0, -8);
+ pl.setCanJump(false);
}
}
private void mobPhy(Mob mob) {
- mob.pos.y += mob.mov.y;
+ mob.getPos().y += mob.getMov().y;
mobYColl(mob);
if (mob.isDead()) return;
if (mob.getType() == 0 && GameItems.isFluid(getBlock(mob.getRect()))) {
- if (mob.mov.y > 9) mob.mov.add(0, -.9f);
- mob.mov.add(0, -.5f);
- if (mob.mov.y < -3) mob.mov.y = -3;
- } else if (!mob.flyMode && mob.mov.y < 18) mob.mov.add(gravity);
+ if (mob.getMov().y > 9) mob.getMov().add(0, -.9f);
+ mob.getMov().add(0, -.5f);
+ if (mob.getMov().y < -3) mob.getMov().y = -3;
+ } else if (!mob.isFlyMode() && mob.getMov().y < 18) mob.getMov().add(gravity);
- mob.pos.x += mob.mov.x;
+ mob.getPos().x += mob.getMov().x;
mobXColl(mob);
- if (checkJump(mob.getRect(), mob.getDirection()) && mob.canJump && mob.mov.x != 0) {
- mob.mov.add(0, -8);
- mob.canJump = false;
+ if (checkJump(mob.getRect(), mob.getDirection()) && mob.canJump() && mob.getMov().x != 0) {
+ mob.getMov().add(0, -8);
+ mob.setCanJump(false);
}
}
if (GP.player.isDead()) GP.player.respawn();
GP.renderer.setCamPos(
- GP.player.pos.x + GP.player.getWidth() / 2 - GP.renderer.getWidth() / 2,
- GP.player.pos.y + GP.player.getHeight() / 2 - GP.renderer.getHeight() / 2);
+ GP.player.getPos().x + GP.player.getWidth() / 2 - GP.renderer.getWidth() / 2,
+ GP.player.getPos().y + GP.player.getHeight() / 2 - GP.renderer.getHeight() / 2);
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java
index 245f0dc5d1d322728e6bf1810ea6986a561916ff..346d9c1ea1c82c1451803e69bbc574271e826b35 100644 (file)
import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
import ru.deadsoftware.cavedroid.game.objects.Drop;
-import ru.deadsoftware.cavedroid.game.objects.Player;
+import ru.deadsoftware.cavedroid.game.mobs.Player;
import ru.deadsoftware.cavedroid.misc.ControlMode;
import java.io.Serializable;
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
index 1f1858989ac0284644b0e725d2d3f433c4bf36fd..e6ead52d5c2f25a8aee5572740c07d95646d09da 100644 (file)
import ru.deadsoftware.cavedroid.CaveGame;
import ru.deadsoftware.cavedroid.GameScreen;
import ru.deadsoftware.cavedroid.game.mobs.Mob;
+import ru.deadsoftware.cavedroid.game.mobs.Pig;
import ru.deadsoftware.cavedroid.game.objects.Drop;
+import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.misc.ControlMode;
import ru.deadsoftware.cavedroid.misc.Renderer;
import static ru.deadsoftware.cavedroid.GameScreen.GP;
-import static ru.deadsoftware.cavedroid.misc.Assets.guiMap;
-import static ru.deadsoftware.cavedroid.misc.Assets.textureRegions;
+import static ru.deadsoftware.cavedroid.misc.Assets.*;
public class GameRenderer extends Renderer {
if (GP.input.getBlockDamage() > 0) {
int index = 10 * GP.input.getBlockDamage() / GameItems.getBlock(bl).getHp();
String key = "break_" + index;
- spriter.draw(textureRegions.get(key), GP.input.getCurX() * 16 - getCamX(), GP.input.getCurY() * 16 - getCamY());
+ spriter.draw(textureRegions.get(key), GP.input.getCurX() * 16 - getCamX(),
+ GP.input.getCurY() * 16 - getCamY());
}
}
}
private void drawMob(Mob mob) {
- float mobDrawX = mob.pos.x - getCamX();
- float mobDrawY = mob.pos.y - getCamY();
-
- if (mobDrawX + mob.getWidth() - GP.world.getWidthPx() >= 0 && mobDrawX - GP.world.getWidthPx() <= getWidth())
- mob.draw(spriter, mobDrawX - GP.world.getWidthPx(), mobDrawY);
-
- if (mobDrawX + mob.getWidth() >= 0 && mobDrawX <= getWidth())
- mob.draw(spriter, mobDrawX, mobDrawY);
-
- if (mobDrawX + mob.getWidth() + GP.world.getWidthPx() >= 0 && mobDrawX + GP.world.getWidthPx() <= getWidth())
- mob.draw(spriter, mobDrawX + GP.world.getWidthPx(), mobDrawY);
+ float mobDrawX = mob.getX() - getCamX();
+ float mobDrawY = mob.getY() - getCamY();
+ mob.draw(spriter, mobDrawX, mobDrawY);
}
private void drawDrop(Drop drop) {
private void drawGamePlay() {
drawWorld(true);
- GP.player.draw(spriter, GP.player.pos.x - getCamX() - 2, GP.player.pos.y - getCamY());
- for (Mob mob : GP.mobs) drawMob(mob);
- for (Drop drop : GP.drops) drawDrop(drop);
+ GP.player.draw(spriter, GP.player.getX() - getCamX() - 2, GP.player.getY() - getCamY());
+ GP.mobs.forEach(this::drawMob);
+ GP.drops.forEach(this::drawDrop);
drawWorld(false);
drawGUI();
}
}
}
shaper.setColor(Color.OLIVE);
- shaper.rect(GP.player.pos.x / 16, GP.player.pos.y / 16 - 128, 1, 2);
+ shaper.rect(GP.player.getMapX(), GP.player.getUpperMapY() - 128, 1, 2);
shaper.end();
//=================
}
if (GameScreen.SHOW_DEBUG) {
spriter.begin();
drawString("FPS: " + GameScreen.FPS, 0, 0);
- drawString("X: " + (int) (GP.player.pos.x / 16), 0, 10);
- drawString("Y: " + (int) (GP.player.pos.y / 16), 0, 20);
+ drawString("X: " + GP.player.getMapX(), 0, 10);
+ drawString("Y: " + GP.player.getUpperMapY() / 16, 0, 20);
drawString("CurX: " + GP.input.getCurX(), 0, 30);
drawString("CurY: " + GP.input.getCurY(), 0, 40);
drawString("Mobs: " + GP.mobs.size(), 0, 50);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
index 7b23d4d619b785177c7bbbe2c25453aaadd7d022..850f8dd073823f4678d05eb61850765050b9185d 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
+import org.jetbrains.annotations.NotNull;
import ru.deadsoftware.cavedroid.misc.Assets;
/**
}
@Override
- public void draw(SpriteBatch spriteBatch, float x, float y) {
+ public void draw(@NotNull SpriteBatch spriteBatch, float x, float y) {
spriteBatch.draw(Assets.gravelSprite, x, y);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
index ac20ffb9bd82574ffbc4692b661c550f05fa81f8..d193dcfa52d5c4569d21d4816ea35c2d5d72bfe0 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
+import org.jetbrains.annotations.NotNull;
import ru.deadsoftware.cavedroid.misc.Assets;
/**
}
@Override
- public void draw(SpriteBatch spriteBatch, float x, float y) {
+ public void draw(@NotNull SpriteBatch spriteBatch, float x, float y) {
spriteBatch.draw(Assets.sandSprite, x, y);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index 32c63cc26514d674c777f6f5a777104c68508fe4..716c3df07f44dc8e45b06c048716fc721fedeb52 100644 (file)
package ru.deadsoftware.cavedroid.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;
private final float height;
private int dir;
- public boolean flyMode;
- public final Vector2 pos;
- public Vector2 mov;
+ protected final Vector2 pos;
+ protected Vector2 mov;
private boolean dead;
+ private boolean canJump, flyMode;
protected int animDelta = 6;
- public boolean canJump;
- int anim;
+ protected int anim;
+
+ protected static int randomDir() {
+ return MathUtils.random(1);
+ }
/**
*
this.width = width;
this.height = height;
canJump = false;
- flyMode = false;
dead = false;
this.dir = dir;
}
return dead;
}
+ public int getAnim() {
+ return anim;
+ }
+
/**
* Set's mob's dead variable to true and nothing else. It doesn't delete the mob.
*/
return new Rectangle(pos.x, pos.y, getWidth(), getHeight());
}
- public abstract void ai();
+ public Vector2 getPos() {
+ return pos;
+ }
- public abstract void changeDir();
+ public Vector2 getMov() {
+ return mov;
+ }
+
+ public float getX() {
+ return pos.x;
+ }
+
+ public float getY() {
+ return pos.y;
+ }
+
+ public boolean canJump() {
+ return canJump;
+ }
+
+ public void setCanJump(boolean canJump) {
+ this.canJump = canJump;
+ }
+
+ public boolean isFlyMode() {
+ return flyMode;
+ }
+
+ public void setFlyMode(boolean flyMode) {
+ this.flyMode = flyMode;
+ }
public abstract void draw(SpriteBatch spriteBatch, float x, float y);
+ public abstract void ai();
+
+ public abstract void changeDir();
+
/**
*
* @return 0 - if regular mob. <br>
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java
index e36da71cdb37d855235287fe8c00a9ac6a4799d7..ecc93978ff0bf6e0db87bf0beeec4d526c0bbbac 100644 (file)
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavedroid.misc.Assets;
+import static ru.deadsoftware.cavedroid.GameScreen.GP;
+import static ru.deadsoftware.cavedroid.misc.Assets.pigSprite;
+
public class Pig extends Mob {
public Pig(float x, float y) {
- super(x, y, 25, 18, MathUtils.random(1));
+ super(x, y, 25, 18, Mob.randomDir());
mov = new Vector2(looksLeft() ? -1 : 1, 0);
}
}
}
+ @Override
+ public int getType() {
+ return 0;
+ }
+
@Override
public void draw(SpriteBatch spriteBatch, float x, float y) {
- Assets.pigSprite[0][1].setRotation(anim);
- Assets.pigSprite[1][1].setRotation(-anim);
+ if (x + getWidth() - GP.world.getWidthPx() >= 0 && x - GP.world.getWidthPx() <= getWidth()) {
+ x -= GP.world.getWidthPx();
+ } else if (x + getWidth() + GP.world.getWidthPx() >= 0 && x + GP.world.getWidthPx() <= getWidth()) {
+ x += GP.world.getWidthPx();
+ }
+
+ pigSprite[0][1].setRotation(getAnim());
+ pigSprite[1][1].setRotation(-getAnim());
//back legs
- Assets.pigSprite[1][1].setPosition(x - 4 + (9 - getDirection() * 9), y + 6);
- Assets.pigSprite[1][1].draw(spriteBatch);
- Assets.pigSprite[1][1].setPosition(x + 17 - (9 * getDirection()), y + 6);
- Assets.pigSprite[1][1].draw(spriteBatch);
+ pigSprite[1][1].setPosition(x - 4 + (9 - getDirection() * 9), y + 6);
+ pigSprite[1][1].draw(spriteBatch);
+ pigSprite[1][1].setPosition(x + 17 - (9 * getDirection()), y + 6);
+ pigSprite[1][1].draw(spriteBatch);
//front legs
- Assets.pigSprite[0][1].setPosition(x - 4 + (9 - getDirection() * 9), y + 6);
- Assets.pigSprite[0][1].draw(spriteBatch);
- Assets.pigSprite[0][1].setPosition(x + 17 - (9 * getDirection()), y + 6);
- Assets.pigSprite[0][1].draw(spriteBatch);
+ pigSprite[0][1].setPosition(x - 4 + (9 - getDirection() * 9), y + 6);
+ pigSprite[0][1].draw(spriteBatch);
+ pigSprite[0][1].setPosition(x + 17 - (9 * getDirection()), y + 6);
+ pigSprite[0][1].draw(spriteBatch);
//head & body
spriteBatch.draw(Assets.pigSprite[getDirection()][0], x, y);
}
-
- @Override
- public int getType() {
- return 0;
- }
-
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
similarity index 98%
rename from core/src/ru/deadsoftware/cavedroid/game/objects/Player.java
rename to core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 11863b7c7122aa794d3d7a2714ce3347e16c79f1..df4e0c961a14ebce095b16456602bf896561b8ad 100644 (file)
rename from core/src/ru/deadsoftware/cavedroid/game/objects/Player.java
rename to core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 11863b7c7122aa794d3d7a2714ce3347e16c79f1..df4e0c961a14ebce095b16456602bf896561b8ad 100644 (file)
-package ru.deadsoftware.cavedroid.game.objects;
+package ru.deadsoftware.cavedroid.game.mobs;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java
index cda629d963bb8a103105978d7f57f998c7d0c48f..44822b19b34127d620fbd82fdb778b8d3891d318 100644 (file)
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavedroid.game.mobs.Player;
import java.io.Serializable;
}
public int closeToPlayer() {
- boolean c1 = Intersector.overlaps(new Rectangle(GP.player.pos.x - 16, GP.player.pos.y - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32), getRect());
- boolean c2 = Intersector.overlaps(new Rectangle((GP.player.pos.x + GP.world.getWidthPx()) - 16, GP.player.pos.y - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32), getRect());
- boolean c3 = Intersector.overlaps(new Rectangle((GP.player.pos.x - GP.world.getWidthPx()) - 16, GP.player.pos.y - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32), getRect());
- if (c1) return 1;
- if (c2) return 2;
- if (c3) return 3;
+ boolean[] c = new boolean[3];
+
+ c[0] = Intersector.overlaps(new Rectangle(GP.player.getX() - 16,
+ GP.player.getY() - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32),
+ getRect());
+ c[1] = Intersector.overlaps(new Rectangle((GP.player.getX() + GP.world.getWidthPx()) - 16,
+ GP.player.getY() - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32),
+ getRect());
+ c[2] = Intersector.overlaps(new Rectangle((GP.player.getX() - GP.world.getWidthPx()) - 16,
+ GP.player.getY() - 16, GP.player.getWidth() + 32, GP.player.getHeight() + 32),
+ getRect());
+
+ for (int i = 0; i < 3; i++) {
+ if (c[i]) {
+ return i + 1;
+ }
+ }
return 0;
}
public void moveToPlayer() {
int ctp = closeToPlayer();
if (ctp > 0) {
- float px = GP.player.pos.x;
- float py = GP.player.pos.y;
+ float px = GP.player.getX();
+ float py = GP.player.getY();
switch (ctp) {
case 2:
px += GP.world.getWidthPx();
break;
}
float dx = 0, dy = 0;
- if (px + GP.player.getWidth() < pos.x + 4) dx = -.5f;
- else if (px > pos.x + 4) dx = .5f;
- if (py + GP.player.getHeight() < pos.y + 4) dy = -.5f;
- else if (py > pos.y + 4) dy = .5f;
+ if (px + GP.player.getWidth() < pos.x + 4) {
+ dx = -.5f;
+ } else if (px > pos.x + 4) {
+ dx = .5f;
+ }
+
+ if (py + GP.player.getHeight() < pos.y + 4) {
+ dy = -.5f;
+ } else if (py > pos.y + 4) {
+ dy = .5f;
+ }
+
move.add(dx, dy);
- if (move.x > 2) move.x = 1;
- if (move.x < -2) move.x = -1;
- if (move.y > 2) move.y = 1;
- if (move.y < -2) move.y = -1;
+
+ if (move.x > 2) {
+ move.x = 1;
+ } else if (move.x < -2) {
+ move.x = -1;
+ }
+
+ if (move.y > 2) {
+ move.y = 1;
+ } else if (move.y < -2) {
+ move.y = -1;
+ }
}
}