Advertisement
Cubby208

Untitled

Jul 2nd, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. class MosePlayerControler : ZilchComponent
  2. {
  3. [Property]
  4. var Bullet : Archetype = Archetype.Find("Bullet");
  5. [Property]
  6. var Accel : Real = 1.0;
  7. [Property]
  8. var MaxVelocity : Real = 15.0;
  9.  
  10. function Initialize(init : CogInitializer)
  11. {
  12. Zero.Connect(this.Space, Events.MouseMove, this.OnMouseMove);
  13. Zero.Connect(this.Space, Events.LeftMouseDown, this.OnLeftMouseDown);
  14. Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
  15. Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
  16.  
  17. }
  18. function OnLogicUpdate(event : UpdateEvent)
  19. {
  20. var movement = local Real3(0.0, 0.0, 0.0);
  21. var forwardDirection = this.Owner.Orientation.WorldForward;
  22. if(Zero.Keyboard.KeyIsDown(Keys.W))
  23. {
  24. movement += forwardDirection;
  25. }
  26. this.Owner.RigidBody.Velocity += movement * event.Dt * this.Accel;
  27. }
  28. function OnLeftMouseDown(event : ViewportMouseEvent)
  29. {
  30. this.Shoot();
  31. }
  32. function OnMouseMove(event : ViewportMouseEvent)
  33. {
  34. var mousePositon = event.ToWorldZPlane(0);
  35.  
  36. //this.Owner.Transform.Translation = mousePositon;
  37.  
  38. if(this.Owner.Transform.Translation != mousePositon)
  39. {
  40. this.Owner.Orientation.LookAtPointWithUp(mousePositon, this.Owner.Orientation.WorldUp);
  41. }
  42.  
  43. if(Zero.Keyboard.KeyIsDown(Keys.Space))
  44. {
  45. this.Shoot();
  46. }
  47. }
  48.  
  49. function Shoot()
  50. {
  51. var spawnLocation = this.Owner.Transform.Translation + this.Owner. Orientation.WorldForward;
  52.  
  53. var bullet = this.Space.CreateAtPosition(this.Bullet, spawnLocation); bullet.RigidBody.Velocity = this.Owner.Orientation.WorldForward * 10;
  54. }
  55. function OnCollisionStarted(event : CollisionEvent)
  56. {
  57. Console.WriteLine("Colodeded");
  58. if(event.OtherObject.Name == "Space Rock")
  59. {
  60. this.Space.ReloadLevel();
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement