Starlight-30036225 / Ai-Assignment

Assets from Code the Classics
0 stars 0 forks source link

Player defense #6

Open Starlight-30036225 opened 6 months ago

Starlight-30036225 commented 6 months ago

I want the player to be able to defend itself from incoming bullets from the robots. For this I will need to check if any bullets are close, and if they are facing the player. Then either fire or jump to avoid it (I would like this to be random for variation.

Starlight-30036225 commented 6 months ago

`` def defend(self): for bullet in game.bolts:

The orb must be at our height, and within 200 pixels on the x axis

        if bullet.y >= self.top and bullet.y < self.bottom and abs(bullet.x - self.x) < 200:
            if bullet.direction_x == sign(self.x - bullet.x):
                self.Pmove(sign(bullet.x - self.x))
                self.fire()
                break

``

This works. the player will only destroy bullets currently attacking it

I want to give a chance to also jump, if the player has no bullets then definately jump

Starlight-30036225 commented 6 months ago

The player jumps and shoots, im not sure how to stop it from doing both other than a defence cooldown. Which im not a huge fan of. But itll do for now