-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_player.py
61 lines (43 loc) · 1.62 KB
/
class_player.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
import pygame
from constantes import *
from class_bullet import *
class Player(pygame.sprite.Sprite):
def __init__(self, all_sprites, bullets, player_list, sound) -> None:
super().__init__()
self.sprites = player_list
self.current_sprite = 0
self.image = self.sprites[self.current_sprite]
self.rect = self.image.get_rect()
self.rect.x = ANCHO_VENTANA // 2
self.rect.y = ALTO_VENTANA - 100
self.speed_x = 0
self.all_sprites = all_sprites
self.bullets = bullets
self.is_animating = False
self.sound = sound
def animating(self):
self.is_animating = True
def update(self):
if self.is_animating:
self.current_sprite += 0.2
if self.current_sprite >= len(self.sprites):
self.current_sprite = 0
self.is_animating = False
self.image = self.sprites[int(self.current_sprite)]
self.speed_x = 0
keystate = pygame.key.get_pressed()
if keystate[pygame.K_LEFT]:
self.speed_x = -5
if keystate[pygame.K_RIGHT]:
self.speed_x = 5
self.rect.x += self.speed_x
if self.rect.right > ANCHO_VENTANA:
self.rect.right = ANCHO_VENTANA
if self.rect.left < 0:
self.rect.left = 0
def shoot(self):
bullet = Bullet(self.rect.centerx, self.rect.top)
self.all_sprites.add(bullet)
self.bullets.add(bullet)
self.sound.play()
self.sound.set_volume(0.3)