-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontrols.py
More file actions
56 lines (44 loc) · 2.25 KB
/
Copy pathcontrols.py
File metadata and controls
56 lines (44 loc) · 2.25 KB
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
import pygame
from settings import *
from support import import_folder
class Control:
def __init__(self):
# general
self.display_surface = pygame.display.get_surface()
self.buttons = ['up', 'down', 'left', 'right', 'attack', 'magic', 'switch']
self.clicked = ''
# Rect objects for buttons
self.button_rects = {
'up': pygame.Rect(100, 600, BTN_WIDTH, BTN_HEIGHT),
'down': pygame.Rect(100, 700, BTN_WIDTH, BTN_HEIGHT),
'left': pygame.Rect(45, 650, BTN_WIDTH, BTN_HEIGHT),
'right': pygame.Rect(155, 650, BTN_WIDTH, BTN_HEIGHT),
'attack': pygame.Rect(700, 600, BTN_WIDTH, BTN_HEIGHT),
'magic': pygame.Rect(600, 650, BTN_WIDTH, BTN_HEIGHT),
'switch': pygame.Rect(400, 700, BTN_WIDTH, BTN_HEIGHT),
}
def display_controller(self, player):
for button in self.buttons:
full_path = f'./assets/chrono/buttons/{button}/{button}.png'
image = pygame.image.load(full_path).convert_alpha()
rect = pygame.Rect(0, 0, BTN_WIDTH, BTN_HEIGHT)
if button == 'up':
rect.topleft = (UP_BTN_X, UP_BTN_Y)
elif button == 'down':
rect.topleft = (DOWN_BTN_X, DOWN_BTN_Y)
elif button == 'left':
rect.topleft = (LEFT_BTN_X, LEFT_BTN_Y)
elif button == 'right':
rect.topleft = (RIGHT_BTN_X, RIGHT_BTN_Y)
elif button == 'attack':
rect.topleft = (ATTACK_BTN_X, ATTACK_BTN_Y)
elif button == 'magic':
rect.topleft = (MAGIC_BTN_X, MAGIC_BTN_Y)
elif button == 'switch':
rect.topleft = (SWITCH_BTN_X, SWITCH_BTN_Y)
self.display_surface.blit(image, rect.topleft)
# Check for button click
mouse_pos = pygame.mouse.get_pos()
if rect.collidepoint(mouse_pos):
self.clicked = button
player.clicked = button