package {
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Spritemap;
import net.flashpunk.graphics.Text;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;
public class Pinco extends Entity {
private var power:Number=0.2;
private var jumpPower:Number=10;
private var hFriction:Number=0.95;
private var vFriction:Number=0.99;
private var xSpeed:Number=0;
private var ySpeed:Number=0;
private var gravity:Number=0.3;
private var isJumping:Boolean=false;
private var doubleJump:Boolean = false;
private var hitted:Boolean = false;
[Embed(source = "../assets/pinco.png")] private const PINCO:Class;
public var sprPinco:Spritemap = new Spritemap(PINCO, 54, 37.2);
public function Pinco () {
setHitbox(54,37.2);
x = 40;
y = 460;
type = 'player';
sprPinco.add('fermo', [0, 1, 2, 3, 4, 5], 13, true);
sprPinco.add('corsa', [6, 7, 8, 9, 10, 11], 20, true);
sprPinco.add('corsa_sx', [12, 13, 14, 15, 16, 17], 20, true);
sprPinco.add('attacca', [18, 19], 20, false);
sprPinco.add('salto', [20, 21], 20, false);
sprPinco.add('morte', [30, 31, 32, 33, 34, 35], 20, false);
graphic = sprPinco;
sprPinco.play('fermo');
}
override public function update():void {
var pressed:Boolean=false;
if (Input.check(Key.LEFT)) {
xSpeed-=power;
pressed=true;
}
if (Input.check(Key.RIGHT)) {
xSpeed+=power;
pressed=true;
}
if(!Input.check(Key.UP) && isJumping){
doubleJump=true;
}
if(Input.check(Key.UP) && doubleJump && isJumping){
ySpeed=-jumpPower;
isJumping=false;
doubleJump=false;
}
if (collide("Muro",x,y+1)) {
ySpeed=0;
isJumping=false;
if (Input.check(Key.UP)) {
ySpeed=-jumpPower;
isJumping=true;
}
} else {
ySpeed+=gravity;
}
if (Math.abs(xSpeed)<1&&! pressed) {
xSpeed=0;
}
xSpeed*=hFriction;
ySpeed*=vFriction;
moveBy(xSpeed,ySpeed,"Muro");
if(xSpeed>0 || Input.pressed(Key.RIGHT)){
sprPinco.play("corsa");
}
if(xSpeed<0 || Input.pressed(Key.LEFT)){
sprPinco.play("corsa_sx");
}
if(xSpeed==0 || Input.released(Key.RIGHT) || Input.released(Key.LEFT)){
sprPinco.play("fermo");
}
}
//the truble start here! The collide function doesn't work
if (collide('D_Muro', x, y) || collide('Enemy', x, y))
{
hitted = !hitted;
if (!hitted)
{
sprPinco.play('morte');
FP.world = new W_GameO();
}
}
/*}
override public function moveCollideX(e:Entity):void {
xSpeed = 0;
}
override public function moveCollideY(e:Entity):void {
ySpeed = 0;
}
*/
} }
The strange thing is that the function collide before my comment work properly!