PDA

View Full Version : Need help with programming an enemy for a platformer.



ferretg
May 30th, 2010, 01:38 PM
I am trying to make an enemy for a side-scrolling platformer game that is similar to the green turtle in Super Mario. It needs to go 1 direction 1st then either turn when hitting a wall or fall if it walks over the edge. I am programming using separate as files connected together and so far have come up with the following code files.

enemy_test.as:

package
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class inkman_enTest extends MovieClip
{

public var Enemy:enemy;
public var walls:Array;
public var gtimer:Timer;
public function inkman_enTest()
{
walls = new Array();
Enemy = new enemy();
addChild( Enemy );

gtimer= new Timer(25);
gtimer.addEventListener(TimerEvent.TIMER, gameLoop);
gtimer.start();
}

function gameLoop(loop:TimerEvent):void
{
Enemy.en_move();
}
}
}

enemy.as:

package
{
import flash.display.MovieClip;
public class enemy extends MovieClip
{
public function en_start()
{
x= 100; // Variables for enemy starting place.
y= 10;//
}
public function en_move():void
{
this.x +=3;// Initial movement

}
}
}

wall.as:

package
{
import flash.display.MovieClip;
public class Wall extends MovieClip
{
public var WIDTH:int = 32;

public var HEIGHT:int = 32;

}

}

Any help would be appreciated. If not can I you point me to a website or forum where I can get more information. Thanks.

dandylion13
May 30th, 2010, 05:20 PM
Could you explain how it's working or not working?

ferretg
May 31st, 2010, 02:12 PM
Well right now now it has the enemy object appear on the 0,0 x/y coordinates on the stage even though I have it set in the enemy.as to appear on 100x and 10y, . Since I am mainly programming the A.I. of the enemy and not the whole game I have a small stage of 400 x 200 pixels but I don't think that's the problem of where the enemy is placed.

Right now the enemy will only travel in a straight line to the left so I got that part completed, ideally what I am also trying to accomplish is for the enemy to move the opposite direction when hitting a wall object and falling when not detecting any wall object below it.

I realize that I will have to set up the enemy as an array object so I can place as many instances of it that are needed in the various game stages but I anm at a loss of how to program this.

ferretg
June 11th, 2010, 04:01 PM
Is there anyone who can help at all or point me to another resource or forum that could help?

therobot
June 12th, 2010, 01:57 AM
Is there anyone who can help at all or point me to another resource or forum that could help?

http://www.tonypa.pri.ee/tbw/tut09a.html

It seems to me that you are probably having a hard time coming up with a solution because you don't have a very good system in place for solving problems like this. Allow me to suggest then a tile based approach.

http://www.tonypa.pri.ee/tbw/tut09a.html

is what you're looking for. start at the first tutorial and work your way up and this problem shouldn't be too difficult

DrRobot
July 11th, 2010, 05:38 PM
You don't call the en_start() function anywhere, so it's no wonder that when you add the enemy to the stage it's at the origin. And where are your constructors?