mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Added triggers and targetting system for brushes. Added corresponding Scripting API endpoint for accessing those.
This commit is contained in:
@@ -30,8 +30,9 @@ class Scene {
|
||||
return this.GetScript_(id)
|
||||
} else if (component == "Trigger") {
|
||||
return Trigger.new(id)
|
||||
} else if (component == "Brush") {
|
||||
return Brush.new(id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
@@ -67,6 +68,9 @@ class Scene {
|
||||
|
||||
foreign static TriggerGetOverlappingBodyCount_(e)
|
||||
foreign static TriggerGetOverlappingBodies_(e)
|
||||
|
||||
foreign static BrushGetTargets_(e)
|
||||
foreign static BrushGetTargetsCount_(e)
|
||||
}
|
||||
|
||||
class Entity {
|
||||
@@ -170,12 +174,40 @@ class Trigger {
|
||||
}
|
||||
|
||||
GetOverlappingBodies() {
|
||||
bodies = Scene.TriggerGetOverlappingBodies_(_entityId)
|
||||
if(this.GetOverlappingBodyCount() <= 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
entities = []
|
||||
var bodies = Scene.TriggerGetOverlappingBodies_(_entityId)
|
||||
|
||||
var entities = []
|
||||
for(b in bodies) {
|
||||
entities.add(Entity.new(b))
|
||||
}
|
||||
return entities
|
||||
}
|
||||
}
|
||||
|
||||
class Brush {
|
||||
construct new(id) {
|
||||
_entityId = id
|
||||
}
|
||||
|
||||
GetTargetsCount() {
|
||||
return Scene.BrushGetTargetsCount_(_entityId)
|
||||
}
|
||||
|
||||
GetTargets() {
|
||||
if(this.GetTargetsCount() <= 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
var entities = []
|
||||
var targets = Scene.BrushGetTargets_(_entityId)
|
||||
for(t in targets) {
|
||||
entities.add(Entity.new(t))
|
||||
}
|
||||
|
||||
return entities
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,43 @@ import "Scripts/Physics" for Physics, CollisionResult
|
||||
|
||||
class TriggerScript is ScriptableEntity {
|
||||
construct new() {
|
||||
|
||||
_Activated = false
|
||||
}
|
||||
|
||||
init() {
|
||||
Engine.Log("Hello, I'm a trigger")
|
||||
}
|
||||
|
||||
update(ts) {
|
||||
|
||||
}
|
||||
|
||||
fixedUpdate(ts) {
|
||||
var trigger = this.GetComponent("Trigger")
|
||||
|
||||
Engine.Log("Current overlap: %(trigger.GetOverlappingBodyCount())")
|
||||
if(trigger.GetOverlappingBodyCount() > 0) {
|
||||
var bodies = trigger.GetOverlappingBodies()
|
||||
var brush = this.GetComponent("Brush")
|
||||
var isPlayer = bodies[0].HasComponent("CharacterController")
|
||||
if(isPlayer) {
|
||||
_Activated = true
|
||||
}
|
||||
|
||||
}
|
||||
if(_Activated) {
|
||||
var brush = this.GetComponent("Brush")
|
||||
for(t in brush.GetTargets()) {
|
||||
var transform = t.GetComponent("Transform")
|
||||
var pos = transform.GetTranslation()
|
||||
|
||||
var target = t.GetComponent("Brush")
|
||||
var pos2 = target.GetTargets()[0].GetComponent("Transform")
|
||||
var targetPos = pos2.GetTranslation()
|
||||
|
||||
if(pos.y < targetPos.y) {
|
||||
pos.y = pos.y + 3.0 * ts
|
||||
}
|
||||
|
||||
transform.SetTranslation(pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit() {
|
||||
|
||||
Reference in New Issue
Block a user