Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created July 26, 2015 18:51
Show Gist options
  • Save SpaceVoyager/a5183850411bd59b0a19 to your computer and use it in GitHub Desktop.
Save SpaceVoyager/a5183850411bd59b0a19 to your computer and use it in GitHub Desktop.
crazy bubbles 2.py
from scene import *
import math
from random import random
class MyScene (Scene):
circles = []
max_score = 0
game_began = False
speed = 1
def setup(self):
# This will be called before the first frame is drawn.
pass
def circles_touch(self, c1, c2):
d = c1['center'].distance(c2['center'])
if d > c1['radius'] + c2['radius']:
return False
else:
return True
def draw(self):
# This will be called for every frame (typically 60 times per second).
background(1, 1, 1)
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'] += self.speed
for c1 in self.circles:
if c1['center'].x - c1['radius'] <= 0 or c1['center'].x + c1['radius'] >= self.bounds.w or c1['center'].y - c1['radius'] <= 0 or c1['center'].y + c1['radius']>= self.bounds.h :
self.circles = []
for c2 in self.circles:
if c1 != c2 and self.circles_touch(c1, c2):
self.circles = []
if len(self.circles) > self.max_score:
self.max_score = len(self.circles)
tint(1.00, 0.40, 0.40)
text('Score: ' + str(len(self.circles)), font_size = 30, x = 500, y= 20, alignment = 5)
tint(1.00, 0.50, 0.00)
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 2', 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