Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created July 19, 2015 19:25
Show Gist options
  • Save SpaceVoyager/c3dc20c5087584a4bc55 to your computer and use it in GitHub Desktop.
Save SpaceVoyager/c3dc20c5087584a4bc55 to your computer and use it in GitHub Desktop.
crazy bubbles.py
from scene import *
import math
from random import random
class MyScene (Scene):
circles = []
max_score = 0
game_began = False
def setup(self):
# This will be called before the first frame is drawn.
pass
def draw(self):
# This will be called for every frame (typically 60 times per second).
background(1, 1, 1)
# Draw a red circle for every finger that touches the screen:
for c in self.circles:
fill(c['color'][0], c['color'][1], c['color'][2], c['color'][3])
ellipse(c['center'].x - c['radius'], c['center'].y - c['radius'],
2*c['radius'], 2*c['radius'])
c['radius'] += 1
if c['center'].x - c['radius'] <= 0 or c['center'].x + c['radius'] >= self.bounds.w or c['center'].y - c['radius'] <= 0 or c['center'].y + c['radius']>= self.bounds.h :
self.circles = []
tint(1,0,0)
if len(self.circles) > self.max_score:
self.max_score = len(self.circles)
text('Score: ' + str(len(self.circles)), font_size = 30, x = 500, y= 20, alignment = 5)
text('Highest Score: ' + str(self.max_score), font_size = 50, x = 500, y= 80, alignment = 5)
if not self.game_began:
tint(0,0,1)
text('Crazy Bubbles', font_name = 'Noteworthy-Bold', font_size = 100, x = 500, y= 400, alignment = 5)
def touch_began(self, touch):
self.game_began = True
center = Point(touch.location.x, touch.location.y)
color = (random(), random(), random(), 0.5)
radius = 10
circle = {'center': center,
'color' : color,
'radius': radius}
self.circles.append(circle)
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