From ea55a6624700fd2a652f1fdcf3348b890b248793 Mon Sep 17 00:00:00 2001 From: falsycat Date: Tue, 8 Oct 2019 00:00:00 +0000 Subject: [PATCH] [add] Added ActorController. --- sjplayer/src/sjplayer/ActorController.d | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 sjplayer/src/sjplayer/ActorController.d diff --git a/sjplayer/src/sjplayer/ActorController.d b/sjplayer/src/sjplayer/ActorController.d new file mode 100644 index 0000000..e8d4410 --- /dev/null +++ b/sjplayer/src/sjplayer/ActorController.d @@ -0,0 +1,58 @@ +/// License: MIT +module sjplayer.ActorController; + +import std.algorithm; + +import gl4d; + +import sjscript; + +import sjplayer.Actor, + sjplayer.ScheduledController, + sjplayer.VarStoreInterface; + +/// +class ActorController : ActorScheduledController { + public: + /// + enum MaxAccel = 1e-1; + + /// + this( + Actor actor, + in VarStoreInterface varstore, + in ParametersBlock[] operations) { + super(actor, varstore, operations); + actor_ = actor; + varstore_ = varstore; + operations_ = operations; + } + + /// + void Manipulate(vec2 accel) { + actor_.accel += accel; + + actor_.accel.x = actor_.accel.x.clamp(-MaxAccel, MaxAccel); + actor_.accel.y = actor_.accel.y.clamp(-MaxAccel, MaxAccel); + + actor_.pos += actor_.accel; + // TODO: clamping the actor position + } + + private: + Actor actor_; + + const VarStoreInterface varstore_; + + const ParametersBlock[] operations_; +} + +private alias ActorScheduledController = ScheduledController!( + Actor, + [ + "color_r": "color.r", + "color_g": "color.g", + "color_b": "color.b", + "color_a": "color.a", + ] + );