Book Image

Kivy - Interactive Applications and Games in Python

By : Roberto Ulloa
Book Image

Kivy - Interactive Applications and Games in Python

By: Roberto Ulloa

Overview of this book

Table of Contents (13 chapters)
Kivy – Interactive Applications and Games in Python Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Scheduling events with the clock


We saw that Animation has a duration parameter that establishes the time in which an animation should take place. A different time-related topic is the scheduling of a particular task at a certain time or during intervals of n seconds. In these cases, we use the Clock class. Let's analyze the following code, fragment 2 (of 2), of fleet.py:

189. # File name: fleet.py (Fragment 2)
190.   def schedule_events(self):
191.     Clock.schedule_interval(self.solo_attack, 2)
192.     Clock.schedule_once(self.shoot,random())
193. 
194.   def solo_attack(self, dt):
195.     if len(self.survivors):
196.       rint = randint(0, len(self.survivors) - 1)
197.       child = self.survivors[rint]
198.       child.invader.solo_attack()
199. 
200.   def shoot(self, dt):
201.     if len(self.survivors):
202.       rint = randint(0,len(self.survivors) - 1)
203.       child = self.survivors[rint]
204.       child.invader.drop_missile()
205.       Clock.schedule_once(self.shoot,random...