Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created August 16, 2015 23:38
Show Gist options
  • Save SpaceVoyager/1b78cd3244b33943c1a4 to your computer and use it in GitHub Desktop.
Save SpaceVoyager/1b78cd3244b33943c1a4 to your computer and use it in GitHub Desktop.
double cannon example.py
from scene import *
import math
class MyScene (Scene):
def setup(self):
# This will be called before the first frame is drawn.
# Set up the root layer
self.root_layer = Layer(self.bounds)
center = self.bounds.center()
self.cannon_size = 200
# add layer for the first cannon
self.layer1 = Layer(Rect(200, 0, self.cannon_size, self.cannon_size))
self.layer1.image = '_cannon'
self.root_layer.add_layer(self.layer1)
self.angle = 0
self.counter_clock_wise = True
# add layer for the second cannon
self.layer2 = Layer(Rect(self.bounds.w-self.cannon_size-200, 0, self.cannon_size, self.cannon_size))
self.layer2.image = '_cannon'
self.root_layer.add_layer(self.layer2)
def draw(self):
if self.angle >= 180:
self.counter_clock_wise = False
if self.angle <= 0:
self.counter_clock_wise = True
if self.counter_clock_wise:
self.angle += 1
else:
self.angle -= 1
background(0.40, 0.80, 1.00)
self.root_layer.update(self.dt)
self.root_layer.draw()
self.layer1.animate('rotation', self.angle, 1/60.0)
self.layer2.animate('rotation', self.angle, 1/60.0)
def touch_began(self, touch):
pass
def touch_moved(self, touch):
pass
def touch_ended(self, touch):
pass
run(MyScene())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment