-
Notifications
You must be signed in to change notification settings - Fork 0
/
nanogame.py
74 lines (57 loc) · 1.41 KB
/
nanogame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from processing import *
from time import sleep
from math import *
from random import randint
def setup():
frameRate(30)
size(400, 400)
class Storage:
def __init__ (self):
pass
# You can store whatever you want in this object
Variables = Storage()
# Sprite object class
class Sprite:
def __init__ (self, x, y, height, width):
self.x = x
self.y = y
self.v = 0
self.height = height
self.width = width
def color(self, r, g, b):
self.r = r
self.g = g
self.b = b
def display(self):
stroke(0)
fill(self.r, self.g, self.b)
rectMode(CENTER)
rect(self.x, self.y, self.width, self.height)
# Easy collision detection
def isTouching(self, sprite2):
if (self.x < self.x < sprite2.x + 75):
if (self.y < sprite2.y - 75) or (self.y > sprite2.y + 75):
print "Bird died!"
else:
pass
# Reusable wall class that can be used in other games
class Wall:
def __init__ (self, speed, spacing, r, g, b):
self.speed = speed
self.spacing = spacing
self.r = r
self.g = g
self.b = b
self.x = 400
self.y = randint(10 + self.spacing, 400 - (10 + self.spacing))
def color(self, r, g, b):
self.r = r
self.g = g
self.b = b
def display(self):
rectMode(CORNER)
stroke(80)
fill(self.r, self.g, self.b)
rect(self.x, self.y - (400 + self.spacing), 75, 400)
rect(self.x, self.y + self.spacing, 75, 400)
run()