-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding an area that can apply physics forces to objects
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
Dungeoneer/src/com/interrupt/dungeoneer/entities/areas/PhysicsForceArea.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Entity> 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; | ||
} | ||
} |