diff options
| author | ilotterytea <iltsu@alright.party> | 2024-06-10 00:04:33 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-06-10 00:04:33 +0500 |
| commit | 5bb8db06b01524bee613776cb9896a85ecbe2862 (patch) | |
| tree | 035ea25b3c6ea6e0f793ec570805975ff9c0a147 /core | |
| parent | 8833419a56c090fc357ee483556428196d26ed67 (diff) | |
feat: render pet bros
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/pets/Pet.java | 13 | ||||
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java | 40 |
2 files changed, 51 insertions, 2 deletions
diff --git a/core/src/kz/ilotterytea/maxon/pets/Pet.java b/core/src/kz/ilotterytea/maxon/pets/Pet.java index 4b4cb00..7c69a0b 100644 --- a/core/src/kz/ilotterytea/maxon/pets/Pet.java +++ b/core/src/kz/ilotterytea/maxon/pets/Pet.java @@ -2,6 +2,7 @@ package kz.ilotterytea.maxon.pets; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g3d.decals.Decal; import com.badlogic.gdx.utils.GdxRuntimeException; import kz.ilotterytea.maxon.MaxonConstants; import kz.ilotterytea.maxon.MaxonGame; @@ -14,15 +15,17 @@ public class Pet { private final String id, name, description; private final double price, multiplier; private final AnimatedImage icon; + private final Decal decal; private static final Logger logger = LoggerFactory.getLogger(Pet.class); - private Pet(String id, String name, String description, double price, double multiplier, AnimatedImage icon) { + private Pet(String id, String name, String description, double price, double multiplier, AnimatedImage icon, Decal decal) { this.id = id; this.name = name; this.description = description; this.price = price; this.multiplier = multiplier; this.icon = icon; + this.decal = decal; } public static Pet create(String id, double price, double multiplier, int iconColumns, int iconRows) { @@ -56,7 +59,9 @@ public class Pet { description = "pet." + id + ".desc"; } - return new Pet(id, name, description, price, multiplier, icon); + Decal decal = Decal.newDecal(0.5f, 0.5f, regions[0], true); + + return new Pet(id, name, description, price, multiplier, icon, decal); } public String getId() { @@ -82,4 +87,8 @@ public class Pet { public AnimatedImage getIcon() { return icon; } + + public Decal getDecal() { + return decal; + } } diff --git a/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java b/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java index 49dc09e..0ff5eaf 100644 --- a/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java +++ b/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy; import com.badlogic.gdx.graphics.g3d.decals.Decal; import com.badlogic.gdx.graphics.g3d.decals.DecalBatch; import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; @@ -24,6 +25,7 @@ import kz.ilotterytea.maxon.anim.SpriteUtils; import kz.ilotterytea.maxon.audio.Playlist; import kz.ilotterytea.maxon.inputprocessors.CrossProcessor; import kz.ilotterytea.maxon.pets.Pet; +import kz.ilotterytea.maxon.pets.PetManager; import kz.ilotterytea.maxon.player.DecalPlayer; import kz.ilotterytea.maxon.player.MaxonItem; import kz.ilotterytea.maxon.player.MaxonItemRegister; @@ -83,6 +85,8 @@ public class GameScreen implements Screen, InputProcessor { private ArrayList<Decal> decals; private DecalPlayer decalPlayer; + private float elapsedTime = 0.0f; + private final ArrayList<Timer.Task> tasks = new ArrayList<>(); public GameScreen() { @@ -190,6 +194,42 @@ public class GameScreen implements Screen, InputProcessor { this.decalBatch.add(decal); } + // - - - R E N D E R I N G P E T S - - - + ArrayList<Decal> petDecals = new ArrayList<>(); + + // Getting the pet decals + for (String id : savegame.getPurchasedPets().keySet()) { + PetManager petManager = game.getPetManager(); + Optional<Pet> pet = petManager.getPet(id); + + if (pet.isEmpty()) { + continue; + } + + int amount = savegame.getPurchasedPets().get(id); + + for (int i = 0; i < amount; i++) { + Decal decal = pet.get().getDecal(); + petDecals.add(Decal.newDecal(decal.getWidth(), decal.getHeight(), decal.getTextureRegion())); + } + } + + elapsedTime += delta; + + // Rendering the pet decals + for (int i = 0; i < petDecals.size(); i++) { + Decal decal = petDecals.get(i); + + float angle = elapsedTime + (i * MathUtils.PI2 / petDecals.size()); + float radius = 2.0f; + float x = MathUtils.cos(angle) * radius; + float z = MathUtils.sin(angle) * radius; + + decal.setPosition(decalPlayer.getDecal().getX() + x, 0.5f, decalPlayer.getDecal().getZ() + z); + decal.lookAt(this.camera.position, this.camera.up); + this.decalBatch.add(decal); + } + this.decalBatch.flush(); stage.act(delta); |
