-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapon.py
194 lines (150 loc) · 7.22 KB
/
weapon.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
from __future__ import annotations
from typing import TYPE_CHECKING
from physics import addtomove
if TYPE_CHECKING:
from main import Game
import pygame
from entity import Entity
from math import sin, cos, pi
from utils import get_circle
from CONSTS import coordinate
class Fleche(Entity):
def __init__(self, game: Game, x: int, y: int, angle: int, size: int):
super().__init__(game, x, y)
self.original = pygame.image.load("assets/textures/weapons/arrow.png")
self.x_base = self.x
self.y_base = self.y
self.angle = angle
self.original = pygame.transform.scale(self.original, (size, size))
self.image = pygame.transform.rotate(self.original, angle)
def move_with_rota(self, angle, x, y):
self.x_base = x - 15
self.y_base = y - 50
self.rx = self.x_base + cos(angle) * 120
self.ry = self.y_base + sin(angle) * 120
self.image = pygame.transform.rotate(self.original, - (angle * 360 / (2 * pi)) + self.angle)
self.update_co_from_rco()
# all_moves: list[tuple[float, float, list[list[bool]], coordinate, Entity, bool, int, Callable]] = list()
class ChargeBar(Entity):
def __init__(self, game: Game, x: int, y: int):
super().__init__(game, x, y)
self.image = pygame.Surface((0, 15))
self.image.fill((255, 0, 0))
self.taille = 0
self.charging = False
self.x_base = self.x
self.y_base = self.y
def up_taille(self, vitesse: float, x, y):
self.taille += vitesse
self.image = self.image = pygame.Surface((self.taille, 15))
self.image.fill((255, 0, 0))
def reset_taille(self):
self.taille = 0
self.image = self.image = pygame.Surface((self.taille, 15))
def moove_bar(self, x, y):
self.x_base = x
self.y_base = y
self.rx = self.x_base - 30
self.ry = self.y_base - 100
self.update_co_from_rco()
class Weapon(Entity):
def __init__(self, game: Game, x: int, y: int, image: str, angle: float, size: int):
super().__init__(game, x, y)
self.original = pygame.image.load(image)
self.angle = angle
self.original = pygame.transform.scale(self.original, (size, size))
self.image = pygame.transform.rotate(self.original, angle)
self.x_base = self.x - 15
self.y_base = self.y - 50
def move_with_rota(self, angle, x, y):
self.x_base = x - 15
self.y_base = y - 50
self.rx = self.x_base + cos(angle) * 60
self.ry = self.y_base + sin(angle) * 60
self.image = pygame.transform.rotate(self.original, - (angle * 360 / (2 * pi)) + self.angle)
self.update_co_from_rco()
def shoot(self, power, inclinaison):
pass
class Bazooka(Weapon):
def __init__(self, game: Game, x: int, y: int, angle: float):
super().__init__(game, x, y, "assets/textures/weapons/bazooka.png", angle, 50)
def shoot(self, power, inclinaison):
pro_bazooka = ProBazooka(self.game, self.x + 25, self.y + 25)
print("x: " + str(self.x) + " y: " + str(self.y))
addtomove(power * pro_bazooka.speed, inclinaison, pro_bazooka, pro_bazooka.destroy, pro_bazooka.kill)
class Sniper(Weapon):
def __init__(self, game: Game, x: int, y: int, angle: float):
super().__init__(game, x, y, "assets/textures/weapons/sniper.png", angle, 50)
def shoot(self, power, inclinaison):
pro_sniper = ProSniper(self.game, self.x + 25, self.y + 25)
addtomove(power * pro_sniper.speed, inclinaison, pro_sniper, pro_sniper.destroy, pro_sniper.kill)
class Grenade(Weapon):
def __init__(self, game: Game, x: int, y: int, angle: float):
super().__init__(game, x, y, "assets/textures/weapons/grenade.png", angle, 50)
def shoot(self, power, inclinaison):
pro_grenade = ProGrenade(self.game, self.x + 25, self.y + 25)
addtomove(power * pro_grenade.speed, inclinaison, pro_grenade, pro_grenade.destroy, pro_grenade.kill)
class GrenadeFrag(Weapon):
def __init__(self, game: Game, x: int, y: int, angle: float):
super().__init__(game, x, y, "assets/textures/weapons/grenade_frag.png", angle, 50)
def shoot(self, power, inclinaison):
pro_grenade_frag = ProFragGrenade(self.game, self.x + 25, self.y + 25)
addtomove(power * pro_grenade_frag.speed, inclinaison, pro_grenade_frag, pro_grenade_frag.destroy,
pro_grenade_frag.kill)
class Projectile(Entity):
def __init__(self, game: Game, x: int, y: int, image: str, speed: float, taille: int, rebond: bool, damage: int):
super().__init__(game, x, y)
self.can_bounce = False
self.image = pygame.Surface((taille, taille))
self.speed = speed
self.rebond = rebond
self.damage = damage
self.original = pygame.image.load(image)
self.image = pygame.transform.scale(self.original, (taille, taille))
def destroy(self, *args):
self.kill()
def explosion_damage(self, explosions: list[tuple[coordinate, float, float]]):
"""
:param explosions: Tuple[center, radius]
"""
for center, radius, damage in explosions:
for player in self.game.players:
dist = ((player.x - center[0]) ** 2 + (player.y - center[1]) ** 2) ** 0.5
if dist < radius:
player.hit(damage * (dist / radius))
class ProBazooka(Projectile):
def __init__(self, game: Game, x: int, y: int):
super().__init__(game, x, y, "assets/textures/weapons/explosion.png", 12, 25, False, 45)
def destroy(self, *args):
if not args[-1]:
self.game.map.destruction_stack.append(((self.x, self.y), 80))
self.explosion_damage([((self.x, self.y), 80, self.damage)])
super().destroy()
class ProSniper(Projectile):
def __init__(self, game: Game, x: int, y: int):
super().__init__(game, x, y, "assets/textures/weapons/explosion.png", 120, 8, False, 90)
def destroy(self, *args):
if not args[-1]:
self.game.map.destruction_stack.append(((self.x, self.y), 15))
self.explosion_damage([((self.x, self.y), 15, self.damage)])
super().destroy()
class ProGrenade(Projectile):
def __init__(self, game: Game, x: int, y: int):
super().__init__(game, x, y, "assets/textures/weapons/grenade.png", 7, 20, True, 50)
self.can_bounce = True
def destroy(self, *args):
if not args[-1]:
self.game.map.destruction_stack.append(((self.x, self.y), 100))
self.explosion_damage([((self.x, self.y), 100, self.damage)])
super().destroy()
class ProFragGrenade(Projectile):
def __init__(self, game: Game, x: int, y: int):
super().__init__(game, x, y, "assets/textures/weapons/grenade_frag.png", 7, 20, True, 20)
self.can_bounce = True
def destroy(self, *args):
if not args[-1]:
circle = get_circle(5, pos := (self.x, self.y), radius := 80)
self.game.map.destruction_stack.append((pos, radius))
self.game.map.destruction_stack.extend([(circle[i], 45.0) for i in range(len(circle))])
self.explosion_damage([(circle[i], 45.0, self.damage) for i in range(len(circle))] + [(pos, 45, self.damage)])
super().destroy()