Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created August 9, 2015 21:05
Show Gist options
  • Save SpaceVoyager/283adc2accfcf076bd8f to your computer and use it in GitHub Desktop.
Save SpaceVoyager/283adc2accfcf076bd8f to your computer and use it in GitHub Desktop.
aquarium3.py
from scene import *
from random import uniform
bounds = None
class SeaCreature:
def __init__(self, image_name, direction, size, speed_x, y):
self.image_name = image_name
self.direction = direction
self.size = size
self.speed_x = speed_x
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 >= bounds.w:
self.x = -self.size
else:
self.x -= self.speed_x
if self.x <= -self.size:
self.x = 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
global bounds
bounds = self.bounds
self.fish1 = SeaCreature('Tropical_Fish', 'move_left', 150, 2, 200)
self.snail = SeaCreature('Snail', 'move_right', 64, 1, 10)
self.octopus = SeaCreature('Octopus', 'move_right', 200, 2, 400)
self.fish_school1 = []
for i in range(50):
self.fish_school1.append(SeaCreature('Tropical_Fish', 'move_left', uniform(50, 150), uniform(1,5), uniform(100, 600)))
self.octopus_school = []
for i in range(10):
self.octopus_school.append(SeaCreature('Octopus', 'move_right', 100, uniform(1, 2), uniform(50, 700)))
def draw(self):
# This will be called for every frame (typically 60 times per second).
background(0.00, 1.00, 1.00)
fill(1.00, 0.80, 0.40)
rect(0, 0, self.bounds.w, 50)
self.snail.update_state()
self.fish1.update_state()
self.octopus.update_state()
for fish in self.fish_school1:
fish.update_state()
for o in self.octopus_school:
o.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