1Game.addToManifest({ 2 face_angry: "sprites/peeps/face_angry.json", 3 body_red: "sprites/peeps/body_red.json", 4 5 shout: "sounds/shout.mp3" 6}); 7 8/**** 9 10FRAMES: 1100-05: frown at screen 1206-10: anger awayyyyyy! 1311-25: SHOUT! // loop back to 10. (>=20, no, not screaming) 14 15****/ 16 17function AngryPeep(scene, type){ 18 19 var self = this; 20 Peep.apply(self, [scene]); 21 self._CLASS_ = "AngryPeep"; 22 23 // Add the body & face sprites 24 var g = self.graphics; 25 self.bodyMC = self.addMovieClip("body"); 26 self.bodyRedMC = self.addMovieClip("body_red"); 27 self.bodyRedMC.alpha = 0; 28 self.faceMC = self.addMovieClip("face_angry"); 29 self.faceMC.anchor.x = 0.333333333; 30 self.faceMC.gotoAndStop(0); 31 32 // Set Type: Am I a circle or square? 33 self.type = "???"; 34 self.setType = function(type){ 35 self.type = type; 36 self.bodyMC.gotoAndStop((type=="circle") ? 0 : 1); 37 self.bodyRedMC.gotoAndStop(self.bodyMC.currentFrame); 38 }; 39 self.setType(type); 40 41 // IS SHOUTING? 42 self.isShouting = false; 43 44 // Animate on triples 45 var doubles = 0; 46 var MODE = -1; 47 var MODE_STARE = 0; 48 var MODE_BLINK = 1; 49 var MODE_SHOUT = 2; 50 self.gracePeriod = -1; 51 52 // HACK 53 self.HACK_JUMPSTART = function(){ 54 MODE = MODE_BLINK; 55 }; 56 57 // WANDERING 58 self.wander = 0; 59 self.changeWander = function(){ 60 self.wander = Math.random()*0.1-0.05; 61 }; 62 63 self.callbacks.update = function(){ 64 65 // Animate on doubles! ...or... TRIPLES? 66 doubles = (doubles+1)%3; 67 68 // Wander around 69 self.direction += self.wander; 70 if(Math.random()<0.05) self.changeWander(); 71 self.stayWithinRect({ 72 l:100, r:860, t:100, b:480 73 },0.15); 74 75 // FRAMES: MANUALLY 76 var face = self.faceMC; 77 var frame = face.currentFrame; 78 if(doubles==0){ 79 switch(MODE){ 80 case MODE_STARE: 81 if(frame<5) face.gotoAndStop(frame+1); 82 break; 83 case MODE_BLINK: 84 if(frame<10){ 85 face.gotoAndStop(frame+1); 86 } 87 break; 88 case MODE_SHOUT: 89 if(frame<25){ 90 face.gotoAndStop(frame+1); 91 }else{ 92 face.gotoAndStop(10); 93 MODE = MODE_BLINK; 94 self.isShouting = false; 95 self.startWalking(); 96 } 97 break; 98 } 99 } 100 101 if(frame>=10){ 102 self.bodyRedMC.alpha = self.bodyRedMC.alpha*0.9 + 1*0.1; 103 } 104
105 /////////////////////////// 106 /////////////////////////// 107 /////////////////////////// 108 109 // Less red bod... 110 // self.bodyRedMC.alpha *= 0.985; 111 112 // Scream at THE OPPOSITE TYPE 113 // Grace period... AND IF SCENE ALLOWS IT. 114 if(self.gracePeriod<=0 && !scene.noYellingYet){ 115 var opposite = (self.type=="circle") ? "square" : "circle"; 116 var closeTo = self.touchingPeeps(90, function(peep){ 117 return(!peep.offended && peep.isWalking && peep.type==opposite); 118 }); 119 if(self.isWalking && closeTo.length>0){ 120 121 var other = closeTo[0]; 122 123 // Bounce TOWARDS 124 self.flip = (other.x>self.x) ? 1 : -1; 125 self.bounce = 1.7; 126 self.vel.y = 0; 127 self.vel.x = 3*self.flip; 128 129 // BE SHOCKED 130 MODE = MODE_SHOUT; 131 132 self.isWalking = false; 133 self.isShouting = true; 134 135 // AHHHHH 136 var peeps = scene.world.peeps; 137 var angry = peeps.filter(function(peep){ 138 return(peep._CLASS_=="AngryPeep"); 139 }); 140 var angryNum = angry.length; 141 var volume; 142 if(angryNum<5) volume=1; 143 else if(angryNum<10) volume=0.70; 144 else if(angryNum<15) volume=0.42; 145 else volume=0.27; 146 var shout = Game.sounds.shout; 147 shout.volume(volume); 148 shout.play(); 149 150 // MAKE BOD REDDER 151 // self.bodyRedMC.alpha = 1; 152 153 // GRACE... 154 self.gracePeriod = _s(2.5); 155 156 // If the closeTo is ANOTHER ANGRY ONE. 157 // They get confused! 158 if(other._CLASS_=="NormalPeep"){ 159 if(other.shocked) return; 160 other.vel.x = self.flip*5; 161 other.flip = -1*self.flip; 162 other.beShocked(self); 163 }else{ 164 // nothing...? 165 } 166 167 } 168 }else{ 169 self.gracePeriod--; 170 } 171 172 }; 173 174 // WEIRD WALK 175 self.walkAnim = function(){ 176 177 // Hop & flip 178 self.hop += self.speed/40; 179 if(self.hop>1) self.hop--; 180 self.flip = (self.vel.x<0) ? -1 : 1; 181 182 // Hop up & down 183 var t = self.hop*Math.TAU; 184 g.pivot.y = Math.abs(Math.sin(t))*15; 185 g.rotation = 0; 186 187 // Squash at the bottom of your cycle 188 if(self._lastHop<0.5 && self.hop>=0.5) self.bounce = 1.2; 189 if(self._lastHop>0.9 && self.hop<=0.1) self.bounce = 1.2; 190 191 }; 192 self.callbacks.startWalking = function(){ 193 self.speed = 1.7; 194 }; 195 self.callbacks.startWalking(); 196 197 // AT FIRST... 198 self.watchTV = function(){ 199 200 self.clearAnims(); // just in case... 201 202 // 0) Stop & look 203 var tv = scene.tv; 204 self.stopWalking(true); 205 self.flip = (tv.x>self.x) ? 1 : -1; 206 var OFFSET = (Math.abs(self.x-tv.x)-60)/100; 207 var WAIT = Director.ZOOM_OUT_1_TIME + Director.SEE_VIEWERS_TIME; 208 209 // 1) Become frowny 210 self.setTimeout(function(){ 211 212 self.bounce = 1.6; 213 MODE = MODE_STARE; 214 215 // SQUEAK 216 Game.sounds.squeak.play(); 217 218 },_s(BEAT*2+OFFSET)); 219 220 // 2) Blink... 221 self.setTimeout(function(){ 222 self.bounce = 1.3; 223 MODE = MODE_BLINK; 224 },_s(WAIT+OFFSET)); 225 226 // 3) And go on. 227 self.setTimeout(function(){ 228 // self.bounce = 1.2; 229 self.startWalking(); 230 },_s(WAIT+1+OFFSET)); 231 232 }; 233 234}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.