+ 2
Help me with write a logic code for my game?
I create a tank game in python.when my tank shoot enemy then it does not move until my tank bullet is not destroy.so how i can done multiple work in my game that my tank move and also shoot enemy and as well as aim enemy tank.does here I need to create threads or it can be done in any other way.
2 Antworten
+ 3
Use a different class for bullet
Create instance of the bullet in the method of tank class
Push the bullet instance into a list at global scope
Run for loop in the loop function over the list of bullet to call the update and draw of each bullet
+ 12
What you need is an event-driven programming approach. You should draw the game scene constantly with objects' positions being updated by events (mouseclicks or keys pressed).
Then a "fire" button should just initialize a projectile object and add it to the collections of objects being drawn on the screen.
Do not create separate loops for ea h object as that will concentrate on updating one object at a time. It is enough for turn-based games, but if you want real-time, you have to use a different approach.