Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MosePlayerControler : ZilchComponent
- {
- [Property]
- var Bullet : Archetype = Archetype.Find("Bullet");
- [Property]
- var Accel : Real = 1.0;
- [Property]
- var MaxVelocity : Real = 15.0;
- function Initialize(init : CogInitializer)
- {
- Zero.Connect(this.Space, Events.MouseMove, this.OnMouseMove);
- Zero.Connect(this.Space, Events.LeftMouseDown, this.OnLeftMouseDown);
- Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
- Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
- }
- function OnLogicUpdate(event : UpdateEvent)
- {
- var movement = local Real3(0.0, 0.0, 0.0);
- var forwardDirection = this.Owner.Orientation.WorldForward;
- if(Zero.Keyboard.KeyIsDown(Keys.W))
- {
- movement += forwardDirection;
- }
- this.Owner.RigidBody.Velocity += movement * event.Dt * this.Accel;
- }
- function OnLeftMouseDown(event : ViewportMouseEvent)
- {
- this.Shoot();
- }
- function OnMouseMove(event : ViewportMouseEvent)
- {
- var mousePositon = event.ToWorldZPlane(0);
- //this.Owner.Transform.Translation = mousePositon;
- if(this.Owner.Transform.Translation != mousePositon)
- {
- this.Owner.Orientation.LookAtPointWithUp(mousePositon, this.Owner.Orientation.WorldUp);
- }
- if(Zero.Keyboard.KeyIsDown(Keys.Space))
- {
- this.Shoot();
- }
- }
- function Shoot()
- {
- var spawnLocation = this.Owner.Transform.Translation + this.Owner. Orientation.WorldForward;
- var bullet = this.Space.CreateAtPosition(this.Bullet, spawnLocation); bullet.RigidBody.Velocity = this.Owner.Orientation.WorldForward * 10;
- }
- function OnCollisionStarted(event : CollisionEvent)
- {
- Console.WriteLine("Colodeded");
- if(event.OtherObject.Name == "Space Rock")
- {
- this.Space.ReloadLevel();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement