class EnemyMovement : ZilchComponent { //This script allows you to make an object or enemy to move back and forth between 2 points //This is the speed at which the object will move [Property] var Speed : Real = 5.0; [Property] var LeftBoundary : Real = 0.0; [Property] var RightBoundary : Real = 0.0; function Initialize(init : CogInitializer) { // Connect to the LogicUpdate event: Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate); } function OnLogicUpdate(event : UpdateEvent) { var position = this.Owner.Transform.Translation; // This will make the object move to the left first // If the object moves past the Left Boundary than it will flip then move in the opposite direction if (position.X < this.LeftBoundary) { this.Owner.Sprite.FlipX = true; this.Speed *= -1; } //If the object moves past the Right Boundary than it will flip back to its //original direction than move in the opposite direction if (position.X >= this.RightBoundary) { this.Owner.Sprite.FlipX = false; this.Speed *= -1; } position.X -= this.Speed * event.Dt; this.Owner.Transform.Translation = position;