mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-19 16:57:20 +07:00
Added Missile entity
This commit is contained in:
parent
93b9acc944
commit
ddb869308f
@ -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<Monster, State> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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"});
|
||||
|
||||
|
76
core/src/com/riiablo/entity/Missile.java
Normal file
76
core/src/com/riiablo/entity/Missile.java
Normal file
@ -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<DCC> 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) {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user