Hey
I've been working on this game for a while now and for the past 3 weeks I've been stuck on this problem. I'm trying to animate my enemy, but the code for working out which pose the enemy should be in doesn't work.
Currently all it does is stay on the jumping animations all the time.
I want it to select the Jump pose when in the air, the walk pose when it's moving on the floor, and the stand pose when it's on the floor and not moving.
This is the complete code for my enemy:
The part at the bottom is the selecting pose part but I included the whole code so that you could see if it was something else that was wrong.
ActionScript Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Sprite;
public class enemy extends MovieClip {
//variables
private var speedX=0;
private var speedY=0;
private var jump=false;
private var canJump=false;
var pose="standR";
public function enemy() {
// constructor code
trace("Made an enemy");
visible=false;
}
function update(){
//Actual ai bit
var block:Boolean=false;
var yDistance:Number = MovieClip(parent).player_hitbox.y - this.y;
var xDistance:Number = MovieClip(parent).player_hitbox.x - this.x;
if (MovieClip(parent).player_hitbox.y < this.y+350 && MovieClip(parent).player_hitbox.y > this.y-350){
if (MovieClip(parent).player_hitbox.x < this.x+320 && MovieClip(parent).player_hitbox.x > this.x-320){
if(xDistance < - MovieClip(parent).player_hitbox.width/2 - this.width/2 - 100)
{
speedX=-8.5;
this.x += speedX;
}
else if(xDistance > + MovieClip(parent).player_hitbox.width/2 + this.width/2 + 100)
{
speedX=8.5;
this.x += speedX;
}
else{
speedX=0;
}
if(MovieClip(parent).DoingJump && !MovieClip(parent).sliding){
jump=true;
}
}
else{
speedX=0;
}
}
else{
speedX=0;
}
//sidewards hit tests
var level = MovieClip(parent).level;
for (var i=0;i<level.length;i++) {
if (this.getRect(parent).intersects(level[i])) {
if (speedX > 0) { //moving right
this.x = +level[i].left-this.width/2;
jump=true;
}
if (speedX < 0) { //moving left
this.x = level[i].right+this.width/2;
jump=true;
}
}
}
//shizzle
speedY+=1;
this.y+=speedY;
//hit tests
for (i=0;i<level.length;i++) {
if (this.getRect(parent).intersects(level[i])) {
if (speedY > 0) { //moving down
this.y = level[i].top-this.height/2;
speedY=0;
canJump=true;
}
if (speedY < 0) { //moving up
this.y = level[i].bottom+this.height/2;
speedY*=-0.5;
canJump=false;
}
}
}
if (speedY > 0) { //moving down
canJump=false;
}
if (jump && canJump){
speedY-=2;
jump=false;
}
if (speedY==-13){
MovieClip(parent).DoingJump=false;
}
if (jump && canJump && speedX>0){
pose="WalkR"
}
if (jump && canJump && speedX<0){
pose="WalkL"
}
if (!jump || !canJump || (!jump && !canJump)){
if (MovieClip(parent).player_hitbox.x<this.x){
pose="JumpL";
}
else{
pose="JumpR";
}
}
if (jump && canJump && speedX==0){
if (MovieClip(parent).player_hitbox.x<this.x){
pose="standL";
}
else{
pose="standR";
}
}
trace(pose);
}
}
}
Any help would be wonderful.
Thank you
Smudge