-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.py
65 lines (50 loc) · 1.61 KB
/
control.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
import pygame
from pygame.locals import *
class Control:
# Acciones que puede realizar un jugador
def idle(self):
raise NotImplementedError()
def jump(self):
raise NotImplementedError()
def left(self):
raise NotImplementedError()
def right(self):
raise NotImplementedError()
def shoot(self):
raise NotImplementedError()
# # Métodos para asignar teclas a acciones
#
# def assign_jump(self, key):
# raise NotImplementedError()
#
# def assign_left(self, key):
# raise NotImplementedError()
#
# def assign_right(self, key):
# raise NotImplementedError()
#
# def assign_shoot(self, key):
# raise NotImplementedError()
class ControlKeyboard(Control):
key_jump = K_UP
key_left = K_LEFT
key_right = K_RIGHT
key_shoot = K_SPACE
def idle(self):
pressedKeys = pygame.key.get_pressed()
return all(v == 0 for v in pressedKeys[:290])
def jump(self):
pressedKeys = pygame.key.get_pressed()
return pressedKeys[self.key_jump]
def left(self):
pressedKeys = pygame.key.get_pressed()
return pressedKeys[self.key_left]
def right(self):
pressedKeys = pygame.key.get_pressed()
return pressedKeys[self.key_right]
def isShooting(self):
pressedKeys = pygame.key.get_pressed()
return pressedKeys[self.key_shoot]
def shoot(self, player, grupoSpritesDinamicos, grupoSprites, scrollx, event):
if event.key == pygame.K_SPACE:
player.shoot(grupoSpritesDinamicos, grupoSprites, scrollx)