Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-13-2012, 09:18 AM   #1
SmudgeStudios
Smudge Studios
 
Join Date: Jun 2011
Location: United Kingdom
Posts: 8
Red face [AS3] Selecting an Enemies pose/animation

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.xthis.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

Last edited by SmudgeStudios; 07-13-2012 at 09:34 AM.
SmudgeStudios is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:49 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.