-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_controller.py
76 lines (62 loc) · 1.97 KB
/
game_controller.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
"""
Classes that take user input and do somethings.
"""
import pygame
class ButtonControl: # pylint: disable=too-few-public-methods
"""
A class to define button functions within the game.
Attributes:
__button: A Button instance.
__pos: A tuple of ints representing the location of the mouse.
"""
def __init__(self):
"""
Initialize an instance of the ButtonControl class.
"""
self.__pos = pygame.mouse.get_pos()
def check_press(self, button):
"""
Checks if the button is pressed.
Returns:
A boolean representing whether or not a button is pressed.
"""
action = False
# get mouse position
self.__pos = pygame.mouse.get_pos()
# check mouseover and clicked conditions
if button.rect.collidepoint(self.__pos):
if pygame.mouse.get_pressed()[0] == 1:
action = True
return action
class Arrow:
"""
A class to define the function of a button press
Attributes:
__pizza_speed: An integer representing the number of pixels the pizza
moves with each press of an arrow key.
"""
def __init__(self, speed):
"""
Initialize an instance of the arrow class.
Args:
speed: An int representing the distance the pizza moves on a press
of an arrow key.
"""
self.__pizza_speed = speed
def move_pizza(self, pizza):
"""
A function to move the pizza left or right based on arrow interaction.
Args:
pizza: A PizzaStatus instance.
"""
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
pizza.update_position(-(self.__pizza_speed))
elif keys[pygame.K_RIGHT]:
pizza.update_position(self.__pizza_speed)
@property
def speed(self):
"""
Returns an int representing the speed of the pizza.
"""
return self.__pizza_speed