class PlayerController : ZilchComponent { [Property] var WallJumpRight : Real = 0.0; [Property] var WallJumpLeft : Real = 0.0; [Property] var WallJumpHeight : Real = 0.0; var WallRight : Boolean = false; var WallLeft : Boolean = false; var Counter : Integer = 0; function Initialize(init : CogInitializer) { Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate); Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted); Zero.Connect(this.Owner, Events.CollisionPersisted, this.OnCollisionPersisted); Zero.Connect(this.Owner, Events.CollisionEnded, this.OnCollisionEnded); var startPosition = this.Space.LevelSettings.LevelVars.PlayerPosition; this.Owner.Transform.Translation = startPosition; } function OnCollisionPersisted(event : CollisionEvent) { if(this.Owner.SweptController.Grounded == false && this.Owner.Sprite.FlipX == true) { this.WallLeft = true; Console.WriteLine(this.WallLeft); //this.Owner.SweptController.JumpDirectionally(Real3(5.0, 5.0, 0.0)); } else if(this.Owner.SweptController.Grounded == false && this.Owner.Sprite.FlipX == false) { this.WallRight = true; Console.WriteLine(this.WallRight); //this.Owner.SweptController.JumpDirectionally(Real3(-5.0, 5.0, 0.0)); } } function OnCollisionEnded(event : CollisionEvent) { this.WallLeft = false; this.WallRight = false; } function OnCollisionStarted(event : CollisionEvent) { if(event.OtherObject.CheckPoint1 != null) { var checkpointPosition = event.OtherObject.Transform.Translation; checkpointPosition.Y = this.Owner.Transform.Translation.Y; this.Space.LevelSettings.LevelVars.PlayerPosition = checkpointPosition; } } function OnLogicUpdate(event : UpdateEvent) { var movement = Real3(0.0, 0.0, 0.0); // control left, right, and up if(Zero.Keyboard.KeyIsDown(Keys.Left)) { movement.X -= 1.0; this.Owner.Sprite.FlipX = true; } if(Zero.Keyboard.KeyIsDown(Keys.Right)) { movement.X += 1.0; this.Owner.Sprite.FlipX = false; } if(Zero.Keyboard.KeyIsPressed(Keys.Up)) { this.Counter += 1; if(this.Owner.SweptController.Grounded == true) { this.Owner.SweptController.JumpUnconditionally(); } if(this.Counter < 3) { this.Owner.SweptController.JumpUnconditionally(); } if(this.WallLeft == true) { this.Owner.SweptController.JumpDirectionally(Real3(this.WallJumpRight, this.WallJumpHeight, 0.0)); } if(this.WallRight == true) { this.Owner.SweptController.JumpDirectionally(Real3(this.WallJumpLeft, this.WallJumpHeight, 0.0)); } } if(Zero.Keyboard.KeyIsDown(Keys.Up) == false) { if(this.Owner.SweptController.Jumping) { this.Owner.SweptController.JumpCancel(); } } this.Owner.SweptController.Update(movement, event.Dt); if(this.Owner.SweptController.Grounded == true) { this.Counter = 0; } } }