summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b62c3a3)
raw | patch | inline | side by side (parent: b62c3a3)
author | fredboy <fredboy@protonmail.com> | |
Fri, 19 Apr 2024 17:43:29 +0000 (00:43 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Fri, 19 Apr 2024 17:44:05 +0000 (00:44 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java
index a0c5f664cdcef8d05081b11dee9488e502eb263e..015d81a1ad6b2ff4abcea74462113214747d95f3 100644 (file)
private void hitMobs() {
final Player player = mMobsController.getPlayer();
- mMobsController.forEach((mob) -> {
+ mMobsController.getMobs().forEach((mob) -> {
if (Intersector.overlaps(mob, player)) {
mob.damage(5);
mob.jump();
break;
case Input.Keys.G:
- mMobsController.addMob(Pig.class, mCurX * 16, mCurY * 16);
+ mMobsController.addMob(new Pig(mCurX * 16, mCurY * 16));
break;
case Input.Keys.Q:
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index 4127b6dba4ee9fbb6af1b90d3c47390591467d9f..1ff603c26148f9a473cd9705bfc29ae665e1690a 100644 (file)
}
}
- for (Iterator<Mob> it = mMobsController.getIterator(); it.hasNext(); ) {
+ for (Iterator<Mob> it = mMobsController.getMobs().iterator(); it.hasNext(); ) {
Mob mob = it.next();
mob.ai(mGameWorld, delta);
mobPhy(mob, delta);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
index 09878f501d1224304633243a69b80fafc0fe34bc..20401acd7e000fd4fd62efaea89a2909630d3898 100644 (file)
drawWorld(true);
player.draw(spriter, player.getX() - getCamX() - player.getWidth() / 2, player.getY() - getCamY(), delta);
- mMobsController.forEach( (mob) -> { drawMob(mob, delta); });
+ mMobsController.getMobs().forEach( (mob) -> { drawMob(mob, delta); });
mDropController.forEach(this::drawDrop);
drawWorld(false);
drawGUI();
drawString("CurY: " + mGameInput.getCurY(), 0, 40);
drawString("Velocity: " + player.getVelocity(), 0, 50);
drawString("Swim: " + player.swim, 0, 60);
- drawString("Mobs: " + mMobsController.getSize(), 0, 70);
+ drawString("Mobs: " + mMobsController.getMobs().size(), 0, 70);
drawString("Drops: " + mDropController.getSize(), 0, 80);
drawString("Block: " + GameItems.getBlockKey(mGameWorld.getForeMap(mGameInput.getCurX(), mGameInput.getCurY())), 0, 90);
drawString("Hand: " + GameItems.getItemKey(mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot]), 0, 100);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/MobsController.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/MobsController.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package ru.deadsoftware.cavedroid.game.mobs;
-
-import com.badlogic.gdx.Gdx;
-import ru.deadsoftware.cavedroid.game.GameScope;
-
-import javax.inject.Inject;
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-@GameScope
-public class MobsController implements Serializable {
-
- public interface Callback {
- void run(Mob mob);
- }
-
- private static final String TAG = "MobsController";
-
- private final Player mPlayer;
- private final LinkedList<Mob> mMobs = new LinkedList<>();
-
- @Inject
- public MobsController() {
- mPlayer = new Player();
- }
-
- public Player getPlayer() {
- return mPlayer;
- }
-
- public void addMob(Class<? extends Mob> mobClass, float x, float y) {
- try {
- mMobs.add(mobClass.getConstructor(float.class, float.class).newInstance(x, y));
- } catch (Exception e) {
- Gdx.app.error(TAG, e.getMessage());
- }
- }
-
- public int getSize() {
- return mMobs.size();
- }
-
- public void forEach(Callback callback) {
- mMobs.forEach(callback::run);
- }
-
- public Iterator<Mob> getIterator() {
- return mMobs.iterator();
- }
-
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/MobsController.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/MobsController.kt
--- /dev/null
@@ -0,0 +1,25 @@
+package ru.deadsoftware.cavedroid.game.mobs
+
+import ru.deadsoftware.cavedroid.game.GameScope
+import java.io.Serializable
+import java.util.*
+import javax.inject.Inject
+
+@GameScope
+class MobsController @Inject constructor() : Serializable {
+
+ private val _mobs = LinkedList<Mob>()
+
+ val player: Player = Player()
+
+ val mobs: List<Mob>
+ get() = _mobs
+
+ fun addMob(mob: Mob) {
+ _mobs.add(mob)
+ }
+
+ companion object {
+ private const val TAG = "MobsController"
+ }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java
index 31d842b331e85768e3ff9369c26e93c0160c361b..692eabcb45289a6944150b07cfc6f2dd12959d5c 100644 (file)
if (getForeMap(x, y) == 10) {
if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
setForeMap(x, y, 0);
- mMobsController.addMob(FallingSand.class, x * 16, y * 16);
+ mMobsController.addMob(new FallingSand(x * 16, y * 16));
updateBlock(x, y - 1);
}
}
if (getForeMap(x, y) == 11) {
if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
setForeMap(x, y, 0);
- mMobsController.addMob(FallingGravel.class, x * 16, y * 16);
+ mMobsController.addMob(new FallingGravel(x * 16, y * 16));
updateBlock(x, y - 1);
}
}