Hi
We are high school students working on a final project for our course.
We are making a top down shooter type game using pygame (its kind of like boxhead), and have made made all of our game except for the ai.
We really need some help with this, so if any one has any ideas on how we could go about making ai it would really help.

Somethings we would like to incorporate in our AI are:
-if there is no wall between and enemy the enemy shoots at the player
-if the player is far enough from the enemy AND their is no wall between them, then the enemy moves towards the player in order to get in range of him.
-if there IS a wall between the player and enemy, the enemy doesn't shoot or move.


Everything in our game so far (characters,bullets,walls, ect...) are made using sprites for collision.

PS we asked our teacher if we were allowed to ask about this on the forums and he said it was alright, since he didn't have much experience with ai in this type of game.


Thanks

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.

huh, sorry we're not following your advice...

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.

That's our problem converting in into code. Mainly, we don't know how we would check if there is a wall between the player and enemy.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.