TheNegroShoddy
Member
I'm currently working on a game in which both the player and the enemy ai move on tiles (9x9). I have an enemy currently that moves up and down the tiles freely using two paths as shown below:
In the game, the player will be able to create various objects and place them on a tile on either the player's side of the screen or the enemy's side. The problem I'm having is simply preventing the enemies from moving on the tile where an object is (such as a ticking bomb the player can place out).
What I would like for the enemy objects to do is simply move in the opposite direction whenever there is a bomb or other object above them. They should never occupy the same space as the object. I've tried using path_reverse and flip_path, but those didn't work right and from my understanding those functions alter the actual paths themselves, which I don't think is what I need.
Anyway this is the relevant code:
Step Event
By the way, this is what happens when the enemy object touches the bomb object:
In the game, the player will be able to create various objects and place them on a tile on either the player's side of the screen or the enemy's side. The problem I'm having is simply preventing the enemies from moving on the tile where an object is (such as a ticking bomb the player can place out).
What I would like for the enemy objects to do is simply move in the opposite direction whenever there is a bomb or other object above them. They should never occupy the same space as the object. I've tried using path_reverse and flip_path, but those didn't work right and from my understanding those functions alter the actual paths themselves, which I don't think is what I need.
Anyway this is the relevant code:
Step Event
Code:
execute code:
COMMENT: Have the virus move if mode is set to 0 after waiting
if wait_countdown is equal to 0
if mode is equal to 0
if position_meeting(x, y - 45, player_bomb_obj) is not equal to true
if position_meeting(x, y + 45, player_bomb_obj) is not equal to true
if move_pattern is equal to "up_down"
set the relative path to boomer_path_updown with speed 3 and at the end stop
if position_meeting(x, y - 45, player_bomb_obj) is not equal to true
if position_meeting(x, y + 45, player_bomb_obj) is not equal to true
if move_pattern is equal to "down_up"
set the relative path to boomer_path_downup with speed 3 and at the end reverse
execute code:
if position_meeting(x, y - 45, player_bomb_obj) || position_meeting(x, y + 45, player_bomb_obj)
{
if path_index == boomer_path_updown || path_index == boomer_path_downup
{
var current_path, current_speed, current_position;
current_path = path_index;
current_speed = path_speed;
current_position = path_position;
path_speed = 0; // Should stop the enemy briefly
path_reverse( current_path ); // Flip the direction
path_speed = current_speed;
}
}
Begin