Skip to content

Instantly share code, notes, and snippets.

@ssophwang
Created August 10, 2015 00:10
Show Gist options
  • Save ssophwang/9b64eb734e2e447a992d to your computer and use it in GitHub Desktop.
Save ssophwang/9b64eb734e2e447a992d to your computer and use it in GitHub Desktop.
fish_tank.py
from scene import *
from random import uniform
bounds = None
class sea_creature:
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 = 0 - 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.fish_x = self.bounds.w
self.fishspeed = 3
self.fishsize = 50
self.snail_size = 20
self.snail_speed = 0.5
self.snail_x = -self.snail_size
self.turtle_x = self.bounds.w
self.turtle_speed = 2
self.turtle_size = 150
self.octopus_y = 100
self.octopus_speed = 6
self.octopus_size = 100
self.blowfish = sea_creature('Blowfish', 'move_left', 100, 3, 50)
self.Whale = sea_creature('Whale', 'move_left', 525, 5, 400)
self.Tropical_Fish = sea_creature('Tropical_Fish', 'move_left', 70, 5, 300)
self.tropical_fish = sea_creature('Tropical_Fish', 'move_left', 60, 3.5, 200)
self.Tropical_fish = sea_creature('Tropical_Fish', 'move_left', 80, 5.5, 250)
self.Snail = sea_creature('Snail', 'move_right', 16, 0.3, 20)
self.fish_school1 = []
for i in range(6):
self.fish_school1.append(sea_creature('Fish', 'move_left', uniform(30, 100), uniform(2, 5), uniform(100, 600)))
self.dolphin_school = []
for i in range(8):
self.dolphin_school.append(sea_creature('Dolphin', 'move_left', uniform(100, 250), uniform(4, 8), uniform(50, 600)))
def draw(self):
# This will be called for every frame (typically 60 times per second).
background(0.75, 1.00, 1.00)
fill(1.00, 0.80, 0.40)
rect(0,0,1024,50)
self.octopus_y += self.octopus_speed
if self.octopus_y > self.bounds.h + self.octopus_size:
self.octopus_y = 100
image('Octopus', 400, self.octopus_y, self.octopus_size, self.octopus_size)
self.Whale.update_state()
image('Spiral_Shell', 486, 0, 75, 75)
self.fish_x -= self.fishspeed
if self.fish_x <= -self.fishsize:
self.fish_x = self.bounds.w
image('Tropical_Fish', self.fish_x, 400, self.fishsize, self.fishsize)
self.Tropical_Fish.update_state()
self.tropical_fish.update_state()
self.Tropical_fish.update_state()
self.snail_x += self.snail_speed
if self.snail_x >= self.bounds.w:
self.snail_x = -self.snail_size
image('Snail', self.snail_x, 10, self.snail_size, self.snail_size)
image('Herb', 235, -1, 125, 250,)
self.turtle_x -= self.turtle_speed
if self.turtle_x <= -self.turtle_size:
self.turtle_x = self.bounds.w
image('Turtle', self.turtle_x, 100, self.turtle_size, self.turtle_size)
self.blowfish.update_state()
self.Snail.update_state()
for fish in self.fish_school1:
fish.update_state()
for dolphin in self.dolphin_school:
dolphin.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