Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created August 2, 2015 22:52
Show Gist options
  • Save SpaceVoyager/bb5183e6ef962234633a to your computer and use it in GitHub Desktop.
Save SpaceVoyager/bb5183e6ef962234633a to your computer and use it in GitHub Desktop.
aquarium2.py
from scene import *
class SeaCreature:
def __init__(self, image_name, direction, size, speed_x, y, bounds):
self.image_name = image_name
self.direction = direction
self.size = size
self.speed_x = speed_x
self.bounds = bounds
if self.direction == 'move_right':
self.x = -self.size
else:
self.x = bounds.w
self.y = y
def update_state(self):
if self.direction == 'move_right':
self.x += self.speed_x
if self.x >= self.bounds.w:
self.x = -self.size
else:
self.x -= self.speed_x
if self.x <= -self.size:
self.x = self.bounds.w
image(self.image_name, self.x, self.y, self.size, self.size)
class MyScene (Scene):
def setup(self):
# This will be called before the first frame is drawn
self.fish1 = SeaCreature('Tropical_Fish', 'move_left', 150, 2, 200, self.bounds)
self.snail = SeaCreature('Snail', 'move_right', 64, 1, 5, self.bounds)
self.octopus = SeaCreature('Octopus', 'move_right', 200, 2, 400, self.bounds)
def draw(self):
# This will be called for every frame (typically 60 times per second).
background(0.00, 1.00, 1.00)
self.snail.update_state()
self.fish1.update_state()
self.octopus.update_state()
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