Strip old stuff, double entries

pull/2/head
kaqu 2 years ago
parent c3947790c8
commit dc7b6a487a
  1. 4
      evalgamepad.py
  2. BIN
      pictures/pong.jpeg
  3. BIN
      pictures/pong_background.png
  4. 0
      pictures/pong_background_test.png
  5. 107
      simple_pong.py

@ -27,8 +27,8 @@ BTN_BASE4 = 128 # [Centre right]
GAMEAREA_MIN_X = 0 # Game area definition
GAMEAREA_MAX_X = 1920 # Assume FHD resolution
GAMEAREA_MIN_Y = 0
GAMEAREA_MAX_Y = 1080
GAMEAREA_MIN_Y = 15
GAMEAREA_MAX_Y = 920-GAMEAREA_MIN_Y
def init_player(path):
# Gamepad init.

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

@ -23,105 +23,18 @@ from PyQt5.QtGui import QPainter, QBrush, QPen
import evalgamepad
# Buttons in 'state<n>'
BTN_TRIGGER = 1 # [Blue/X]
BTN_THUMB = 2 # [Red/A]
BTN_THUMB2 = 4 # [Yellow/B]
BTN_TOP = 8 # [Green/Y]
BTN_TOP2 = 16 # [Frontal left]
BTN_PINKIE = 32 # [Frontal right]
BTN_BASE3 = 64 # [Centre left]
BTN_BASE4 = 128 # [Centre right]
GAMEAREA_MIN_X = 0 # Game area definition
GAMEAREA_MAX_X = 1920 # Assume FHD resolution
GAMEAREA_MIN_Y = 0
GAMEAREA_MAX_Y = 1080
ball_x = 0
ball_y = 0
"""
class pongQT5BaseClass(QWidget):
""Pong GUI""
def __init__(self):
""Qt5 requirement""
super().__init__() # Init base classes
self.initUI() # Init our own stuff
def initUI(self):
""Initialize Qt5 & pong setup""
qlblBall = QLabel(self)
#q.setAutoFillBackground(False) # No automatic filling
#q.RenderFlags = 0 # Disable automatic rendering
#q.WA_OpaquePaintEvent = True # We paint over everything ourself
#q.WA_PaintOnScreen = True # No parent background propagation please!
#q.WA_NoSystemBackground = True # No parent background propagation please!
# Headline
self.qpbHeader = QPushButton("Ball")
f = self.qpbHeader.font()
f.setPointSize(32)
self.qpbHeader.setFont(f)
#self.qpbHeader.setFrameStyle(QFrame.Panel or QFrame.Sunken)
#self.qpbHeader.setTextFormat(Qt.PlainText)
#self.qpbHeader.setText("Boat Detector")
#self.qpbHeader.setAlignment(Qt.AlignCenter or Qt.AlignHCenter)
p = self.qpbHeader.palette()
p.setColor(self.qpbHeader.backgroundRole(), Qt.darkCyan)
p.setColor(self.qpbHeader.foregroundRole(), Qt.lightGray)
self.qpbHeader.setPalette(p)
self.qpbHeader.autoFillBackground()
self.addWidget(self.qpbHeader,1)
self.move(300, 200) # Upper left corner
self.setWindowTitle("Simple Pong")
self.Width = 1024 # Indicate non-valid entry for 1st event
self.Height = 800
# Modify main window background
pW = self.qpbHeader.parentWidget()
p = pW.palette()
p.setColor(pW.backgroundRole(), QColor(8,8,0,255)) #Qt.darkGray)
pW.setPalette(p)
pW.setAutoFillBackground(True)
#self.show()
self.showFullScreen()
#self.resize(res_x, res_y)
self.timer = QTimer() # Start processing 'loop'
self.timer.setInterval(50) # 50ms
self.timer.setTimerType(Qt.PreciseTimer)
self.timer.timeout.connect(self.on_timer)
self.timer.start()
# if bBoatDetected:
# playsound('/usr/lib/libreoffice/share/gallery/sounds/laser.wav')
@pyqtSlot()
def on_timer(self):
''Qt5 timer event''
self.timer.stop() # Block overrun
# Do something
self.timer.start() # Re-enable
# end class
"""
def pong_game(ball, player1, player2):
# 1. Retrieve user entries
bChanged = evalgamepad.eval_gamepad(player1)
if bChanged:
if (player1["state"] & BTN_BASE4) > 0: # Exit?
if (player1["state"] & evalgamepad.BTN_BASE4) > 0: # Exit?
print("Player #1 aborted game")
return False
else:
print("Player #1: {}h".format(hex(player1["state"])))
bChanged = evalgamepad.eval_gamepad(player2) # Exit?
if bChanged:
if (player2["state"] & BTN_BASE4) > 0:
if (player2["state"] & evalgamepad.BTN_BASE4) > 0:
print("Player #2 aborted game")
return False
else:
@ -138,8 +51,7 @@ def pong_game(ball, player1, player2):
# 3. Adjust object positions
evalgamepad.eval_object(ball)
# 4. Refresh game area drawing
#evalgamepad.draw_objects(ball, player1, player2)
# use: playsound('/usr/lib/libreoffice/share/gallery/sounds/laser.wav')
return True
class pongWindow(QMainWindow):
@ -149,7 +61,7 @@ class pongWindow(QMainWindow):
self.top= 0
self.left= 0
self.width = 1920
self.height = 1080
self.height = 960
self.InitWindow()
def InitWindow(self):
@ -174,13 +86,17 @@ class pongWindow(QMainWindow):
painter.setPen(QPen(Qt.white, 1, Qt.SolidLine)) # Circle: Color/Linewidth/Pattern
painter.setBrush(QBrush(Qt.white, Qt.SolidPattern)) # Fill
pic = QPixmap("pong_background.png")
pic = QPixmap("pictures/pong_background.png")
painter.drawPixmap(self.rect(), pic) # Game background
painter.drawEllipse(ball["x"], ball["y"], 50, 50) # Ball
painter.drawRect(10, player1["y"], 20, 100) # Player left
painter.drawRect(GAMEAREA_MAX_X - 30, player2["y"], 20, 100) # Player right
painter.drawRect(evalgamepad.GAMEAREA_MAX_X - 30, player2["y"], 20, 100) # Player right
painter.drawText(10, 30, "X: {}".format(ball["x"]))
painter.drawText(10, 60, "y: {}".format(ball["y"]))
@pyqtSlot()
def on_timer(self):
'''Qt5 timer event'''
@ -194,6 +110,7 @@ class pongWindow(QMainWindow):
self.update() # Redraw
self.timer.start() # Re-enable
if __name__ == '__main__':
try:
# Initialize

Loading…
Cancel
Save