diff --git a/Dungeoneer/assets/data/entities.dat b/Dungeoneer/assets/data/entities.dat index e1179979..4e10a7a3 100644 --- a/Dungeoneer/assets/data/entities.dat +++ b/Dungeoneer/assets/data/entities.dat @@ -39,6 +39,9 @@ }, "Status Effect Area": { "class": "com.interrupt.dungeoneer.entities.areas.StatusEffectArea" + }, + "Physics Force Area": { + "class": "com.interrupt.dungeoneer.entities.areas.PhysicsForceArea" } }, "Camera": { diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/areas/PhysicsForceArea.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/areas/PhysicsForceArea.java new file mode 100644 index 00000000..6ded2c30 --- /dev/null +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/areas/PhysicsForceArea.java @@ -0,0 +1,93 @@ +package com.interrupt.dungeoneer.entities.areas; + +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.Array; +import com.interrupt.dungeoneer.annotations.EditorProperty; +import com.interrupt.dungeoneer.entities.Entity; +import com.interrupt.dungeoneer.game.Level; +import com.interrupt.dungeoneer.interfaces.Directional; + +public class PhysicsForceArea extends Area implements Directional { + public PhysicsForceArea() { hidden = true; spriteAtlas = "editor"; tex = 11; isStatic = false; isDynamic = true; collision.set(0.25f, 0.25f, 1f); } + + @EditorProperty + public float forceAmount = 0.01f; + + @EditorProperty + public boolean instantForce = false; + + @EditorProperty + public boolean enabled = true; + + public Vector3 rotation = new Vector3(); + + public transient Vector3 dirWork = new Vector3(); + + @Override + public void tick(Level level, float delta) { + if(!enabled) + return; + + Array touching = level.getEntitiesEncroaching(this); + for(int i = 0; i < touching.size; i++) { + Entity e = touching.get(i); + if(!e.isStatic) { + Vector3 dir = getDirection(); + + if(instantForce) { + e.xa = dir.x * forceAmount; + e.ya = dir.y * forceAmount; + e.za = dir.z * forceAmount; + } else { + e.xa += dir.x * forceAmount * delta; + e.ya += dir.y * forceAmount * delta; + e.za += dir.z * forceAmount * delta; + } + } + } + } + + @Override + public void onTrigger(Entity instigator, String value) { + enabled = !enabled; + } + + @Override + public void rotate90() { + super.rotate90(); + rotation.z -= 90f; + } + + @Override + public void rotate90Reversed() { + super.rotate90Reversed(); + rotation.z += 90f; + } + + @Override + public void setRotation(float rotX, float rotY, float rotZ) { + rotation.x = rotX; + rotation.y = rotY; + rotation.z = rotZ; + } + + @Override + public void rotate(float rotX, float rotY, float rotZ) { + rotation.x += rotX; + rotation.y += rotY; + rotation.z += rotZ; + } + + @Override + public Vector3 getRotation() { + return rotation; + } + + public Vector3 getDirection() { + Vector3 dir = dirWork.set(1,0,0); + dir.rotate(Vector3.Y, -rotation.y); + dir.rotate(Vector3.X, -rotation.x); + dir.rotate(Vector3.Z, -rotation.z); + return dir; + } +}