home *** CD-ROM | disk | FTP | other *** search
- class Player extends smashing.Renderable
- {
- var oBundle;
- var mcInvul;
- var upThrust = 1700;
- var sideThrust = 300;
- var r = 25;
- var xm = 0;
- var ym = 0;
- var ySpeedLimit = 500;
- var onSurface = false;
- var nHurtFlash = 0.1;
- var nHurtTime = 2;
- var bHurt = false;
- var cGerms = 0;
- var facing = 1;
- var floorMod = 50;
- var germScore = 100;
- var nInvul = 5;
- var cInvul = 0;
- var bInvul = false;
- var nSpeed = 0;
- var nSpeedBoost = 150;
- var nSpeedTime = 5;
- var cSpeedTime = 0;
- var nCrouchMod = 0;
- var nIdle = 3;
- var cIdle = 0;
- var sIdle = "";
- function Player()
- {
- var _loc1_ = this;
- super();
- _loc1_.update = _loc1_.updateGround;
- _loc1_.floorMod += _loc1_.r;
- smashing.Menu.watchProp(_loc1_,"cGerms","text");
- _loc1_.cGerms = 0;
- _loc1_.aIdle = ["wink","dance","foot tap"];
- }
- function get germs()
- {
- return this.cGerms;
- }
- function updateGround(nElapsed)
- {
- var _loc1_ = this;
- var nXm;
- var sState = "stand";
- var bCrouch = false;
- if(_loc1_.nSpeed == 1)
- {
- _loc1_.cSpeedTime += nElapsed;
- nXm = 0;
- if(Key.isDown(39))
- {
- nXm += nElapsed * (_loc1_.sideThrust + _loc1_.nSpeedBoost);
- _loc1_.faceRight();
- sState = "run";
- }
- if(Key.isDown(37))
- {
- nXm -= nElapsed * (_loc1_.sideThrust + _loc1_.nSpeedBoost);
- _loc1_.faceLeft();
- sState = "run";
- }
- if(_loc1_.cSpeedTime >= _loc1_.nSpeedTime)
- {
- _loc1_.unSpeed();
- }
- }
- else
- {
- nXm = 0;
- if(Key.isDown(39))
- {
- nXm += nElapsed * _loc1_.sideThrust;
- _loc1_.faceRight();
- sState = "run";
- }
- if(Key.isDown(37))
- {
- nXm -= nElapsed * _loc1_.sideThrust;
- _loc1_.faceLeft();
- sState = "run";
- }
- }
- if(Key.isDown(38))
- {
- _loc1_.ym -= _loc1_.upThrust * nElapsed;
- _loc1_.onSurface = false;
- }
- if(Key.isDown(40))
- {
- _loc1_.ym += _loc1_.upThrust * nElapsed;
- _loc1_.onSurface = false;
- bCrouch = true;
- }
- _loc1_.ym += smashing.Phys.gr * nElapsed;
- if(Math.abs(_loc1_.ym) > _loc1_.ySpeedLimit)
- {
- _loc1_.ym = _loc1_.ySpeedLimit * (_loc1_.ym / Math.abs(_loc1_.ym));
- }
- var clips = _loc1_.oGerms.oHandler.clips;
- var l = clips.length;
- var mcC;
- var r2;
- var dist = new smashing.Point(0,0);
- var i = 0;
- while(i < l)
- {
- mcC = clips[i];
- if(mcC != null)
- {
- if(mcC.grabbable == true)
- {
- dist.x = mcC.x - _loc1_.x;
- dist.y = mcC.y - _loc1_.y;
- r2 = Math.pow(_loc1_.r + mcC.r,2);
- if(dist.dot(dist) < r2)
- {
- mcC.react(_loc1_);
- }
- }
- }
- i++;
- }
- if(_loc1_.bInvul == false)
- {
- if(_loc1_.bHurt == false)
- {
- clips = _loc1_.oCitizens.oHandler.clips;
- l = clips.length;
- var mcC;
- i = 0;
- while(i < l)
- {
- mcC = clips[i];
- if(mcC != null)
- {
- if(mcC.bDead == false)
- {
- if(mcC.collisionTest(_loc1_) == true)
- {
- mcC.react(_loc1_,nElapsed);
- }
- }
- }
- i++;
- }
- }
- }
- else
- {
- _loc1_.cInvul += nElapsed;
- if(_loc1_.cInvul >= _loc1_.nInvul)
- {
- _loc1_.unInvulnerable();
- }
- }
- _loc1_.xm -= smashing.Phys.drag(_loc1_.xm,nElapsed);
- if(_loc1_.xm > -20)
- {
- _loc1_.xm = 0;
- }
- nXm += _loc1_.xm * nElapsed;
- var nYm = _loc1_.ym * nElapsed;
- _loc1_.shadow._x = _loc1_._x + nXm;
- _loc1_.shadow._y = _loc1_._y + nYm;
- var m = new smashing.Point(nXm,nYm);
- var p = new smashing.Point(_loc1_.x,_loc1_.y);
- clips = _loc1_.oBuildings.oHandler.clips;
- l = clips.length;
- var l2;
- var aLines;
- var aC = [];
- var _loc2_ = undefined;
- var bestResult = null;
- var aDebug = [];
- i = 0;
- while(i < l)
- {
- mcC = clips[i];
- if(mcC.hasObstacle == true)
- {
- if(mcC.hitTest(_loc1_) == true || mcC.hitTest(_loc1_.shadow) == true)
- {
- aLines = mcC.aLines;
- l2 = aLines.length;
- var _loc3_ = 0;
- while(_loc3_ < l2)
- {
- if(bCrouch == false)
- {
- _loc2_ = aLines[_loc3_].collisionPointSwept(p,m,_loc1_.r);
- }
- else if(!smashing.Misc.isHoriz(aLines[_loc3_]))
- {
- _loc2_ = aLines[_loc3_].collisionPointSwept(p,m,_loc1_.r);
- }
- aDebug.push(_loc2_);
- if(bestResult == null && _loc2_ != null)
- {
- bestResult = _loc2_;
- }
- else if(_loc2_.distSqu < bestResult.distSqu && _loc2_ != null)
- {
- bestResult = _loc2_;
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- }
- i++;
- }
- var bSurface = false;
- if(bestResult != null)
- {
- var actDist = Math.sqrt(bestResult.distSqu);
- m.length -= actDist;
- var normal = bestResult.gizmo.lineNormal;
- _loc1_.onSurface = true;
- bSurface = true;
- var pHit = new smashing.Point(bestResult.hit.x,bestResult.hit.y);
- _loc1_.x = pHit.x;
- _loc1_.y = pHit.y;
- p = new smashing.Point(_loc1_.x,_loc1_.y);
- m = normal.multiply(m.dot(normal));
- if(m.y == 0)
- {
- _loc1_.ym = 0;
- }
- if(m.x == 0)
- {
- _loc1_.xm = 0;
- }
- }
- p = new smashing.Point(_loc1_.x,_loc1_.y);
- var myFloor = BuildingHandler.floor - _loc1_.floorMod;
- if(_loc1_.y + m.y > myFloor)
- {
- _loc1_.y = myFloor;
- _loc1_.ym = 0;
- m.y = 0;
- _loc1_.onSurface = true;
- bSurface = true;
- if(bCrouch == true)
- {
- sState = "crouch";
- }
- }
- if(bSurface == false)
- {
- sState = "fly";
- }
- var myCeil = BuildingHandler.ceiling + _loc1_.r;
- if(_loc1_.y + m.y < myCeil)
- {
- _loc1_.ym = 0;
- m.y = 0;
- _loc1_.y = myCeil;
- }
- var myLeft = smashing.Viewport.halfWidth - _loc1_.r;
- if(_loc1_.x + m.x - smashing.Viewport.x < - myLeft)
- {
- _loc1_.x = smashing.Viewport.x - myLeft;
- m.x = 0;
- _loc1_.xm = 0;
- }
- if(_loc1_.x + m.x - smashing.Viewport.x > myLeft)
- {
- _loc1_.x = smashing.Viewport.x + myLeft;
- m.x = 0;
- _loc1_.xm = 0;
- }
- _loc1_.y += m.y;
- _loc1_.x += m.x;
- if(_loc1_.bHurt == true)
- {
- if(_loc1_.cHurt < _loc1_.nHurtTime / 2)
- {
- sState = "hit";
- }
- }
- if(sState == "stand")
- {
- _loc1_.cIdle += nElapsed;
- if(_loc1_.cIdle >= _loc1_.nIdle)
- {
- if(_loc1_.sIdle == "")
- {
- _loc1_.sIdle = _loc1_.aIdle[Math.floor(Math.random() * _loc1_.aIdle.length)];
- }
- sState = _loc1_.sIdle;
- }
- }
- else
- {
- _loc1_.cIdle = 0;
- _loc1_.sIdle = "";
- }
- _loc1_.a.gotoAndStop(sState);
- if(_loc1_.nSpeed == 1)
- {
- _loc1_.a.a.blur._visible = true;
- }
- else
- {
- _loc1_.a.a.blur._visible = false;
- }
- }
- function updateAir(nElapsed)
- {
- }
- function setBuilding(o, c, g)
- {
- var _loc1_ = this;
- _loc1_.oBuildings = o;
- _loc1_.oCitizens = c;
- _loc1_.oGerms = g;
- }
- function setShadow(mc)
- {
- var _loc1_ = this;
- _loc1_.shadow = mc;
- _loc1_.shadow._width = _loc1_.r * 2;
- _loc1_.shadow._height = _loc1_.r * 2;
- }
- function setBundle(o)
- {
- this.oBundle = o;
- }
- function render()
- {
- var _loc2_ = this;
- var _loc1_ = smashing.Viewport.getPos(_loc2_);
- _loc2_._x = _loc1_.x + smashing.Viewport.centerX;
- _loc2_._y = _loc1_.y + smashing.Viewport.centerY;
- }
- function hurt()
- {
- var _loc1_ = this;
- _global.oSound.playSnd("hit");
- var _loc2_ = new smashing.Point(-3,-2);
- _loc2_.length = 700;
- _loc1_.xm = _loc2_.x;
- _loc1_.ym = _loc2_.y;
- _loc1_.bHurt = true;
- _loc1_.nStartHurt = getTimer();
- _loc1_.onEnterFrame = function()
- {
- var _loc1_ = this;
- _loc1_.cHurt = (getTimer() - _loc1_.nStartHurt) / 1000;
- if(_loc1_.cHurt >= _loc1_.nHurtTime)
- {
- _loc1_.bHurt = false;
- delete _loc1_.onEnterFrame;
- }
- };
- }
- function invulnerable()
- {
- this.bInvul = true;
- this.mcInvul._visible = true;
- }
- function unInvulnerable()
- {
- var _loc1_ = this;
- _loc1_.bInvul = false;
- _loc1_.cInvul = 0;
- _loc1_.mcInvul._visible = false;
- }
- function speed()
- {
- this.nSpeed = 1;
- }
- function unSpeed()
- {
- this.nSpeed = 0;
- this.cSpeedTime = 0;
- }
- function getGerm(g)
- {
- var _loc1_ = this;
- _global.oSound.playSnd("getGerm");
- g.handler.removeClip(g);
- _loc1_.cGerms = _loc1_.cGerms + 1;
- _loc1_.oBundle.setGerms(_loc1_.cGerms);
- MaggieWorld.addScore(_loc1_.germScore);
- _loc1_.a.a.a.head.gotoAndPlay("gather");
- }
- function removeGerm()
- {
- var _loc1_ = this;
- _loc1_.cGerms = _loc1_.cGerms - 1;
- if(_loc1_.cGerms < 0)
- {
- _loc1_.cGerms = 0;
- }
- else
- {
- _global.oSound.playSnd("loseGerm");
- _loc1_.oGerms.addGerm(_loc1_.oBundle.x,_loc1_.oBundle.y,"mcFlyAwayGerm");
- }
- _loc1_.oBundle.setGerms(_loc1_.cGerms);
- }
- function reset()
- {
- var _loc1_ = this;
- _loc1_.a.gotoAndStop("stand");
- _loc1_.x = smashing.Viewport.x - _loc1_.oWorld.playerOffset;
- _loc1_.y = BuildingHandler.floor - _loc1_.r * 3;
- _loc1_.cGerms = 0;
- _loc1_.oBundle.setGerms(_loc1_.cGerms);
- _loc1_.bHurt = false;
- delete _loc1_.onEnterFrame;
- _loc1_._visible = true;
- _loc1_.xm = 0;
- _loc1_.ym = 0;
- _loc1_.faceRight();
- _loc1_.render();
- }
- function faceLeft()
- {
- this.gotoAndStop("left");
- this.facing = -1;
- }
- function faceRight()
- {
- this.gotoAndStop("right");
- this.facing = 1;
- }
- }
-