diff options
Diffstat (limited to 'core/src/kz/ilotterytea/maxon/player')
7 files changed, 252 insertions, 0 deletions
diff --git a/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java b/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java new file mode 100644 index 0000000..ca6d65e --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/player/DecalPlayer.java @@ -0,0 +1,75 @@ +package kz.ilotterytea.maxon.player; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Camera; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g3d.decals.Decal; +import com.badlogic.gdx.math.Intersector; +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.math.collision.BoundingBox; +import com.badlogic.gdx.math.collision.Ray; + +public class DecalPlayer { + private final TextureRegion[] regions; + private int regionIndex; + private final Decal decal; + private final BoundingBox box; + private final MaxonSavegame savegame; + + public DecalPlayer(MaxonSavegame savegame, TextureRegion[] regions) { + this.savegame = savegame; + + this.regions = regions; + this.regionIndex = 0; + + this.decal = Decal.newDecal(this.regions[this.regionIndex]); + this.decal.setScale(0.025f); + this.decal.setPosition(2.0f, 1.75f, 2.0f); + + float width = this.decal.getWidth() / (this.decal.getScaleX() * 1000f); + float height = this.decal.getHeight() / (this.decal.getScaleY() * 1000f); + + Vector3 position = this.decal.getPosition(); + Vector3 minBox = new Vector3(position.x - width / 3, position.y - height / 3, position.z - width / 3); + Vector3 maxBox = new Vector3(position.x + width / 3, position.y + height / 3, position.z + width / 3); + + this.box = new BoundingBox(minBox, maxBox); + } + + public void render(Camera camera) { + checkCollisions(camera); + } + + private void checkCollisions(Camera camera) { + Ray ray = null; + + if (Gdx.input.justTouched()) { + ray = camera.getPickRay(Gdx.input.getX(), Gdx.input.getY()); + } + + if (ray == null) { + return; + } + + Vector3 intersection = new Vector3(); + + if (Intersector.intersectRayBounds(ray, box, intersection)) { + updateTextureRegion(); + savegame.points++; + } + } + + private void updateTextureRegion() { + this.regionIndex++; + + if (this.regions[this.regionIndex] == null) { + this.regionIndex = 0; + } + + this.decal.setTextureRegion(this.regions[this.regionIndex]); + } + + public Decal getDecal() { + return this.decal; + } +} diff --git a/core/src/kz/ilotterytea/maxon/player/MaxonItem.java b/core/src/kz/ilotterytea/maxon/player/MaxonItem.java new file mode 100644 index 0000000..50a9f91 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/player/MaxonItem.java @@ -0,0 +1,23 @@ +package kz.ilotterytea.maxon.player; + +import kz.ilotterytea.maxon.ui.AnimatedImage; + +public class MaxonItem { + public int id; + public String name; + public String desc; + public AnimatedImage icon; + public MaxonItemEnum type; + public float price; + public float multiplier; + + public MaxonItem(int id, String name, String desc, AnimatedImage icon, MaxonItemEnum type, float price, float multiplier) { + this.id = id; + this.name = name; + this.desc = desc; + this.icon = icon; + this.type = type; + this.price = price; + this.multiplier = multiplier; + } +}
\ No newline at end of file diff --git a/core/src/kz/ilotterytea/maxon/player/MaxonItemEnum.java b/core/src/kz/ilotterytea/maxon/player/MaxonItemEnum.java new file mode 100644 index 0000000..12018be --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/player/MaxonItemEnum.java @@ -0,0 +1,7 @@ +package kz.ilotterytea.maxon.player; + +public enum MaxonItemEnum { + DUMMY, + BUFF, + SLAVE +} diff --git a/core/src/kz/ilotterytea/maxon/player/MaxonItemRegister.java b/core/src/kz/ilotterytea/maxon/player/MaxonItemRegister.java new file mode 100644 index 0000000..7b7bc33 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/player/MaxonItemRegister.java @@ -0,0 +1,39 @@ +package kz.ilotterytea.maxon.player; + +import kz.ilotterytea.maxon.ui.AnimatedImage; + +import java.util.ArrayList; + +public class MaxonItemRegister { + private static ArrayList<MaxonItem> items = new ArrayList<>(); + + public static void register( + int id, + String name, + String desc, + AnimatedImage icon, + MaxonItemEnum type, + float price, + float multiplier + ) { + items.add(new MaxonItem(id, name, desc, icon, type, price, multiplier)); + } + + public static void clear() { items.clear(); } + + public static void unRegister( + int id + ) { + items.remove(id); + } + + public static ArrayList<MaxonItem> getItems() { return items; } + public static MaxonItem get(int id) { + for (MaxonItem item : items) { + if (item.id == id) { + return item; + } + } + return null; + } +} diff --git a/core/src/kz/ilotterytea/maxon/player/MaxonPlayer.java b/core/src/kz/ilotterytea/maxon/player/MaxonPlayer.java new file mode 100644 index 0000000..7ba5f49 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/player/MaxonPlayer.java @@ -0,0 +1,26 @@ +package kz.ilotterytea.maxon.player; + +import java.io.Serializable; +import java.util.ArrayList; + +public class MaxonPlayer implements Serializable { + public float points; + public float multiplier; + public ArrayList<Integer> purchasedItems; + + public MaxonPlayer() { + this.points = 0; + this.multiplier = 1.2f; + this.purchasedItems = new ArrayList<>(); + } + + public void load(MaxonPlayer player) { + if (player != null) { + this.points = player.points; + this.multiplier = player.multiplier; + + this.purchasedItems.clear(); + this.purchasedItems.addAll(player.purchasedItems); + } + } +} diff --git a/core/src/kz/ilotterytea/maxon/player/MaxonSavegame.java b/core/src/kz/ilotterytea/maxon/player/MaxonSavegame.java new file mode 100644 index 0000000..e0fe34c --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/player/MaxonSavegame.java @@ -0,0 +1,40 @@ +package kz.ilotterytea.maxon.player; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * Save-game data class. + * @author NotDankEnough + * @since Alpha 1.2 (Oct 02, 2022) + */ +public class MaxonSavegame implements Serializable { + /** Earned Squish Points. */ + public long points = 0L; + /** Multiplier. */ + public long multiplier = 1; + + /** Home inventory. */ + public ArrayList<Integer> inv = new ArrayList<>(); + /** Outside Inventory. */ + public ArrayList<Integer> outInv = new ArrayList<>(); + + /** Seed. */ + public long seed = System.currentTimeMillis(); + + /** Player name. */ + public String name = System.getProperty("user.name"); + /** Pet name. */ + public String petName = "Maxon"; + /** Pet ID. */ + public byte petId = 0; + + /** Elapsed time from game start. */ + public long elapsedTime = 0; + + /** Last timestamp when save game was used. */ + public long lastTimestamp = System.currentTimeMillis(); + + /** Location. */ + public short roomId = 0; +}
\ No newline at end of file diff --git a/core/src/kz/ilotterytea/maxon/player/utils/PetUtils.kt b/core/src/kz/ilotterytea/maxon/player/utils/PetUtils.kt new file mode 100644 index 0000000..31d3720 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/player/utils/PetUtils.kt @@ -0,0 +1,42 @@ +package kz.ilotterytea.maxon.player.utils + +import com.badlogic.gdx.assets.AssetManager +import com.badlogic.gdx.graphics.Texture +import kz.ilotterytea.maxon.anim.SpriteUtils +import kz.ilotterytea.maxon.ui.AnimatedImage + +/** + * Utilities for some operations with pets. + */ +class PetUtils { + companion object { + @JvmStatic + /** + * Get animated image of pet by its ID. + * */ + fun animatedImageById(assetManager: AssetManager, id: Int) : AnimatedImage { + val img: AnimatedImage + + when (id) { + // Maxon: + 0 -> img = AnimatedImage(SpriteUtils.splitToTextureRegions( + assetManager.get( + "sprites/sheet/loadingCircle.png", + Texture::class.java + ), + 112, 112, 10, 5 + )) + // Maxon: + else -> img = AnimatedImage(SpriteUtils.splitToTextureRegions( + assetManager.get( + "sprites/sheet/loadingCircle.png", + Texture::class.java + ), + 112, 112, 10, 5 + )) + } + + return img + } + } +}
\ No newline at end of file |
