Well. I suppose it is only the player code I need to show so yes I can show you the code.
package {
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;
import net.flashpunk.FP;
import net.flashpunk.Sfx;
import net.flashpunk.graphics.Spritemap;
public class Player extends Entity
{
private var power:Number=0.2;
private var jumpPower:Number=6;
private var hFriction:Number=0.95;
private var vFriction:Number=0.99;
private var xSpeed:Number=0;
private var ySpeed:Number=0;
private var onTheGround:Boolean=false;
private var gravity:Number=0.3;
[Embed(source = "../assets/soldier.png")] private const PLAYER:Class;
[Embed(source = "../assets/jump.mp3")] private const JUMP:Class;
public var jump:Sfx = new Sfx(JUMP);
public var soldier:Spritemap = new Spritemap(PLAYER, 27, 48);
public function Player()
{
soldier.add("left", [0, 1, 2, 3], 20, true);
soldier.add("riht", [4, 5, 6, 7], 20, true);
graphic=new Image(PLAYER);
setHitbox(28,47);
x=400;
y=225;
}
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 (collide("wall", x, y + 1))
{
onTheGround=true;
ySpeed=0;
if (Input.check(Key.UP))
{
ySpeed -= jumpPower;
jump.play();
}
} else {
ySpeed+=gravity;
}
if (Math.abs(xSpeed)<1&&! pressed) {
xSpeed=0;
}
xSpeed*=hFriction;
ySpeed*=vFriction;
adjustXPosition();
adjustYPosition();
}
private function adjustXPosition():void {
for (var i:int=0; i<Math.abs(xSpeed); i++) {
if (! collide("wall",x+FP.sign(xSpeed),y)) {
x+=FP.sign(xSpeed);
} else {
xSpeed=0;
break;
}
}
}
private function adjustYPosition():void {
for (var i:int=0; i<Math.abs(ySpeed); i++) {
if (! collide("wall",x,y+FP.sign(ySpeed))) {
y+=FP.sign(ySpeed);
} else {
ySpeed=0;
break;
}
}
}
}
}
Anyways any help would be much appreciated! Thanks.
EDIT: With the current code the whole sprite mad loads…So I have 8 of my player. lol