DEADSOFTWARE

Move game world to new package
authorfredboy <fredboy@protonmail.com>
Mon, 15 Apr 2024 10:42:08 +0000 (17:42 +0700)
committerfredboy <fredboy@protonmail.com>
Mon, 15 Apr 2024 10:51:03 +0000 (17:51 +0700)
16 files changed:
core/src/ru/deadsoftware/cavedroid/game/GameInput.java
core/src/ru/deadsoftware/cavedroid/game/GameModule.java
core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
core/src/ru/deadsoftware/cavedroid/game/GameProc.java
core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
core/src/ru/deadsoftware/cavedroid/game/GameSaver.java
core/src/ru/deadsoftware/cavedroid/game/GameWorldGenerator.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java
core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java [moved from core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java with 99% similarity]
core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java [moved from core/src/ru/deadsoftware/cavedroid/game/GameWorld.java with 95% similarity]
core/src/ru/deadsoftware/cavedroid/game/world/GameWorldGenerator.kt [new file with mode: 0644]

index 2376bb110d28e9ee1f8c30639c5c9ac8d34fd5f2..3da4e2e10c44b28e88bfb0236878acab48c15de6 100644 (file)
@@ -11,6 +11,7 @@ import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.mobs.Pig;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 
index d7ccc2d6e44bb7744aa6fa8f84cafd4fcd439a55..a72dbcd9e3fe06d09b908924510d0a0a3a0e0f49 100644 (file)
@@ -5,6 +5,7 @@ import dagger.Provides;
 import ru.deadsoftware.cavedroid.MainConfig;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 
 import javax.annotation.CheckForNull;
 
index cb5b64c844e1ca85886ea58c6269756d669f4f2c..8d5d24c2e5685819a73e34b1f96612da3f0fdaf0 100644 (file)
@@ -10,6 +10,7 @@ import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 
 import javax.inject.Inject;
 import java.util.Iterator;
index d8925f9dfc81f861e5b6a975c006d52e0b12e01d..8c4fefbffc683801228073cb9bba571e4c9de8c9 100644 (file)
@@ -1,6 +1,7 @@
 package ru.deadsoftware.cavedroid.game;
 
 import com.badlogic.gdx.utils.Disposable;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 
 import javax.inject.Inject;
 
index c35b3b4150e4f6ad7289a86f875622f9de269dce..44ec9baeff02942ed911db177e86aee41027e074 100644 (file)
@@ -12,6 +12,7 @@ import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 import ru.deadsoftware.cavedroid.misc.Renderer;
 
index 1ff2bad9783788a68d6ff1858dc9185f2a9a6fbe..0e149839bb77bfee69de30e2584a386b8edd65d1 100644 (file)
@@ -5,6 +5,7 @@ import com.badlogic.gdx.files.FileHandle;
 import ru.deadsoftware.cavedroid.MainConfig;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 
 import javax.annotation.CheckForNull;
 import java.io.*;
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameWorldGenerator.kt b/core/src/ru/deadsoftware/cavedroid/game/GameWorldGenerator.kt
deleted file mode 100644 (file)
index c157a4e..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-package ru.deadsoftware.cavedroid.game
-
-import com.badlogic.gdx.utils.TimeUtils
-import kotlin.math.abs
-import kotlin.random.Random
-
-private fun generateHeights(width: Int, min: Int, max: Int, random: Random) = IntArray(width).apply {
-    set(0, (min + max) / 2)
-    for (x in 1 until width) {
-        val previous = get(x - 1)
-        var d = random.nextInt(-5, 6).let { if (it !in -4..4) it / abs(it) else 0 }
-
-        if (previous + d !in min..max) { d = -d }
-        if (lastIndex - x < abs(get(0) - previous) * 3) {
-            d = get(0).compareTo(previous).let { if (it != 0) it / abs(it) else 0 }
-        }
-
-        set(x, get(x - 1) + d)
-    }
-}
-
-/**
- * Generates world of given width and height with given seed
- * @param width world width
- * @param height world height
- * @param seed seed for random number generator
- * @return pair of foreground and background layers
- */
-fun generate(width: Int, height: Int, seed: Long = TimeUtils.millis()): Pair<Array<IntArray>, Array<IntArray>> {
-    val random = Random(seed)
-    val foreMap = Array(width) { IntArray(height) }
-    val backMap = Array(width) { IntArray(width) }
-    val heightsMap = generateHeights(width, height / 2, height * 3 / 4, random)
-
-    for (x in 0 until width) {
-        val xHeight = heightsMap[x]
-
-        foreMap[x][xHeight] = GameItems.getBlockId("grass")
-        foreMap[x][height - 1] = GameItems.getBlockId("bedrock")
-        backMap[x][xHeight] = GameItems.getBlockId("grass")
-        backMap[x][height - 1] = GameItems.getBlockId("bedrock")
-
-        for (y in xHeight + 1 until height - 1) {
-            foreMap[x][y] = when {
-                y < xHeight + random.nextInt(5, 8) -> GameItems.getBlockId("dirt")
-                else -> GameItems.getBlockId("stone")
-            }
-            backMap[x][y] = foreMap[x][y]
-        }
-    }
-    return Pair(foreMap, backMap)
-}
index f4c62f95a0e97bb861f698f1e5a257e6f8320cbc..495b628416c0cecdf3fac155862e7485a38200ed 100644 (file)
@@ -3,7 +3,7 @@ package ru.deadsoftware.cavedroid.game.mobs;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavedroid.game.GameItems;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 
 /**
  * Falling gravel is actually a mob, that spawns in place of gravel when there is no block under it,
index d1242431f460c7f777462735e99d5558e8657605..07cd8cdd84e3ddf8249be1964681b2a422c09b63 100644 (file)
@@ -3,7 +3,7 @@ package ru.deadsoftware.cavedroid.game.mobs;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavedroid.game.GameItems;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 
 
 /**
index 9f14a698cd526b6a5ce0e00d8fa7b91a20f54977..4ad04e8538affb3b49e3bbf2eb0f80a796ce4510 100644 (file)
@@ -4,7 +4,7 @@ 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;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 
 import java.io.Serializable;
 
index 5742a7c2599c9bd0fe2377a34047d51689aad6a0..15185ef1b8319311aead7f8f74c675a73a0b14f0 100644 (file)
@@ -3,7 +3,7 @@ package ru.deadsoftware.cavedroid.game.mobs;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.misc.Assets;
 
 import static ru.deadsoftware.cavedroid.misc.Assets.pigSprite;
index 5cdb5d85bb5baa6a28e01e14327675f2e1d59deb..272992a29973735c1d38c7b6c10bd2c68d225ae4 100644 (file)
@@ -2,8 +2,7 @@ package ru.deadsoftware.cavedroid.game.mobs;
 
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GamePhysics;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.misc.Assets;
 
 public class Player extends Mob {
index e9f2e61f489ac4b3a276075c4ed1479f2483ce14..995c79e9bc88a544804c740f8ac5582e9ed68610 100644 (file)
@@ -4,7 +4,7 @@ import com.badlogic.gdx.math.Intersector;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
 
 import java.io.Serializable;
similarity index 99%
rename from core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java
rename to core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java
index c3cdd47b355a5d2434f27c3df622dbb1ea669836..570b2c191fbd359f543e74b9a28255b6b516acbb 100644 (file)
@@ -1,4 +1,4 @@
-package ru.deadsoftware.cavedroid.game;
+package ru.deadsoftware.cavedroid.game.world;
 
 import com.badlogic.gdx.utils.TimeUtils;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
similarity index 95%
rename from core/src/ru/deadsoftware/cavedroid/game/GameWorld.java
rename to core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java
index 3bf4981d76d5b5914679f3ed82d2f81adcf979b7..18afcd4b3eec1c725a4675c5b8b429c317256da4 100644 (file)
@@ -1,8 +1,10 @@
-package ru.deadsoftware.cavedroid.game;
+package ru.deadsoftware.cavedroid.game.world;
 
 import com.badlogic.gdx.utils.Disposable;
 import com.badlogic.gdx.utils.TimeUtils;
 import kotlin.Pair;
+import ru.deadsoftware.cavedroid.game.GameItems;
+import ru.deadsoftware.cavedroid.game.GameScope;
 import ru.deadsoftware.cavedroid.game.mobs.FallingGravel;
 import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
@@ -45,7 +47,7 @@ public class GameWorld implements Disposable {
         if (isNewGame) {
             mWidth = DEFAULT_WIDTH;
             mHeight = DEFAULT_HEIGHT;
-            Pair<int[][], int[][]> maps = GameWorldGeneratorKt.generate(mWidth, mHeight, TimeUtils.millis());
+            Pair<int[][], int[][]> maps = GameWorldGenerator.INSTANCE.generate(mWidth, mHeight, TimeUtils.millis());
             mForeMap = maps.getFirst();
             mBackMap = maps.getSecond();
             mMobsController.getPlayer().respawn(this);
@@ -75,11 +77,11 @@ public class GameWorld implements Disposable {
         return mHeight * 16f;
     }
 
-    int[][] getFullForeMap() {
+    public int[][] getFullForeMap() {
         return mForeMap;
     }
 
-    int[][] getFullBackMap() {
+    public int[][] getFullBackMap() {
         return mBackMap;
     }
 
diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldGenerator.kt b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldGenerator.kt
new file mode 100644 (file)
index 0000000..dd64c6a
--- /dev/null
@@ -0,0 +1,57 @@
+package ru.deadsoftware.cavedroid.game.world
+
+import com.badlogic.gdx.utils.TimeUtils
+import ru.deadsoftware.cavedroid.game.GameItems
+import kotlin.math.abs
+import kotlin.random.Random
+
+object GameWorldGenerator {
+
+    private fun generateHeights(width: Int, min: Int, max: Int, random: Random) = IntArray(width).apply {
+        set(0, (min + max) / 2)
+        for (x in 1 until width) {
+            val previous = get(x - 1)
+            var d = random.nextInt(-5, 6).let { if (it !in -4..4) it / abs(it) else 0 }
+
+            if (previous + d !in min..max) { d = -d }
+            if (lastIndex - x < abs(get(0) - previous) * 3) {
+                d = get(0).compareTo(previous).let { if (it != 0) it / abs(it) else 0 }
+            }
+
+            set(x, get(x - 1) + d)
+        }
+    }
+
+    /**
+     * Generates world of given width and height with given seed
+     * @param width world width
+     * @param height world height
+     * @param seed seed for random number generator
+     * @return pair of foreground and background layers
+     */
+    fun generate(width: Int, height: Int, seed: Long = TimeUtils.millis()): Pair<Array<IntArray>, Array<IntArray>> {
+        val random = Random(seed)
+        val foreMap = Array(width) { IntArray(height) }
+        val backMap = Array(width) { IntArray(width) }
+        val heightsMap = generateHeights(width, height / 2, height * 3 / 4, random)
+
+        for (x in 0 until width) {
+            val xHeight = heightsMap[x]
+
+            foreMap[x][xHeight] = GameItems.getBlockId("grass")
+            foreMap[x][height - 1] = GameItems.getBlockId("bedrock")
+            backMap[x][xHeight] = GameItems.getBlockId("grass")
+            backMap[x][height - 1] = GameItems.getBlockId("bedrock")
+
+            for (y in xHeight + 1 until height - 1) {
+                foreMap[x][y] = when {
+                    y < xHeight + random.nextInt(5, 8) -> GameItems.getBlockId("dirt")
+                    else -> GameItems.getBlockId("stone")
+                }
+                backMap[x][y] = foreMap[x][y]
+            }
+        }
+        return Pair(foreMap, backMap)
+    }
+
+}