Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Kivy - Interactive Applications and Games in Python

You're reading from  Kivy - Interactive Applications and Games in Python

Product type Book
Published in Jun 2015
Publisher
ISBN-13 9781785286926
Pages 206 pages
Edition 1st Edition
Languages
Author (1):
Roberto Ulloa Roberto Ulloa
Profile icon Roberto Ulloa

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
1. GUI Basics – Building an Interface 2. Graphics – the Canvas 3. Widget Events – Binding Actions 4. Improving the User Experience 5. Invaders Revenge – an Interactive Multi-touch Game 6. Kivy Player – a TED Video Streamer Index

Ammo – simple animation


This section explains how to animate shots and missiles, which show very similar behavior. They move from their original position to a destination, constantly checking whether a target has been hit. The following is the code for the ammo.py class:

61. # File name: ammo.py
62. from kivy.animation import Animation
63. from kivy.uix.image import Image
64. from boom import Boom
65. 
66. class Ammo(Image):
67.   def shoot(self, tx, ty, target):
68.     self.target = target
69.     self.animation = Animation(x=tx, top=ty)
70.     self.animation.bind(on_start = self.on_start)
71.     self.animation.bind(on_progress = self.on_progress)
72.     self.animation.bind(on_complete = self.on_stop)
73.     self.animation.start(self)
74. 
75.   def on_start(self, instance, value):
76.     self.boom = Boom()
77.     self.boom.center=self.center
78.     self.parent.add_widget(self.boom)
79. 
80.   def on_progress(self, instance, value, progression):
81.     if progression >= .1:
82...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}