home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 145
/
MOBICLIC145.ISO
/
pc
/
DATA
/
DSS145
/
DSS145_12
/
DSS145_12.swf
/
scripts
/
dss145_12
/
Perso.as
< prev
next >
Wrap
Text File
|
2012-07-19
|
11KB
|
347 lines
package dss145_12
{
import flash.display.MovieClip;
public class Perso
{
public static const REST_RIGHT:String = "E1";
public static const REST_LEFT:String = "E2";
public static const WALK_RIGHT:String = "E3";
public static const WALK_LEFT:String = "E4";
public static const UPSTAIRS_STOP:String = "upstairs_stop";
public static const GO_UP:String = "E5";
public static const GO_DOWN:String = "E5";
public static const CRAWL_RIGHT:String = "E7";
public static const CRAWL_LEFT:String = "E8";
public static const JUMP_INPLACE_RIGHT:String = "E9";
public static const JUMP_INPLACE_LEFT:String = "E10";
public static const DUCK_RIGHT:String = "E11";
public static const DUCK_LEFT:String = "E12";
public static const JUMP_RIGHT:String = "E13";
public static const JUMP_LEFT:String = "E14";
public static const FALL_RIGHT:String = "E15";
public static const FALL_LEFT:String = "E16";
public static const FALL_END_RIGHT:String = "fall_end_right";
public static const FALL_END_LEFT:String = "fall_end_left";
public static const JUMP_END:String = "jump_end";
public var invincible:Boolean = false;
public var clip:MovieClip;
public var distanceSol:Number = 67;
public var distanceSolFall:Number = 40;
public var xOriginal:Number = 0;
public var yOriginal:Number = 0;
public var x:Number = 0;
public var y:Number = 0;
public var speed:Number = 4;
public var speedX:Number = 0;
public var speedY:Number = 0;
public var DECOR:Decor;
public var state:String = "E1";
public var directionLast:String = "right";
public var direction:String = "none";
private var zoneHit:HitZone;
private var colorHit:uint;
private var actif:Boolean = true;
public var isJumping:Boolean = false;
public var isFalling:Boolean = false;
public var isArrivedToEnd:Boolean = false;
public function Perso(param1:Decor, param2:MovieClip)
{
super();
this.clip = param2;
this.DECOR = param1;
this.x = this.xOriginal = this.clip.x;
this.y = this.yOriginal = this.clip.y;
}
public function reset() : void
{
this.x = this.xOriginal;
this.y = this.yOriginal;
this.state = Perso.REST_RIGHT;
this.clip.STATE.gotoAndStop("E1");
this.directionLast = "right";
this.isJumping = false;
this.isFalling = false;
this.actif = true;
}
public function resetContinue() : void
{
this.y = this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol;
this.state = Perso.REST_RIGHT;
this.clip.STATE.gotoAndStop("E1");
this.directionLast = "right";
this.isJumping = false;
this.isFalling = false;
this.actif = true;
}
public function move(param1:Object) : void
{
if(this.actif)
{
this.speedX = this.speedY = 0;
if(param1.left)
{
this.speedX -= this.speed;
}
if(param1.right)
{
this.speedX += this.speed;
}
if(param1.up)
{
this.speedY -= this.speed;
}
if(param1.down)
{
this.speedY += this.speed;
}
this.colorHit = this.DECOR.getColorOnDecor(this.x + this.speedX,this.y + this.speedY);
if(this.colorHit == 0)
{
this.speedX = this.speedY = 0;
this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
}
else if(this.colorHit == ColorZones.OUTPUT)
{
this.speedX = this.speedY = 0;
this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
this.isArrivedToEnd = true;
}
else if(this.colorHit == ColorZones.FREE_HORIZONTAL)
{
this.speedY = 0;
this.y = this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol;
if(this.speedX != 0)
{
if(param1.down)
{
this.state = this.speedX > 0 ? Perso.CRAWL_RIGHT : Perso.CRAWL_LEFT;
}
else if(param1.up)
{
this.speedX *= 1.5;
this.state = this.directionLast == "right" ? Perso.JUMP_RIGHT : Perso.JUMP_LEFT;
}
else
{
this.state = this.speedX > 0 ? Perso.WALK_RIGHT : Perso.WALK_LEFT;
}
}
else if(param1.up)
{
this.state = this.directionLast == "right" ? Perso.JUMP_INPLACE_RIGHT : Perso.JUMP_INPLACE_LEFT;
}
else if(param1.down)
{
this.state = this.directionLast == "right" ? Perso.DUCK_RIGHT : Perso.DUCK_LEFT;
}
else
{
this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
}
}
else if(this.colorHit == ColorZones.LOW_CEILING)
{
if(this.speedX != 0)
{
if(param1.down == false && this.state != Perso.CRAWL_LEFT && this.state != Perso.CRAWL_RIGHT)
{
this.speedX = 0;
}
else
{
this.state = this.speedX > 0 ? Perso.CRAWL_RIGHT : Perso.CRAWL_LEFT;
}
}
else if(param1.down == true || this.state == Perso.CRAWL_LEFT || this.state == Perso.CRAWL_RIGHT)
{
this.state = this.directionLast == "right" ? Perso.CRAWL_RIGHT : Perso.CRAWL_LEFT;
}
this.speedY = 0;
}
else if(this.colorHit == ColorZones.UPSTAIRS_EXTREMITY_TOP)
{
if(param1.up)
{
this.state = Perso.GO_UP;
}
else if(param1.down)
{
if(this.state == Perso.CRAWL_LEFT || this.state == Perso.CRAWL_RIGHT)
{
this.speedY += 40;
}
this.state = Perso.GO_DOWN;
}
else if(param1.left)
{
if(param1.down)
{
this.state = Perso.CRAWL_LEFT;
}
else
{
this.state = Perso.WALK_LEFT;
}
}
else if(param1.right)
{
if(param1.down)
{
this.state = Perso.CRAWL_RIGHT;
}
else
{
this.state = Perso.WALK_RIGHT;
}
}
else
{
this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
}
}
else if(this.colorHit == ColorZones.UPSTAIRS_EXTREMITY_BOTTOM)
{
if(param1.up)
{
this.state = Perso.GO_UP;
}
else if(param1.down)
{
if(this.state == Perso.CRAWL_LEFT || this.state == Perso.CRAWL_RIGHT || this.y >= this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol && (this.state == Perso.DUCK_LEFT || this.state == Perso.DUCK_RIGHT))
{
this.y = this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol;
this.state = this.directionLast == "right" ? Perso.DUCK_RIGHT : Perso.DUCK_LEFT;
}
else
{
this.state = Perso.GO_DOWN;
}
}
else if(param1.left)
{
if(param1.down)
{
this.state = Perso.CRAWL_LEFT;
}
else
{
this.state = Perso.WALK_LEFT;
}
}
else if(param1.right)
{
if(param1.down)
{
this.state = Perso.CRAWL_RIGHT;
}
else
{
this.state = Perso.WALK_RIGHT;
}
}
else
{
this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
}
}
else if(this.colorHit == ColorZones.UPSTAIRS)
{
this.speedX = 0;
if(param1.up)
{
this.state = Perso.GO_UP;
}
else if(param1.down)
{
this.state = Perso.GO_DOWN;
}
else
{
this.state = Perso.UPSTAIRS_STOP;
}
}
else if(this.colorHit == ColorZones.HOLE)
{
this.speedY = 0;
if(this.isJumping == false)
{
this.actif = false;
this.isFalling = true;
}
}
}
if(this.isFalling)
{
if(this.DECOR.getColorOnDecor(this.x,this.y + this.distanceSolFall) == 0)
{
this.speedX = this.speedY = 0;
this.state = this.directionLast == "right" ? Perso.FALL_END_RIGHT : Perso.FALL_END_LEFT;
}
else
{
this.speedX = 0;
this.speedY = 2;
this.state = this.directionLast == "right" ? Perso.FALL_RIGHT : Perso.FALL_LEFT;
}
}
this.x += this.speedX;
this.y += this.speedY;
if(this.speedX != 0)
{
this.directionLast = this.speedX > 0 ? "right" : "left";
}
}
public function redraw() : void
{
}
}
}