-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbony.py
138 lines (118 loc) · 3.53 KB
/
bony.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
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
131
132
133
134
135
136
137
138
# coding: utf-8
import random, math, pygame
from protoobjects import Bonus, Define
from player import vxy
@Define(0.3, 5, "speed.png")
class Speed(Bonus):
def modify(self, p):
p.v *= 2
def unmodify(self, p):
p.v /= 2
@Define(0.1, 3, "slow.png")
class Slow(Bonus):
def modify(self, p):
p.v /= 2.0
def unmodify(self, p):
p.v *= 2.0
@Define(0.1, 5, "invert.png")
class InvertControls(Bonus):
def modify(self, p):
p.swichedctrl = not p.swichedctrl
p.k_l, p.k_r = p.k_r, p.k_l
p.ll, p.lr = p.lr, p.ll
def unmodify(self, p):
p.swichedctrl = not p.swichedctrl
p.k_l, p.k_r = p.k_r, p.k_l
p.ll, p.lr = p.lr, p.ll
@Define(0.1, 3, "unknown.png")
class Unknown(Bonus):
def __init__(self, maxpx, maxpy, typ):
Bonus.__init__(self, maxpx, maxpy, typ)
bl = BonusList[:]
bl.pop(bl.index(Unknown))
self.bonus = random.choice(bl)(maxpx, maxpy, typ)
self.duration = self.bonus.duration
def modify(self, p):
return self.bonus.modify(p)
def unmodify(self, p):
return self.bonus.unmodify(p)
@Define(0.1, 5, "thinner.png")
class Thinner(Bonus):
def modify(self, p):
p.size /= 2.0
def unmodify(self, p):
p.size *= 2.0
@Define(0.3, 8, "thicker.png")
class Thicker(Bonus):
def modify(self, p):
p.size *= 2.0
def unmodify(self, p):
p.size /= 2.0
@Define(0.1, 5, "square.png")
class Square(Bonus):
def modify(self, p):
p.square += 1
def unmodify(self, p):
p.square -= 1
@Define(0.3, 8, "walkingthroughwalls.png")
class WalkingThroughWalls(Bonus):
def modify(self, p):
if self.typ:
self.game.wtwalls += 1
else:
p.wtwalls += 1
def unmodify(self, p):
if self.typ:
self.game.wtwalls -= 1
else:
p.wtwalls -= 1
@Define(0.3, 8, "invulnerability.png")
class Invulnerability(Bonus):
def __init__(self, maxpx, maxpy, game):
Bonus.__init__(self, maxpx, maxpy, game)
self.typ = 0
def modify(self, p):
p.invulnerability += 1
def unmodify(self, p):
p.invulnerability -= 1
@Define(0.05, 0, "clear.png")
class Clear(Bonus):
def __init__(self, maxpx, maxpy, game):
Bonus.__init__(self, maxpx, maxpy, game)
self.typ = 0
def modify(self, p):
self.game.background.fill(self.game.bgcolor)
@Define(0.2, 0, "laser.png")
class Laser(Bonus):
def __init__(self, maxpx, maxpy, game):
Bonus.__init__(self, maxpx, maxpy, game)
self.typ = 0
def modify(self, p):
pkt = []
r0, r1 = vxy(1500, p.a)
t0, t1 = vxy(200, p.a + math.pi/2.0)
pkt.append((int(p.px + t0 / 10.0), int(p.py + t1 / 10.0)))
pkt.append((int(p.px + t0 + r0), int(p.py + t1 + r1)))
t0, t1 = vxy(200, p.a - math.pi/2.0)
pkt.append((int(p.px + t0 + r0), int(p.py + t1 + r1)))
pkt.append((int(p.px + t0 / 10.0), int(p.py + t1 / 10.0)))
pygame.gfxdraw.filled_polygon(self.game.background, pkt, self.game.bgcolor)
BonusList = [
Speed,
Slow,
InvertControls,
Unknown,
Thinner,
Thicker,
Square,
WalkingThroughWalls,
Invulnerability,
Clear,
Laser,
]
def AddBony(maxpx, maxpy, game):
r = []
for b in BonusList:
if b.chance > random.random():
r.append(b(maxpx, maxpy, game))
return r