Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PlayerController : ZilchComponent
- {
- sends ShootUp : ZilchEvent;
- sends ShootDown : ZilchEvent;
- sends ShootLeft : ZilchEvent;
- sends ShootRight : ZilchEvent;
- sends ShootUpRight : ZilchEvent;
- sends ShootUpLeft : ZilchEvent;
- sends ShootDownRight : ZilchEvent;
- sends ShootDownLeft : ZilchEvent;
- [Property]
- var MoveUp : Keys = Keys.W;
- [Property]
- var MoveDown : Keys = Keys.S;
- [Property]
- var MoveLeft : Keys = Keys.A;
- [Property]
- var MoveRight : Keys = Keys.D;
- [Property]
- var ShootUp : Keys = Keys.Up;
- [Property]
- var ShootDown : Keys = Keys.Down;
- [Property]
- var ShootLeft : Keys = Keys.Left;
- [Property]
- var ShootRight : Keys = Keys.Right;
- [Property]
- var MovementSpeed : Real = 0.0;
- [Property]
- var StandingSprite : SpriteSource = null;
- [Property]
- var WalkingSprite : SpriteSource = null;
- var DefaultShotSpeed : Real = 20.0;
- var ShotSpeedModifier : Real = 1.0;
- var ShotTimer : Real = 0;
- var TimerReset : Boolean = false;
- var BulletDamageMod : Real = 1.0;
- function Initialize(init : CogInitializer)
- {
- Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
- }
- function OnLogicUpdate(event : UpdateEvent)
- {
- this.TimerReset = false;
- if(this.ShotTimer > 0){
- this.ShotTimer -= 1;
- }
- var movement = Real3(0,0,0);
- var bulletAim = Real3(0,0,0);
- if(Zero.Keyboard.KeyIsDown(this.MoveUp)){
- movement += Real3(0.0, 1.0, 0.0);
- }
- if(Zero.Keyboard.KeyIsDown(this.MoveDown)){
- movement += Real3(0.0, -1.0, 0.0);
- }
- if(Zero.Keyboard.KeyIsDown(this.MoveRight)){
- movement += Real3(1.0, 0.0, 0.0);
- }
- if(Zero.Keyboard.KeyIsDown(this.MoveLeft)){
- movement += Real3(-1.0, 0.0, 0.0);
- }
- if(Zero.Keyboard.KeyIsDown(this.ShootUp)){
- if(this.ShotTimer <= 0){
- bulletAim += Real3(0.0, 1.0, 0.0);
- this.TimerReset = true;
- }
- }
- if(Zero.Keyboard.KeyIsDown(this.ShootDown)){
- if(this.ShotTimer <= 0){
- bulletAim += Real3(0.0, -1.0, 0.0);
- this.TimerReset = true;
- }
- }
- if(Zero.Keyboard.KeyIsDown(this.ShootLeft)){
- if(this.ShotTimer <= 0){
- bulletAim += Real3(-1.0, 0.0, 0.0);
- this.TimerReset = true;
- }
- }
- if(Zero.Keyboard.KeyIsDown(this.ShootRight)){
- if(this.ShotTimer <= 0){
- bulletAim += Real3(1.0, 0.0, 0.0);
- this.TimerReset = true;
- }
- }
- if(this.TimerReset){
- this.ShotTimer = this.DefaultShotSpeed * this.ShotSpeedModifier;
- }
- if(movement == Real3(0.0, 0.0, 0.0))
- {
- if(this.Owner.Sprite.SpriteSource != this.StandingSprite)
- {
- this.Owner.Sprite.SpriteSource = this.StandingSprite;
- }
- }
- else
- {
- if(this.Owner.Sprite.SpriteSource != this.WalkingSprite)
- {
- this.Owner.Sprite.SpriteSource = this.WalkingSprite;
- }
- this.Owner.Transform.Translation += movement * this.MovementSpeed * event.Dt;
- }
- if(bulletAim == Real3(1.0, 0.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootRight, ZilchEvent());
- }
- if(bulletAim == Real3(-1.0, 0.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootLeft, ZilchEvent());
- }
- if(bulletAim == Real3(0.0, 1.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootUp, ZilchEvent());
- }
- if(bulletAim == Real3(0.0, -1.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootDown, ZilchEvent());
- }
- if(bulletAim == Real3(1.0, 1.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootUpRight, ZilchEvent());
- }
- if(bulletAim == Real3(1.0, -1.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootDownRight, ZilchEvent());
- }
- if(bulletAim == Real3(-1.0, 1.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootUpLeft, ZilchEvent());
- }
- if(bulletAim == Real3(-1.0, -1.0, 0.0)){
- this.Owner.DispatchEvent(Events.ShootDownLeft, ZilchEvent());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement