-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheffects.py
140 lines (119 loc) · 4.21 KB
/
effects.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
139
140
import pygame
import os
import CONSTANTS
import random
import math
global effect_cache
effect_cache = {}
def get_image(key):
if not key in effect_cache:
# print(f"loading {key}")
effect_cache[key] = pygame.image.load(os.path.join(key)).convert_alpha()
return effect_cache[key]
effect_list = ["health", "speed", "crit", "attack", "distance"]
effect_weights = (6, 3, 2, 1, 1)
effects = {
"health": "assets/effect/heart.png",
"healthboost": "assets/effect/heart2.png",
"speed": "assets/effect/speed.png",
"speedboost": "assets/effect/speed_perm.png",
"crit": "assets/effect/crit.png",
"critboost": "assets/effect/crit_perm.png",
"attack": "assets/effect/attack.png",
"attackboost": "assets/effect/attack_perm.png",
"distance": "assets/effect/distance.png",
"distanceboost": "assets/effect/distance_perm.png"
}
def health(state, e):
state.hearts += 1
def healthboost(state, e):
state.hearts += 2
def speed(state, e):
state.vel += 0.1
def speedboost(state, e):
if not e.used:
state.vel += 1
if state.frame == e.end_frame:
state.vel -= 1
def crit(state, e):
state.crit += state.crit/CONSTANTS.CRITSCALE
def critboost(state, e):
if not e.used:
state.crit += state.crit/(CONSTANTS.CRITSCALE/2)
if state.frame == e.end_frame:
state.crit -= state.crit/(CONSTANTS.CRITSCALE/2)
def attack(state, e):
state.attack += 0.1
def attackboost(state, e):
if not e.used:
state.attack += 1
if state.frame == e.end_frame:
state.attack -= 1
def distance(state, e):
CONSTANTS.ATTACKDISTANCE += CONSTANTS.PIXELS/8
def distanceboost(state, e):
if not e.used:
CONSTANTS.ATTACKDISTANCE += CONSTANTS.PIXELS
if state.frame == e.end_frame:
CONSTANTS.ATTACKDISTANCE -= CONSTANTS.PIXELS
framelength = {
"health": 1,
"healthboost": 1,
"speed": 1,
"speedboost": CONSTANTS.TICK*CONSTANTS.BOOSTLENGTH(),
"crit": 1,
"critboost": CONSTANTS.TICK*CONSTANTS.BOOSTLENGTH(),
"attack": 1,
"attackboost": CONSTANTS.TICK*CONSTANTS.BOOSTLENGTH(),
"distance": 1,
"distanceboost": CONSTANTS.TICK*CONSTANTS.BOOSTLENGTH(),
}
def effectEvent(state):
for e in state.activeEffects:
if e.effect == "health":
health(state, e)
elif e.effect == "healthboost":
healthboost(state, e)
elif e.effect == "speed":
speed(state, e)
elif e.effect == "speedboost":
speedboost(state, e)
elif e.effect == "crit":
crit(state, e)
elif e.effect == "critboost":
critboost(state, e)
elif e.effect == "attack":
attack(state, e)
elif e.effect == "attackboost":
attackboost(state, e)
elif e.effect == "distance":
distance(state, e)
elif e.effect == "distanceboost":
distanceboost(state, e)
e.used = True
state.activeEffects = list(filter(lambda e: state.frame != e.end_frame, state.activeEffects))
class Effect():
def __init__(self, x, y, frame, effect):
self.x = x
self.y = y
self.hitbox_width = CONSTANTS.PIXELS/2
self.hitbox_height = CONSTANTS.PIXELS/2
self.hitbox_x = self.x - self.hitbox_width * 3/4
self.hitbox_y = self.y - self.hitbox_height * 3/4
self.used = False
self.effect = effect
def draw(self, window, state):
if math.hypot(state.x-self.x, state.y-self.y) > (CONSTANTS.BOUND+1)*64:
return
animframe = math.floor((state.frame % CONSTANTS.TICK) / (CONSTANTS.TICK/4))
effect = get_image(effects[self.effect]).convert_alpha()
window.blit(effect, (self.x - CONSTANTS.PIXELS/2, self.y - CONSTANTS.PIXELS/2))
# Draw hitbox (for debugging purposes)
if CONSTANTS.DEBUG:
pygame.draw.rect(window, (255, 0, 0), (self.hitbox_x, self.hitbox_y, self.hitbox_width, self.hitbox_height), 2)
def drop_effect(x,y, state):
if random.randint(0,4) == 0:
e = random.choices(effect_list, weights=effect_weights, k=1)[0]
e = random.choices([e, e+"boost"], weights=(3,1), k=1)[0]
effect = Effect(x,y, state.frame, e)
state.effects.append(effect)