-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
115 lines (97 loc) · 4.25 KB
/
game.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QGridLayout
from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QPushButton
import sys
from pixel_editor import PixelEditor
from PyQt5.QtWidgets import QWidget, QVBoxLayout
from board_gui import BoardGUI
GAME_BOY_PURPLE = QColor(100, 100, 160)
GAME_BOY_BUTTON = QColor(200, 200, 200)
class GameboyAdvanceWindow(QWidget):
def __init__(self, main_window=None):
super().__init__()
self.pixel_size = 6
self.num_of_colors = 4
# Set color palette
palette = QPalette()
palette.setColor(QPalette.Window, GAME_BOY_PURPLE)
palette.setColor(QPalette.WindowText, GAME_BOY_BUTTON)
self.setPalette(palette)
# Set layout
layout = QVBoxLayout()
self.setLayout(layout)
layout.addStretch()
# Set fixed window size
self.setFixedSize(300, 500)
image_editor = PixelEditor()
self.main_window = BoardGUI(image_editor)
layout.addWidget(self.main_window)
# Add arrow buttons
arrowLayout = QGridLayout()
buttonUp = QPushButton('^')
buttonDown = QPushButton('v')
buttonLeft = QPushButton('<')
buttonRight = QPushButton('>')
arrowLayout.addWidget(buttonUp, 0, 1)
arrowLayout.addWidget(buttonDown, 2, 1)
arrowLayout.addWidget(buttonLeft, 1, 0)
arrowLayout.addWidget(buttonRight, 1, 2)
# bind arrow buttons to the image editor
buttonUp.clicked.connect(self.increase_num_colors)
buttonLeft.clicked.connect(self.decrease_num_colors)
buttonRight.clicked.connect(self.increase_pixel_size)
buttonDown.clicked.connect(self.decrease_pixel_size)
# Add A and B buttons
buttonLayout = QHBoxLayout()
buttonA = QPushButton('A')
buttonB = QPushButton('B')
buttonA.setStyleSheet(
"background-color: rgba(211, 212, 207, 128); border-radius: 15px; min-width: 30px; min-height: 30px;")
buttonB.setStyleSheet(
"background-color: rgba(211, 212, 207, 128); border-radius: 15px; min-width: 30px; min-height: 30px;")
buttonLayout.addWidget(buttonA)
buttonLayout.addWidget(buttonB)
# Add arrow and button layouts to main layout
controlLayout = QHBoxLayout()
layout.addLayout(controlLayout)
controlLayout.addLayout(arrowLayout)
controlLayout.addLayout(buttonLayout)
# Add LED light
ledLight = QLabel()
ledLight.setStyleSheet(
"background-color: red; border-radius: 50%; min-width: 10px; min-height: 10px;")
layout.addWidget(ledLight, 0, Qt.AlignCenter)
# Add Start and Select buttons
startSelectLayout = QHBoxLayout()
buttonStart = QPushButton('Start')
buttonSelect = QPushButton('Select')
buttonStart.setStyleSheet(
"background-color: rgba(211, 212, 207, 128); border-radius: 15px; min-width: 30px; min-height: 30px;")
buttonSelect.setStyleSheet(
"background-color: rgba(211, 212, 207, 128); border-radius: 15px; min-width: 30px; min-height: 30px;")
startSelectLayout.addWidget(buttonStart)
startSelectLayout.addWidget(buttonSelect)
layout.addLayout(startSelectLayout)
def increase_pixel_size(self):
self.pixel_size += 1
self.main_window.image_editor.change_pixel_size(self.pixel_size)
self.main_window.display_image()
def decrease_pixel_size(self):
if self.pixel_size > 1:
self.pixel_size -= 1
self.main_window.image_editor.change_pixel_size(self.pixel_size)
self.main_window.display_image()
def increase_num_colors(self):
self.num_of_colors += 1
self.main_window.image_editor.change_num_colors(self.num_of_colors)
self.main_window.display_image()
def decrease_num_colors(self):
if self.num_of_colors > 1:
self.num_of_colors -= 1
self.main_window.image_editor.change_num_colors(self.num_of_colors)
self.main_window.display_image()
app = QApplication(sys.argv)
window = GameboyAdvanceWindow()
window.show()
app.exec_()