If you make distance matrix from player, it is easy for enemy to zoom in to player. Only problem is that it is too deadly. You only move one closer and check if players position is distance away in same direction, if yes no walls are between.
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
You've already clearly explained (in English) what you need to do, now translate that into code.
pseudo-code here:
for enemy in enemies:
is_wall = determine if there is a wall between enemy and me
if is_wall:
# do nothing
continue
dist = compute distance between enemy and me
if dist > max_shooting_dist:
move enemy a little bit towards me
elif this enemy hasn't fired recently:
shoot a bullet towards me
add the bullet to a list of enemy bullets so we can keep updating its position
Do the parts you can, then get back to us with your version of this block of code, and what detail you're stuck on.
raptr_dflo
Practically a Master Poster
602 posts since Aug 2010
Reputation Points: 76
Solved Threads: 82
How does your code determine if the player has hit a wall while moving? Worst case, try moving a temporary fake object in a straight line (or approximately straight anyway)from the enemy to the player (all at once in a loop, rather than making one movement per simulation cycle) and see if you bounce off a wall on the way.
raptr_dflo
Practically a Master Poster
602 posts since Aug 2010
Reputation Points: 76
Solved Threads: 82