Python Forum
Individuallien attack in alien invasion game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Individuallien attack in alien invasion game
#1
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?
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help - 22000 lines of code / alien writings! gfetng 1 1,925 Feb-22-2019, 03:25 PM
Last Post: ichabod801
  Alien game code from book TheMusicMan 4 3,173 Aug-26-2018, 06:05 PM
Last Post: TheMusicMan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020