mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-21 20:18:14 +07:00
Improved entity over detection
Improved entity over detection Added entity highlighting, however my technique is washing out the image too much
This commit is contained in:
parent
0d56f2456e
commit
22251f560a
@ -23,7 +23,7 @@ public class Animation extends BaseDrawable {
|
||||
private static final String TAG = "Animation";
|
||||
private static final int DEBUG_MODE = 0; // 0=off, 1=box, 2=layer box
|
||||
|
||||
private static final int NUM_LAYERS = 16;
|
||||
private static final int NUM_LAYERS = COF.Component.NUM_COMPONENTS;
|
||||
private static final float FRAMES_PER_SECOND = 25f;
|
||||
private static final float FRAME_DURATION = 1 / FRAMES_PER_SECOND;
|
||||
|
||||
@ -41,6 +41,7 @@ public class Animation extends BaseDrawable {
|
||||
private COF cof;
|
||||
//private Bits cache[];
|
||||
private BBox box;
|
||||
private boolean highlighted;
|
||||
|
||||
private final Set<AnimationListener> ANIMATION_LISTENERS;
|
||||
|
||||
@ -200,6 +201,53 @@ public class Animation extends BaseDrawable {
|
||||
looping = b;
|
||||
}
|
||||
|
||||
public boolean isHighlighted() {
|
||||
return highlighted;
|
||||
}
|
||||
|
||||
public void setHighlighted(boolean b) {
|
||||
if (highlighted != b) {
|
||||
highlighted = b;
|
||||
if (b) {
|
||||
if (cof == null) {
|
||||
for (int l = 0; l < NUM_LAYERS; l++) {
|
||||
Layer layer = layers[l];
|
||||
if (layer == null) break;
|
||||
if (layer.blendMode == BlendMode.ID) {
|
||||
layer.setBlendMode(BlendMode.TINT_ID, Riiablo.colors.highlight);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int l = 0; l < cof.getNumLayers(); l++) {
|
||||
COF.Layer cofLayer = cof.getLayer(l);
|
||||
Layer layer = layers[cofLayer.component];
|
||||
if (layer.blendMode == BlendMode.ID) {
|
||||
layer.setBlendMode(BlendMode.TINT_ID, Riiablo.colors.highlight);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (cof == null) {
|
||||
for (int l = 0; l < NUM_LAYERS; l++) {
|
||||
Layer layer = layers[l];
|
||||
if (layer == null) break;
|
||||
if (layer.blendMode == BlendMode.TINT_ID) {
|
||||
layer.setBlendMode(BlendMode.ID);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int l = 0; l < cof.getNumLayers(); l++) {
|
||||
COF.Layer cofLayer = cof.getLayer(l);
|
||||
Layer layer = layers[cofLayer.component];
|
||||
if (layer.blendMode == BlendMode.TINT_ID) {
|
||||
layer.setBlendMode(BlendMode.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float getFrameDuration() {
|
||||
return frameDuration;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ public abstract class Entity {
|
||||
|
||||
String name;
|
||||
Label label;
|
||||
public boolean over = true;
|
||||
boolean over;
|
||||
|
||||
byte nextMode = -1;
|
||||
|
||||
@ -551,6 +551,17 @@ public abstract class Entity {
|
||||
return animation.getMinHeight();
|
||||
}
|
||||
|
||||
public boolean isOver() {
|
||||
return over;
|
||||
}
|
||||
|
||||
public void setOver(boolean b) {
|
||||
if (over != b) {
|
||||
over = b;
|
||||
animation.setHighlighted(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void animate(byte transition, byte mode) {
|
||||
setMode(transition);
|
||||
nextMode = mode;
|
||||
|
@ -33,13 +33,13 @@ public class MapListener {
|
||||
gameScreen.clearLabels();
|
||||
for (Map.Zone zone : map.zones) {
|
||||
for (Entity entity : zone.entities) {
|
||||
entity.over = entity.contains(position);
|
||||
if (entity.over) gameScreen.addLabel(entity.getLabel());
|
||||
entity.setOver(entity.contains(position));
|
||||
if (entity.isOver()) gameScreen.addLabel(entity.getLabel());
|
||||
}
|
||||
}
|
||||
for (Entity entity : gameScreen.entities.values()) {
|
||||
entity.over = entity.contains(position);
|
||||
if (entity.over) gameScreen.addLabel(entity.getLabel());
|
||||
entity.setOver(entity.contains(position));
|
||||
if (entity.isOver()) gameScreen.addLabel(entity.getLabel());
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ public class MapListener {
|
||||
//setTarget(null);
|
||||
for (Map.Zone zone : new Array.ArrayIterator<>(map.zones)) {
|
||||
for (Entity entity : zone.entities) {
|
||||
if (entity.over) {
|
||||
if (entity.isOver()) {
|
||||
if (entity.position().dst(gameScreen.player.position()) <= entity.getInteractRange()) {
|
||||
setTarget(null);
|
||||
entity.interact(gameScreen);
|
||||
|
@ -442,7 +442,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
Array<Entity> nearby = mapRenderer.getNearbyEntities();
|
||||
for (Entity entity : nearby) {
|
||||
if (entity.isSelectable() && entity.position().dst(player.position()) <= entity.getInteractRange() * 2) {
|
||||
entity.over = true;
|
||||
entity.setOver(true);
|
||||
addLabel(entity.getLabel());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user