Python Forum
Individuallien attack in alien invasion game - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Individuallien attack in alien invasion game (/thread-11903.html)



Individuallien attack in alien invasion game - runnerpaul - Jul-31-2018

I'm enhancing the Alien Invasion sample program from the Python Crash Course book. One feature I'd like to add is to randomly have a single alien to fly down the screen towards my ship. I've already created the code to do this. My problem is that it gets called in the game loop so my aliens constantly fly down the screen and the game is over in seconds. I thought about puttign this call into a timer where an alien will only be called to attack at a certain time. I'm just wondering if there is a better way t do this. Any thoughts?


RE: Individuallien attack in alien invasion game - ThiefOfTime - Jul-31-2018

You have different options at that point:
1. insert a counter and fly down an alien when the counter hits the random number
2. insert a thread and put in a timer
3. User the APScheduler (http://apscheduler.readthedocs.io/en/3.0/userguide.html)
I personally would use the 3. option. You can reschedule everytime you called the funktion and set the time intervall to a new random value.