nitrodog96

ShotController

Mar 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. class ShotController : ZilchComponent
  2. {
  3. var DiagonalBulletSpeed : Real = 10 * Math.Sin(Math.ToRadians(45));
  4.  
  5. var BulletDamageModifier : Real = 1.0;
  6. function Initialize(init : CogInitializer)
  7. {
  8. Zero.Connect(this.Owner, Events.ShootUp, this.OnShootUp);
  9. Zero.Connect(this.Owner, Events.ShootDown, this.OnShootDown);
  10. Zero.Connect(this.Owner, Events.ShootLeft, this.OnShootLeft);
  11. Zero.Connect(this.Owner, Events.ShootRight, this.OnShootRight);
  12. Zero.Connect(this.Owner, Events.ShootUpLeft, this.OnShootUpLeft);
  13. Zero.Connect(this.Owner, Events.ShootUpRight, this.OnShootUpRight);
  14. Zero.Connect(this.Owner, Events.ShootDownLeft, this.OnShootDownLeft);
  15. Zero.Connect(this.Owner, Events.ShootDownRight, this.OnShootDownRight);
  16. Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
  17. }
  18.  
  19. function OnLogicUpdate(event : UpdateEvent)
  20. {
  21. this.BulletDamageModifier = this.Owner.PlayerController.BulletDamageMod;
  22. }
  23.  
  24. function OnShootUp(event : Event)
  25. {
  26. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation + Real3(0.0, 0.0, 0.0));
  27. bullet.RigidBody.Velocity = Real3(0, 10, 0);
  28. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  29. }
  30.  
  31. function OnShootDown(event : Event)
  32. {
  33. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation);
  34. bullet.RigidBody.Velocity = Real3(0, -10, 0);
  35. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  36. }
  37.  
  38. function OnShootLeft(event : Event)
  39. {
  40. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation);
  41. bullet.RigidBody.Velocity = Real3(-10, 0, 0);
  42. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  43. }
  44.  
  45. function OnShootRight(event : Event)
  46. {
  47. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation);
  48. bullet.RigidBody.Velocity = Real3(10, 0, 0);
  49. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  50. }
  51.  
  52. function OnShootUpLeft(event : Event)
  53. {
  54. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation);
  55. bullet.RigidBody.Velocity = Real3(-this.DiagonalBulletSpeed, this.DiagonalBulletSpeed, 0);
  56. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  57. }
  58.  
  59. function OnShootUpRight(event : Event)
  60. {
  61. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation);
  62. bullet.RigidBody.Velocity = Real3(this.DiagonalBulletSpeed, this.DiagonalBulletSpeed, 0);
  63. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  64. }
  65.  
  66. function OnShootDownLeft(event : Event)
  67. {
  68. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation);
  69. bullet.RigidBody.Velocity = Real3(-this.DiagonalBulletSpeed, -this.DiagonalBulletSpeed, 0);
  70. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  71. }
  72.  
  73. function OnShootDownRight(event : Event)
  74. {
  75. var bullet = this.Space.CreateAtPosition(Archetype.PlayerBullet, this.Owner.Transform.Translation);
  76. bullet.RigidBody.Velocity = Real3(this.DiagonalBulletSpeed, -this.DiagonalBulletSpeed, 0);
  77. bullet.DamageOnCollide.Damage *= this.BulletDamageModifier;
  78. }
  79. }
Add Comment
Please, Sign In to add comment