1 module evael.graphics.gui.animations.WizzAnimation; 2 3 import evael.graphics.gui.animations.Animation; 4 import evael.graphics.gui.controls.Control; 5 6 import std.random : uniform; 7 8 import dlib.math.vector; 9 10 /** 11 * WizzAnimation. 12 */ 13 class WizzAnimation : Animation 14 { 15 private float m_elapsedTime; 16 17 private vec2 m_initialControlPosition; 18 19 @nogc @safe 20 public this() pure nothrow 21 { 22 super(); 23 24 this.m_elapsedTime = 0.0f; 25 } 26 27 public override void update(in float deltaTime) 28 { 29 if(this.m_status != Status.Playing) 30 { 31 this.onAnimationStart(); 32 } 33 34 this.m_elapsedTime += deltaTime; 35 36 if(this.m_elapsedTime >= this.m_duration) 37 { 38 this.onAnimationEnd(); 39 return; 40 } 41 42 auto newPosition = vec2(this.m_initialControlPosition.x + uniform(-5, 5), this.m_initialControlPosition.y + uniform(-5, 5)); 43 44 this.m_control.realPosition = newPosition; 45 } 46 47 public override void onAnimationStart() 48 { 49 this.m_initialControlPosition = this.m_control.realPosition; 50 51 super.onAnimationStart(); 52 } 53 54 public override void onAnimationEnd() 55 { 56 this.m_control.realPosition = this.m_initialControlPosition; 57 58 super.onAnimationEnd(); 59 } 60 61 @nogc @safe 62 public override void reset() pure nothrow 63 { 64 super.reset(); 65 this.m_elapsedTime = 0; 66 } 67 }