-
Notifications
You must be signed in to change notification settings - Fork 0
/
weapon.py
54 lines (45 loc) · 2.13 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
from collections import deque
import pygame as pg
from sprite_object import *
class Weapon(AnimatedSprite):
def __init__(self, game, path='resources/sprites/weapon/pistol/0.png', scale=0.5, animation_time=90):
super().__init__(game=game, path=path, scale=scale, animation_time=animation_time)
self.images = deque(
[pg.transform.smoothscale(img, (self.image.get_width() * scale, self.image.get_height() * scale))
for img in self.images])
self.weapon_pos = (HALF_WIDTH - self.images[0].get_width() // 2, HEIGHT - self.images[0].get_height())
self.reloading = False
self.num_images = len(self.images)
self.frame_counter = 0
self.damage = 500
self.weapon_types = {
'shotgun': 'resources/sprites/weapon/shotgun/0.png',
'pistol': 'resources/sprites/weapon/pistol/0.png',
'assault': 'resources/sprites/weapon/assault/0.png',
'machine gun':'resources/sprites/weapon/machine gun/0.png'
}
self.current_weapon_type = 'pistol' # Default to 'pistol' when the game starts
def change_weapon(self, weapon_type):
if weapon_type in self.weapon_types:
self.current_weapon_type = weapon_type
self.load_images(self.weapon_types[weapon_type])
def animate_shot(self):
if self.reloading:
self.game.player.shot = False
if self.animation_trigger:
self.images.rotate(-1)
self.image = self.images[0]
self.frame_counter += 1
if self.frame_counter == self.num_images:
self.reloading = False
self.frame_counter = 0
def load_images(self, path):
self.images = deque(
[pg.transform.smoothscale(img, (self.image.get_width() * self.scale, self.image.get_height() * self.scale))
for img in pg.image.load(path)])
self.num_images = len(self.images)
def draw(self):
self.game.screen.blit(self.images[0], self.weapon_pos)
def update(self):
self.check_animation_time()
self.animate_shot()