-
Notifications
You must be signed in to change notification settings - Fork 1
/
bird.py
53 lines (37 loc) · 1.67 KB
/
bird.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
# from PyQt5.QtGui import QVector2D
from PyQt5.QtGui import QPainter, QColor, QPixmap, QFont, QVector2D
from individual import Individual
import math
from PyQt5.QtCore import Qt, QRect
class Bird(Individual):
max_speed = 100
max_turn_rate = 30 # degrees
def __init__(self, id, x, y, velo_x, velo_y):
# super(Individual, self).__init__(x, y, velo_x, velo_y)
Individual.__init__(self, id, x, y, velo_x, velo_y)
self.sprite = QPixmap()
self.sprite.load('bird', 'png')
def move(self, time):
if self.velocity.length() > self.max_speed:
self.velocity /= 1.1 #(self.velocity.length() * self.max_speed)
Individual.move(self, time)
def draw(self, painter, debug):
painter.translate(self.position.x(), self.position.y())
# calculate angle of bird
self.calculateAngle()
painter.rotate(self.angle)
painter.drawPixmap(-self.sprite.width()/2, -self.sprite.height()/2, self.sprite)
if debug:
painter.setPen(Qt.green)
painter.drawLine(-300, 0, 300, 0)
painter.drawLine(0, -300, 0, 300)
rect = QRect(-64, -64, 128, 128)
painter.setPen(Qt.red)
# velocity vector
painter.drawLine(0, 0, 100, 0)
painter.drawLine(80, -20, 100, 0)
painter.drawLine(80, 20, 100, 0)
painter.drawRect(rect)
painter.rotate(90)
painter.setFont(QFont('Decorative', 10))
painter.drawText(-self.sprite.width()/2, self.sprite.height()/2, str(self.id))