-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbirdClass.py
77 lines (62 loc) · 2.27 KB
/
birdClass.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
75
76
77
import neat
import os
import time
import random
import pygame
b1 = pygame.transform.scale2x(pygame.image.load(os.path.join("images", "bird1.png")))
b2 = pygame.transform.scale2x(pygame.image.load(os.path.join("images", "bird2.png")))
b3 = pygame.transform.scale2x(pygame.image.load(os.path.join("images", "bird3.png")))
birdPhotos = [b1, b2, b3]
class Bird:
bp = birdPhotos
animationDuration = 5
rotationSpeed = 20
maxRotation = 25
def __init__(self, x, y):
self.x = x
self.y = y
self.tilt = 0
self.tickCount = 0
self.imageCount = 0
self.speed = 0
self.height = self.y
self.image = self.bp[0]
def jump(self):
self.speed = -10.5
self.tickCount = 0
self.height = self.y
def move(self):
self.tickCount += 1
d = self.speed * self.tickCount + 1.5 * self.tickCount**2
if d>=16:
d = 16
if d<0:
d -= 2
self.y = self.y + d
if d<0 or self.y <self.height + 50:
if self.tilt <self.maxRotation:
self.tilt = self.maxRotation
else:
if self.tilt > -90:
self.tilt -= self.rotationSpeed
def draw(self, window):
self.imageCount += 1
if self.imageCount <self.animationDuration:
self.image = self.bp[0]
elif self.imageCount <self.animationDuration*2:
self.image = self.bp[1]
elif self.imageCount <self.animationDuration*3:
self.image = self.bp[2]
elif self.imageCount <self.animationDuration*4:
self.image = self.bp[1]
elif self.imageCount == self.animationDuration*4 + 1:
self.image = self.bp[0]
self.imageCount = 0
if self.tilt <= -80:
self.image = self.bp[1]
self.imageCount = self.animationDuration*2
rotatedImage = pygame.transform.rotate(self.image, self.tilt)
newRect = rotatedImage.get_rect(center=self.image.get_rect(topleft = (self.x, self.y)).center)
window.blit(rotatedImage, newRect.topleft)
def getMask(self):
return pygame.mask.from_surface(self.image)