gatsby /game/engine/actors/weapons/GoldHatProjectile.as

Language ActionScript Lines 150
MD5 Hash 1d4992b30ce0bbfd701b06a7f8a96952
Repository https://bitbucket.org/charliehoey/gatsby View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package engine.actors.weapons {
    
    import engine.IObserver;
    import engine.actors.Actor;
	import engine.Scoreboard;
    import engine.actors.player.Hero;
    import engine.actors.enemies.*;
    import engine.actors.geoms.*;
    import flash.events.Event;
    import engine.actors.Animatable;
    import engine.actors.weapons.Projectile;
    
    public class GoldHatProjectile extends Projectile implements IObserver {
        
        private var returning:Boolean = false;
        private var throwDistance:int = 30;
        protected var flySpeed:Number = 8;
        private var inertia:Number = 2.5; // amount of inertia to change velocity
		private var scoreboard:Scoreboard = Scoreboard.getInstance();

		private var successiveHits = 0;
        
        public function GoldHatProjectile(owner) {
            super(owner);
        }
		
		override public function setup() {
		    
		    damage = 1;
		    
		    myName = "GoldHatWeapon";
            mySkin = "GoldHatWeaponSkin";
		    
		    tilesWide = 1;
    		tilesTall = 1;
		    collide_left = 2; // what pixel do we collide on on the left
    		collide_right = 14; // what pixel do we collide on on the right
    		
    		startFrame = 0; // the first frame to loop on
            endFrame = 3; // the final frame in the row
            nowFrame = 0; // current frame in row
            loopFrame = 0; // frame at which to loop
            loopType = 1; // 0 loops, 1 bounces
            loopRow = 0; // which row are we on
            loopDir = 1; // loop forward (to the right) by default
            speed = 5; // how many frames should go by before we advance
    		velx = 0;
    		vely = 0;
    		if(vecx > 0) {
    		    throwHat(false);
    		} else {
    		    throwHat(true);
    		}
		}
				
		override public function notify(subject):void {
		    if(checkCollision(subject)) {
		        if(subject is Enemy || subject is EnemyWalker) {
					if(subject.getHP() > 0) {
						successiveHits++;
						scoreboard.setMultiplier(successiveHits);
						subject.receiveDamage(this);
			            if(!returning) {
			                returning = true;
			                velx = -velx;
			            }
					}
		        } else if(subject is Hero && returning) {
					successiveHits = 0;
					scoreboard.setMultiplier(1);
					this.isDead = true;
		        }
            }
		}
		
		public function throwHat(goingLeft) {
		    frameCount = 0;
		    frameDelay = throwDistance;
		    if(goingLeft) {
    		    velx = -flySpeed;
    		} else {
    		    velx = flySpeed;
    		}
            vely = 0;
    		returning = false;
		}
		
		private function flyBack() {
		    if(owner.x >= this.x) {
		        velx += inertia;
		    } else {
		        velx -= inertia;
		    }

		    if(velx >= flySpeed) {
		       velx = flySpeed; 
		    } else if(velx <= -flySpeed) {
		       velx = -flySpeed;
		    }
		    
		    if(owner.y >= this.y) {
		        vely += inertia;
		    } else {
		        vely -= inertia;
		    }

		    if(vely >= flySpeed) {
		       vely = flySpeed; 
		    } else if(vely <= -flySpeed) {
		       vely = -flySpeed;
		    }
		}
		
		override public function update():void {
		    animate();
		    
		    if(frameCount >= frameDelay) {
		        frameCount = 0;
		        if(!returning) {
		            returning = true;
    		    } else {
    		        flyBack();
    		    }
    		    frameDelay = 2;
		    } else {
		        frameCount++;
		    }
		    
		    this.y += vely / 2; // update our y variable
            this.x += velx / 2; // update our x variable
			/*
			if(velx > 0) {
			    this.x = Math.ceil(this.x);
			} else {
			    this.x = Math.floor(this.x);
			}
			
			if(vely > 0) {
			    this.y = Math.ceil(this.y);
			} else {
			    this.y = Math.floor(this.y);
			}
		    */
		    notifyObservers();
		    
		}
        
    }
    
}
Back to Top