I am involved with my classmates in college in programing a platformer game and need help in writing and understanding the code form basic enemy AI such as that of a green turtle in Mario Bros. I am trying to get my enemy to just have simple ground movement that changes direction when the enemy bumps into a wall and the enemy falling down into a pit and being destroyed if it walks over the edge. For our game we are programming using separate file packages instead of writing on the fla file directly so we can work parts of code separately. I have been unable to find any tutorials on this subject that that fits with my situation and am still new to this type of programing.
These are the 2 files I have coded so far.
The main game file:
package
{
import flash.display.MovieClip;
public class game_enTest extends MovieClip
{
public var eraser:eraser_en;
public function inkman_enTest()
{
eraser = new eraser_en;
addChild( eraser );
}
}
}
The enemy file:
package
{
import flash.display.MovieClip;
public class eraser_en extends MovieClip
{
public function onLoad(startx:Number, starty:Number)
{
x= startx_en;// Variables for enemy starting place.
y= starty_en;
}
public function onEnterFrame():void
{
x+=3;// Initial movement
if(this.hitTest(_root.block))// Movement change due to block collision.
{
x*=-1;// Multiplying by negative will switch whatever direction it hits the block from
}
// This is for the event of a pit the enemy falls into.
if (y=stage.stageHeight+100)// stage.stageHeight is the value of the bottom part of the stage screen.
{
this.removeMovieClip();
}
if (this.hitTest(_root.explosion))// If enemy is in contact with bomb explosion
{
death();// Run death function
}
}
public function death();// This is the function that when called up will enable enemy death and removal.
{
this.removeMovieClip();
}
}
}
Any help would be greatly appreciated.