Help me with write a logic code for my game? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

1st Feb 2019, 3:12 AM
Maninder $ingh
Maninder $ingh - avatar
2 Answers
+ 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
1st Feb 2019, 4:27 AM
Gordon
Gordon - avatar
+ 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.
1st Feb 2019, 7:21 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar