Enemy Behaviour
I am currently programming a 2D platform game (like super mario bros). But i am having problems with the enemies. So far i have been able to put an enemy in the game but i can't get it to move.
Enemy class
publicclass Enemyextends GameComponet//class attributes
{
privatefinalint walk_x_speed = 2;
privatefinalint fall_y_speed = 2;
privateint x_pos_left;
privateint x_pos_right;
privateint y_pos_up;
privateint y_pos_down;
// Counter for jumping and animation
privateint jump_counter;
privateint picture_counter;
privateint step_counter;
privateboolean falling;
privateboolean walking_left;
privateboolean walking_right;
privateint game_x_position;
privateboolean look_left;
// Constructor, calls super constructor
public Enemy(int x,int y, Image image, Component parent,int element_id)
{
super(x, y, image, parent, element_id);
}
// sets boolean value walking_left
publicvoid enemyWalkLeft(boolean value)
{
walking_left = value;
}
// sets boolean value walking_right
publicvoid enemyWalkRight(boolean value)
{
walking_right = value;
}
// set value of enemy falling
publicvoid enemyFall(boolean value)
{
// correct player position if player stops falling in a level element
// move player to level element surface
while(y_pos_down%Constant_Values.game_component_height != 0)
{
y_pos_down --;
y_pos_up--;
}
falling = value;
}
publicvoid enemyMove()
{
// player walks left
if(walking_left)
{
x_pos_left -= walk_x_speed;
x_pos_right -= walk_x_speed;
game_x_position -= walk_x_speed;
if (step_counter%15 == 0)
{
picture_counter ++;
if(picture_counter == 2)
{
picture_counter = 0;
}
step_counter = 1;
}
else
{
step_counter ++;
}
look_left =true;
}
// player walks right
elseif(walking_right)
{
x_pos_left += walk_x_speed;
x_pos_right += walk_x_speed;
game_x_position += walk_x_speed;
if (step_counter%15 == 0)
{
picture_counter ++;
if(picture_counter == 2)
{
picture_counter = 0;
}
step_counter = 1;
}
else
{
step_counter ++;
}
look_left =false;
}
// player falls
if(falling)
{
y_pos_up += fall_y_speed;
y_pos_down += fall_y_speed;
}
}
}//end class Enemy
the game loop where the enemy behaviour is activated.
publicvoid run ()
{
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
while (true)
{
// test for collisions of the player with level elements
current_level.testForPlayerCollisions(player);
// move player
player.playerMove();
//this is the code that intializes the enemy
enemy.enemyWalkRight(true);
enemy.enemyMove();
what core features are required for the enemy to move?
are there any tutorials for programming enemies in java?

