-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity.py
More file actions
130 lines (94 loc) · 3.56 KB
/
activity.py
File metadata and controls
130 lines (94 loc) · 3.56 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import pygame
import pygame.freetype
import random
class Activity(pygame.sprite.Sprite):
def __init__(self, bg, row, type, name, score):
super(Activity, self).__init__()
self.height = bg.cellHeight * 3 / 5
self.width = bg.cellWidth
self.name = name
self.x = bg.right
self.y = row * bg.cellHeight + bg.top + bg.cellHeight / 5
self.limitLeft = bg.left
self.limitRight = bg.right
self.limitTop = bg.top
self.limitBottom = bg.bottom
self.type = type
if random.random() < score / 2000:
self.R = 206
self.G = 96
self.B = 2
else:
if self.type == 0:
self.R = 80
self.G = 90
self.B = 224
elif self.type == 1:
self.R = 255
self.G = 50
self.B = 60
elif self.type == 2:
self.R = 200
self.G = 90
self.B = 200
# self.R, self.G, self.B = 206, 96, 2
self.color = (self.R, self.G, self.B)
self.completed = False
self.FONT = pygame.freetype.SysFont("Lucon.ttf", 13)
self.days = []
self.daysPassed = 0
self.row = row
self.randomGen()
# self.getName()
self.drawSurf()
self.HPperDay = 10
self.maxHP = self.daysLeft * self.HPperDay
self.HP = self.maxHP
def drawSurf(self):
self.surf = pygame.Surface((self.daysLeft * self.width, self.height))
self.surf.fill(self.color)
pygame.draw.rect(self.surf, (0,0,0), self.surf.get_rect(), 1)
self.rect = self.surf.get_rect()
self.rect.move_ip(self.x, self.y)
self.FONT.render_to(self.surf, (2, 3), self.name, (0, 0, 0))
def recolorSurf(self):
self.surf.fill(self.color)
pygame.draw.rect(self.surf, (0,0,0), self.surf.get_rect(), 1)
self.FONT.render_to(self.surf, (2, 3), self.name, (0, 0, 0))
def getName(self):
self.name = "20151 KLIMAOPREMA, PK-VS 0316-VIS 2"
def randomGen(self):
self.daysLeft = random.randint(1, 14)
for i in range(0, self.daysLeft):
self.days.append(False)
# self.x = random.randint(0, bg.cols - 1) * bg.cellWidth + bg.left
# self.y = random.randint(0, bg.rows - 1) * bg.cellHeight + bg.top + bg.cellHeight / 5
self.totWidth = self.daysLeft * self.width
def doActivity(self, damage, *args):
if not self.completed:
if len(args) != 0:
if args[0] != self.type:
damage = damage / 5
# return 2 # destroy projectile
self.HP -= damage
if self.HP <= 0:
self.HP = 0
self.completed = True
return 2
self.color = ( self.R * self.HP / self.maxHP,
self.G * self.HP / self.maxHP + 255 * (1 - self.HP / self.maxHP),
self.B * self.HP / self.maxHP )
self.recolorSurf()
return 1 # destroy projectile after damage
else:
return 0 # pass through
def update(self, frame):
removeThis = 0
if frame == 0:
self.rect.move_ip(-self.width, 0)
self.daysPassed += 1
if self.daysPassed == self.daysLeft:
removeThis = 1
if self.rect.left < self.limitLeft - self.totWidth:
removeThis = 2
return removeThis