#๐ tower defence game
14 messages ยท Page 1 of 1 (latest)
@keen birch
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Can you show us some of the code you already have?
Click here to see this code in our pastebin.
Is a Gunman a tower? Or is that a separate thing?
Assuming I'm understanding it correctly and Gunman is your tower class... You could add:
def select(self):
self.selected = True
def deselect(self):
self.selected = False
to them.
and also implement 'draw' directly on them, like
def draw(self, surface):
surface.blit(self.image, self.rect)
if self.selected:
# make another surface and draw a circle or whatever you want
and where you have gunman_group.draw(...) in main, instead call that new draw() directly on them:
for gunman in gunman_group:
gunman.draw(screen1)
In your main loop where you check for events, you can then look for event.type == pg.MOUSEBUTTONDOWN and event.button == 1 (I think that's right, double-check the docs on me maybe) and call gunman.select() on whichever Gunman they clicked on
I'm a pygame noob myself, still learning it; maybe someone will come along with a more-elegant approach
pseudocode for what I'm describing, since I don't want to just write it for you...
When mouse is clicked:
If click is on UI buttons:
# Existing UI logic
Else if placing a tower:
# Existing tower placement
Else:
# Tower selection logic
Deselect all towers
For each tower:
If click position is on this tower:
Select this tower
Break
okay cheers
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.