-
Notifications
You must be signed in to change notification settings - Fork 0
✨ add hound lamp freeze functionality #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| package com.punchbrain.awake.behavior; | ||
|
|
||
| import static com.badlogic.gdx.math.MathUtils.clamp; | ||
| import static com.punchbrain.awake.GameObjectType.CIRCUIT_LAMP; | ||
|
|
||
| import java.util.LinkedList; | ||
| import java.util.Queue; | ||
|
|
||
| import com.badlogic.gdx.Gdx; | ||
| import com.badlogic.gdx.math.Vector2; | ||
| import com.punchbrain.awake.event.GameOverEvent; | ||
| import com.punchbrain.awake.model.Circuit; | ||
| import com.punchbrain.awake.model.map.CircuitModelMap; | ||
| import de.bitbrain.braingdx.behavior.BehaviorAdapter; | ||
| import de.bitbrain.braingdx.event.GameEventManager; | ||
| import de.bitbrain.braingdx.graphics.lighting.LightingManager; | ||
|
|
@@ -27,15 +30,34 @@ public class HoundBehavior extends BehaviorAdapter { | |
| private final Queue<Vector2> snapshots = new LinkedList<Vector2>(); | ||
| private final GameEventManager eventManager; | ||
| private final LightingManager lightingManager; | ||
| private final CircuitModelMap circuitModelMap; | ||
| private boolean inLight; | ||
|
|
||
| public HoundBehavior(GameObject player, GameEventManager eventManager, LightingManager lightingManager) { | ||
| public HoundBehavior(GameObject player, GameEventManager eventManager, LightingManager lightingManager, CircuitModelMap circuitModelMap) { | ||
| this.player = player; | ||
| this.eventManager = eventManager; | ||
| this.lightingManager = lightingManager; | ||
| this.circuitModelMap = circuitModelMap; | ||
| } | ||
|
|
||
| @Override | ||
| public void update(final GameObject hound, final float delta) { | ||
|
|
||
| // TODO: inject a lookup map to find circuit by game object | ||
| // TODO: introduce object to model stereotype Map<GameObject, Model> which can be added to the context | ||
| // Map<Model.class,Map<GameObject, Model>> | ||
| // Or, class ModelMap<T, > | ||
|
|
||
| // TODO: Add a radial resolver | ||
| // TODO: difference in space, plus radius | ||
| // TODO: util method: radialColision(GameObject, radius1, GameObject, radius2) | ||
|
|
||
| // TODO: talk about making this more of a controller class, with resolvers on the models | ||
| if(inLight){ | ||
| // this bool needs to be updated before it's always returned so that it must be checked every time. | ||
| inLight = false; | ||
| return; | ||
| } | ||
| timer.update(delta); | ||
| if (timer.reached(SNAPSHOT_INTERVAL)) { | ||
| timer.reset(); | ||
|
|
@@ -68,6 +90,25 @@ public void update(final GameObject hound, final float delta) { | |
| lightingManager.setAmbientLight(Colors.darken(com.punchbrain.awake.Colors.BACKGROUND, ratio)); | ||
| } | ||
|
|
||
| @Override | ||
| public void update(GameObject hound, GameObject object, float delta){ | ||
| if(CIRCUIT_LAMP.isTypeOf(object)){ | ||
| Circuit circuit = circuitModelMap.getFromLamp(object); | ||
| if(circuit.getState() == Circuit.State.ON){ | ||
| double xSep = hound.getLeft() - object.getLeft(); | ||
| double ySep = hound.getTop() - object.getTop(); | ||
| double rSep = Math.pow(Math.pow(xSep, 2) + Math.pow(ySep, 2), 0.5); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you actually don't need that. Checkout the RayHandler class available through the LightingManager. I'd prefer this since we then can use different types of lights (like cone light for example) |
||
| if(rSep < circuit.getLightRadius()){ | ||
| System.out.println("Contact!"); | ||
| inLight = true; | ||
| System.out.println(inLight); | ||
| return; | ||
| } | ||
| System.out.println(inLight); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private boolean readyToPoll(GameObject hound) { | ||
| return target == null || target.cpy().sub(hound.getPosition()).len() < 396f; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| package com.punchbrain.awake.bootstrap; | ||
|
|
||
| import com.punchbrain.awake.model.map.CircuitModelMap; | ||
| import de.bitbrain.braingdx.context.GameContext2D; | ||
| import de.bitbrain.braingdx.tmx.TiledMapContext; | ||
|
|
||
| public interface LevelBootstrap { | ||
| void boostrap(GameContext2D gameContext2D, TiledMapContext tiledMapContext); | ||
| //TODO: get rid of once a generic game context collection exists. | ||
| void setCircuitModelMap(CircuitModelMap circuitModelMap); | ||
| boolean isApplicable(String tiledMapPath); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,15 @@ | |
| import com.badlogic.gdx.utils.GdxRuntimeException; | ||
| import com.punchbrain.awake.GameObjectType; | ||
| import com.punchbrain.awake.behavior.HoundBehavior; | ||
| import com.punchbrain.awake.model.map.CircuitModelMap; | ||
| import de.bitbrain.braingdx.context.GameContext2D; | ||
| import de.bitbrain.braingdx.tmx.TiledMapContext; | ||
| import de.bitbrain.braingdx.world.GameObject; | ||
|
|
||
| public class LevelStageBootstrap implements LevelBootstrap { | ||
|
|
||
| CircuitModelMap circuitModelMap; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this private |
||
|
|
||
| @Override | ||
| public void boostrap(final GameContext2D gameContext2D, final TiledMapContext tiledMapContext) { | ||
| // add hound | ||
|
|
@@ -32,12 +35,16 @@ public void boostrap(final GameContext2D gameContext2D, final TiledMapContext ti | |
| } | ||
| } | ||
| if (player != null) { | ||
| gameContext2D.getBehaviorManager().apply(new HoundBehavior(player, gameContext2D.getEventManager(), gameContext2D.getLightingManager()), hound); | ||
| gameContext2D.getBehaviorManager().apply(new HoundBehavior(player, gameContext2D.getEventManager(), gameContext2D.getLightingManager(), circuitModelMap), hound); | ||
| } else { | ||
| throw new GdxRuntimeException("Unable to initialise hound! Player not found"); | ||
| } | ||
| } | ||
|
|
||
| public void setCircuitModelMap(CircuitModelMap circuitModelMap) { | ||
| this.circuitModelMap = circuitModelMap; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isApplicable(final String tiledMapPath) { | ||
| return tiledMapPath.contains("level"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.punchbrain.awake.model.map; | ||
|
|
||
| import com.punchbrain.awake.model.Circuit; | ||
| import de.bitbrain.braingdx.world.GameObject; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * | ||
| * Maps circuit time game objects to their {@link com.punchbrain.awake.model.Circuit} models. | ||
| */ | ||
| public class CircuitModelMap { | ||
| private final Map<GameObject, Circuit> lampMap; | ||
| private final Map<GameObject, Circuit> flipSwitchMap; | ||
|
|
||
| public CircuitModelMap(){ | ||
| this.lampMap = new HashMap<>(); | ||
| this.flipSwitchMap = new HashMap<>(); | ||
| } | ||
|
|
||
| public void registerLamp(GameObject gameObject, Circuit circuit) { | ||
| lampMap.put(gameObject, circuit); | ||
| } | ||
|
|
||
| public void registerFlipSwitch(GameObject gameObject, Circuit circuit) { | ||
| lampMap.put(gameObject, circuit); | ||
| } | ||
|
|
||
| public Circuit getFromLamp(GameObject gameObject){ | ||
| return lampMap.get(gameObject); | ||
| } | ||
|
|
||
| public Circuit getFromFlipSwitch(GameObject gameObject){ | ||
| return flipSwitchMap.get(gameObject); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very interesting idea. We might wanna add this to braingdx if it fulfills these criterias:
Let's see some code in action and see if it's useful!