From 22251f560ac4b0d7f392fefbad7a23b1e155539b Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sun, 10 Mar 2019 03:35:25 -0700 Subject: [PATCH] Improved entity over detection Improved entity over detection Added entity highlighting, however my technique is washing out the image too much --- core/src/com/riiablo/codec/Animation.java | 50 ++++++++++++++++++++- core/src/com/riiablo/entity/Entity.java | 13 +++++- core/src/com/riiablo/map/MapListener.java | 10 ++--- core/src/com/riiablo/screen/GameScreen.java | 2 +- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/core/src/com/riiablo/codec/Animation.java b/core/src/com/riiablo/codec/Animation.java index 57fef40f..ae4e70f0 100644 --- a/core/src/com/riiablo/codec/Animation.java +++ b/core/src/com/riiablo/codec/Animation.java @@ -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 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; } diff --git a/core/src/com/riiablo/entity/Entity.java b/core/src/com/riiablo/entity/Entity.java index 9116800a..64be5c24 100644 --- a/core/src/com/riiablo/entity/Entity.java +++ b/core/src/com/riiablo/entity/Entity.java @@ -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; diff --git a/core/src/com/riiablo/map/MapListener.java b/core/src/com/riiablo/map/MapListener.java index 38ca50d4..fcf28cd8 100644 --- a/core/src/com/riiablo/map/MapListener.java +++ b/core/src/com/riiablo/map/MapListener.java @@ -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); diff --git a/core/src/com/riiablo/screen/GameScreen.java b/core/src/com/riiablo/screen/GameScreen.java index cddedd18..707ba813 100644 --- a/core/src/com/riiablo/screen/GameScreen.java +++ b/core/src/com/riiablo/screen/GameScreen.java @@ -442,7 +442,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable Array 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()); } }