Enemy Projectiles Arent Appending On Screen

2024/10/5 15:09:41

I have here my script that targets the player what ever position he is at but the projectiles aren't showing on my screen VIDEO. He isn't attacking at all, I don't know why. I am in my main loop I draw the bullets to.

my enemy bullet class

    # enemys bulletsksud = pygame.image.load("heart.png")class Boolss(object):def __init__(self, x, y,color, xspeed, yspeed):self.x = xself.y = yself.xspeed = xspeedself.yspeed = yspeedself.ksud = pygame.image.load("heart.png")self.hitbox  = self.ksud.get_rect()self.rect  = self.ksud.get_rect()self.rect.topleft = (self.x,self.y)self.speed = 10self.color = colorself.hitbox = (self.x + 57, self.y + 33, 29, 52) # NEWdef draw(self, window):self.rect.topleft = (self.x,self.y)player_rect = self.ksud.get_rect(center = self.rect.center) player_rect.centerx += 0 # 10 is just an exampleplayer_rect.centery += 0 # 15 is just an examplewindow.blit(self.ksud, player_rect)self.hitbox = (self.x + 97, self.y + 33, 10, 10) # NEWwindow.blit(self.ksud,self.rect)

this goes on my main loop, it appends bullets and targets the player

            for shootss in shootsright:shootss.x += shootss.xspeedshootss.y += shootss.yspeedif shootss.x > 500 or shootss.x < 0 or shootss.y > 500 or shootss.y < 0:shootsright.pop(shootsright.index(shootss))if len(shootsright) < 2:start_x = round(enemyshoots1.x+enemyshoots1.width-107)start_y = round(enemyshoots1.y + enemyshoots1.height-50)target_x = playerman.x+playerman.width//2target_y = playerman.y+playerman.width//2dir_x, dir_y = target_x - start_x, target_y - start_ydistance = math.sqrt(dir_x**2 + dir_y**2)if distance > 0:shootsright.append(Boolss(start_x,start_y,(0,0,0),dir_x, dir_y))

I draw the bullets that are appending on my screen but they don't show

            for shootss in shootsright:shootss.draw(window)

my full code script

Answer

I didn't run code but I think you have wrong indentations and this make problem.

You append to shootsright` inside

  for shootss in shootsright:shootsright.append(...)

but at start shootsright is empty so it never runs for shootss in shootsright: and it never runs shootsright.append() - so shootsright is always empty.

Probably you have to move it outside this loop (you have to change indentations)

  for shootss in shootsright:shootss.x += shootss.xspeedshootss.y += shootss.yspeedif shootss.x > 500 or shootss.x < 0 or shootss.y > 500 or shootss.y < 0:shootsright.pop(shootsright.index(shootss))# outside `for`-loopif len(shootsright) < 2:start_x = round(enemyshoots1.x+enemyshoots1.width-107)start_y = round(enemyshoots1.y + enemyshoots1.height-50)target_x = playerman.x+playerman.width//2target_y = playerman.y+playerman.width//2dir_x, dir_y = target_x - start_x, target_y - start_ydistance = math.sqrt(dir_x**2 + dir_y**2)if distance > 0:shootsright.append(Boolss(start_x,start_y,(0,0,0),dir_x, dir_y))

BTW: next time you can use print() in many places to see values in this list in different moments and to see which part of code is executed. It is called "print debuging".

https://en.xdnf.cn/q/119561.html

Related Q&A

Python+Selenium. Cant locate element

Ive implemented the script using Python and selenium to click on the ads. But now this script is not working.Unable to find element on the page.Please help me to correct the script. Thank you!from sele…

AttributeError: NoneType object has no attribute channels [duplicate]

This question already has answers here:Why do I get AttributeError: NoneType object has no attribute something?(11 answers)Closed 5 years ago.Hi Im having an issue with a module for my Discord bot. Im…

How to get a specific value from a html header

Im using selenium to get request headers from a web page, the problem is that it prints out all request headers sent and i want to get only one value from one of them. I dont know how to do it and i ha…

How to use windows as raspberry pi and connect the windows with another raspberry pi [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 4…

Python : Return the missing weekdays dates and assign rate next to missing date

Dates rates 7/26/2019 1.04 7/30/2019 1.0116 7/31/2019 1.005 8/1/2019 1.035 8/2/2019 1.01 8/6/2019 0.9886 8/7/2019 1.0048 8/8/2019 0.97 8/9/2019 0.9659 8/12/2019 0.965In …

How do I use a list or set as keys in file renaming

Is something like this possible? Id like to use a dictionary or set as the key for my file renamer. I have a lot of key words that id like to filter out of the file names but the only way iv found to …

How to change Python comment font style in the latest VS Code? [duplicate]

This question already has an answer here:How to change the font-style of code comments in vscode?(1 answer)Closed 6 months ago.Seems like with the latest VS Code update, all the comment font style has…

How to crop an image based on a complex criteria?

I have a set of similar images like the one below. I want to keep the portion of the image that is within the top red irregular rectangle (green arrows represent the space that I want to keep; anything…

Getting current video tag URL with selenium

Im trying to get the current html5 video tag URL using selenium (with python bindings):from selenium import webdriverdriver = webdriver.Chrome() driver.get(https://www.youtube.com/watch?v=9x6YclsLHN0)…

How to determine if two rows are identical (similar) if row 2 contains part of the info from row 1?

Hope you are having a good day. I am currently working with an extremely dirty dataframe containing First Name, Last Name, and Middle Name. One the issues that I am trying to resolve looks like below:F…