From ddb869308ff7587d67495ab22819bc59cd891c5a Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 17 Apr 2019 01:00:10 -0700 Subject: [PATCH] Added Missile entity --- core/src/com/riiablo/ai/QuillRat.java | 9 +++ core/src/com/riiablo/entity/Entity.java | 3 + core/src/com/riiablo/entity/Missile.java | 76 ++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 core/src/com/riiablo/entity/Missile.java diff --git a/core/src/com/riiablo/ai/QuillRat.java b/core/src/com/riiablo/ai/QuillRat.java index 2fe30fb8..c6ba1a74 100644 --- a/core/src/com/riiablo/ai/QuillRat.java +++ b/core/src/com/riiablo/ai/QuillRat.java @@ -6,7 +6,9 @@ import com.badlogic.gdx.ai.msg.Telegram; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.riiablo.Riiablo; +import com.riiablo.codec.excel.Missiles; import com.riiablo.entity.Entity; +import com.riiablo.entity.Missile; import com.riiablo.entity.Monster; import com.riiablo.entity.Player; @@ -34,11 +36,13 @@ public class QuillRat extends AI { final StateMachine stateMachine; float nextAction; float time; + Missiles.Entry missile; public QuillRat(Monster entity) { super(entity); stateMachine = new DefaultStateMachine<>(entity, State.IDLE); monsound = "spikefiend"; + missile = Riiablo.files.Missiles.get(entity.monstats.MissA2); } @Override @@ -72,6 +76,11 @@ public class QuillRat extends AI { entity.sequence(Monster.MODE_A2, Monster.MODE_NU); Riiablo.audio.play(monsound + "_shoot_1", true); time = MathUtils.random(1f, 2); + + Missile miss = new Missile(missile); + miss.position().set(entity.position()); + miss.lookAt(ent); // TODO: should be able to set angle to firing entity angle later + Riiablo.engine.add(miss); return; } } diff --git a/core/src/com/riiablo/entity/Entity.java b/core/src/com/riiablo/entity/Entity.java index 9150ddbf..75de1147 100644 --- a/core/src/com/riiablo/entity/Entity.java +++ b/core/src/com/riiablo/entity/Entity.java @@ -94,6 +94,9 @@ public abstract class Entity implements Animation.AnimationListener { new String[] {"NU"}, new String[] {"NIL"}), WRP("WARPS", + new String[] {"NU"}, + new String[] {"NIL"}), + MIS("MISSILES", new String[] {"NU"}, new String[] {"NIL"}); diff --git a/core/src/com/riiablo/entity/Missile.java b/core/src/com/riiablo/entity/Missile.java new file mode 100644 index 00000000..d6e3b6e5 --- /dev/null +++ b/core/src/com/riiablo/entity/Missile.java @@ -0,0 +1,76 @@ +package com.riiablo.entity; + +import com.badlogic.gdx.assets.AssetDescriptor; +import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.math.Vector2; +import com.riiablo.Riiablo; +import com.riiablo.audio.Audio; +import com.riiablo.codec.Animation; +import com.riiablo.codec.DC; +import com.riiablo.codec.DCC; +import com.riiablo.codec.excel.Missiles; +import com.riiablo.graphics.BlendMode; +import com.riiablo.graphics.PaletteIndexedBatch; + +public class Missile extends Entity { + public final Missiles.Entry missile; + + AssetDescriptor imageDescriptor; + DC image; + int blendMode; + Audio.Instance travelSound; + int velocity; + float remainingDist; + final Vector2 tmpVec2 = new Vector2(); + + public Missile(Missiles.Entry missile) { + super(Type.MIS, missile.Missile, null); + this.missile = missile; + + velocity = missile.Vel; + remainingDist = missile.Range; + switch (missile.Trans) { + case 0: blendMode = BlendMode.ID; break; + case 1: blendMode = BlendMode.LUMINOSITY; break; + default: blendMode = BlendMode.ID; break; + } + + imageDescriptor = new AssetDescriptor<>(Type.MIS.PATH + "\\" + missile.CelFile + ".dcc", DCC.class); + } + + @Override + public void update(float delta) { + float radius = velocity * delta; + remainingDist -= radius; + if (remainingDist < 0) { + Riiablo.engine.remove(this); + return; + } + + // FIXME: angle given using pixels but applied using map coordinated + tmpVec2.x = radius * MathUtils.cos(angle); + tmpVec2.y = radius * MathUtils.sin(angle); + position.add(tmpVec2); + } + + @Override + protected void updateCOF() { + Riiablo.assets.load(imageDescriptor); + Riiablo.assets.finishLoadingAsset(imageDescriptor); + image = Riiablo.assets.get(imageDescriptor); + + animation = Animation.builder() + .layer(image, blendMode) + .build(); + animation.setLooping(missile.LoopAnim > 0); // TODO: Some are 2 -- special case? + animation.setFrame(missile.RandStart); + animation.setFrameDuration(Animation.FRAME_DURATION * missile.AnimSpeed); + animation.setDirection(direction()); + dirty = Dirty.NONE; + + travelSound = Riiablo.audio.play(missile.TravelSound, true); + } + + @Override + public void drawShadow(PaletteIndexedBatch batch) {} +}