-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.py
More file actions
64 lines (47 loc) · 1.55 KB
/
objects.py
File metadata and controls
64 lines (47 loc) · 1.55 KB
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
import pygame
from constants import *
from config import *
from util import *
class GameObject:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def update(self, dt):
pass
def draw(self, surface):
pass
class Bird(GameObject):
a = 500
jump_v = 300
def __init__(self, y=height/2):
super().__init__()
self.x = 100
self.y = y
self.r = 20
self.color = RED
self.v = 0
self.a = Bird.a
def draw(self, surface, color=None):
pygame.draw.circle(surface, color if color != None else self.color, [int(self.x), int(self.y)], int(self.r))
def update(self, dt):
self.v += self.a * dt
self.y += self.v * dt
def jump(self):
self.v = -Bird.jump_v
def collide(self, pipe):
return collide([pipe.x, 0, pipe.width, pipe.uy], [self.x, self.y, self.r]) or collide([pipe.x, pipe.ly, pipe.width, height - pipe.ly], [self.x, self.y, self.r]) or self.y < self.r or self.y > height - self.r
def die(self, score):
pass
class Pipe(GameObject):
def __init__(self, uy, ly, x=width):
super().__init__()
self.x = x
self.uy = uy
self.ly = ly
self.color = GREEN
self.width = 100
self.v = 100
def draw(self, surface):
pygame.draw.rect(surface, self.color, [self.x, 0, self.width, self.uy])
pygame.draw.rect(surface, self.color, [self.x, self.ly, self.width, height - self.ly])
def update(self, dt):
self.x -= dt * self.v