-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.py
232 lines (183 loc) · 6.1 KB
/
entity.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import logging
from typing import Callable, Sequence
import pyxel
from dataclasses import dataclass, field
from sprites import SPRITE_TYPE, Sides
from sprites import Efeitos
log = logging.getLogger(__name__)
def ciclone(self):
return_list = []
directions = Sides
damage = self.player.atk
for i, direction in enumerate(directions):
dx, dy = direction.value
distance = 8
index = i
new_speedx = dx * distance
new_speedy = dy * distance
new_x = self.player.x + new_speedx
new_y = self.player.y + new_speedy
attack = Projectile(
new_x, new_y, Efeitos.CYCLONE[index], duration=1.1 ,damage=damage)
print(attack)
return_list.append(attack)
return return_list
def arrow(self):
return_list = []
speedx, speedy = self.player.direct.value
multi = 8
new_speedx = speedx * multi
new_speedy = speedy * multi
new_x = self.player.x + new_speedx
new_y = self.player.y + new_speedy
damage = self.player.atk
if self.player.direct == Sides.LEFT:
attack = Projectile(
new_x, new_y, Efeitos.ARROW[0], speedx=speedx, speedy=speedy, damage=damage)
elif self.player.direct == Sides.RIGHT:
attack = Projectile(
new_x, new_y, Efeitos.ARROW[1], speedx=speedx, speedy=speedy, damage=damage)
elif self.player.direct == Sides.UP:
attack = Projectile(
new_x, new_y, Efeitos.ARROW[3], speedx=speedx, speedy=speedy, damage=damage)
elif self.player.direct == Sides.DOWN:
attack = Projectile(
new_x, new_y, Efeitos.ARROW[2], speedx=speedx, speedy=speedy, damage=damage)
return_list.append(attack)
return return_list
def a_button(self):
return_list = []
speedx, speedy = self.player.direct.value
multi = 8
new_speedx = speedx * multi
new_speedy = speedy * multi
new_x = self.player.x + new_speedx
new_y = self.player.y + new_speedy
damage = self.player.atk
if self.player.direct == Sides.LEFT:
attack = Projectile(
new_x, new_y, Efeitos.FIREBALL[0], speedx=speedx, speedy=speedy, damage=damage)
elif self.player.direct == Sides.RIGHT:
attack = Projectile(
new_x, new_y, Efeitos.FIREBALL[1], speedx=speedx, speedy=speedy, damage=damage)
elif self.player.direct == Sides.UP:
attack = Projectile(
new_x, new_y, Efeitos.FIREBALL[3], speedx=speedx, speedy=speedy, damage=damage)
elif self.player.direct == Sides.DOWN:
attack = Projectile(
new_x, new_y, Efeitos.FIREBALL[2], speedx=speedx, speedy=speedy, damage=damage)
print("attack: ", attack)
return_list.append(attack)
return return_list
def space_button(self):
return_list = []
for side in Sides:
speedx, speedy = side.value
multi = 8
new_speedx = speedx * multi
new_speedy = speedy * multi
new_x = self.player.x + new_speedx
new_y = self.player.y + new_speedy
damage = self.player.atk
attack = Projectile(
new_x, new_y, Efeitos.ATTACK[0], Efeitos.ATTACK, speedx, speedy, damage=damage)
return_list.append(attack)
return return_list
def verifyCollision(objeto1, objeto2):
if (objeto1.x < objeto2.x + objeto2.sprite[3] and
objeto1.x + objeto1.sprite[3] > objeto2.x and
objeto1.y < objeto2.y + objeto2.sprite[4] and
objeto1.y + objeto1.sprite[4] > objeto2.y):
log.debug(f"{type(objeto1)} - {type(objeto2)} colidiram um com o outro")
return True
else:
return False
def levelUp(character):
if character.exp_atual == character.exp_para_upar or character.exp_atual > character.exp_para_upar:
character.level += 1
character.exp_atual = 0
character.exp_para_upar = int(
character.exp_progresso * character.exp_para_upar)
log.info(f"personagem upou {character}")
def exp_walk(self, orb):
player_x = self.player.x
player_y = self.player.y
object_x = orb.x
object_y = orb.y
distance = pyxel.sqrt((player_x - object_x) ** 2 +
(player_y - object_y) ** 2)
if distance > 0:
direction_x = (player_x - object_x) / distance
direction_y = (player_y - object_y) / distance
orb.x += round(direction_x)
orb.y += round(direction_y)
def addItem(character, item):
character.inventory.append(item)
def is_in_inventory(character, item):
return item in character.inventory
@dataclass
class Object:
x: int
y: int
sprite: SPRITE_TYPE
name: str
@dataclass
class Player:
x: int
y: int
sprite: SPRITE_TYPE
spritelist: Sequence[SPRITE_TYPE] | None = None
speed: int = 1
atk: int = 1
strength: int = 0
dexterity: int = 0
intelligence: int = 0
direct: Sides = Sides.DOWN
is_alive: bool = True
vida: int = 10
inventory: list = field(default_factory=list)
level: int = 1
exp_atual: int = 0
exp_para_upar: int = 10
exp_rate: int = 1
exp_progresso: float = 3.14
skill_1: Callable = None
@dataclass
class Enemy:
x: int
y: int
sprite: SPRITE_TYPE
sprite_list: Sequence[SPRITE_TYPE] | None = None
speedx: float = 0
speedy: float = 0
exp: int = 1
vida: int = 10
def walk(self):
self.speedx = pyxel.sin(pyxel.frame_count % 360)
self.speedy = pyxel.cos(pyxel.frame_count % 360)
self.x %= pyxel.width
self.y %= pyxel.height
@dataclass
class Projectile:
x: int
y: int
sprite: SPRITE_TYPE | None = None
sprite_list: Sequence[SPRITE_TYPE] | None = None
speedx: int = 0
speedy: int = 0
duration: int = 30
angle: int = 0
damage: int = 0
@dataclass
class Item:
x: int
y: int
sprite: SPRITE_TYPE
sprite_list: Sequence[SPRITE_TYPE] | None = None
exp: int = 0
@dataclass
class Portal:
x: int
y: int
sprite: SPRITE_TYPE
sprite_list: Sequence[SPRITE_TYPE] | None = None