-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.py
executable file
·66 lines (51 loc) · 1.62 KB
/
launcher.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
#!/usr/bin/python
import sys, time
from PyQt4 import QtCore, QtGui
from enemies import *
from towers import *
from scoreboard import *
from gameboard import *
import globals
class TowerDefence(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setFixedSize(800,520)
self.setWindowTitle('Dat Tower Defence!')
self.mainBoard = gameBoard(self)
self.secondaryBoard = scoreBoard(self)
self.setCentralWidget(self.mainBoard)
self.mainBoard.start()
self.secondaryBoard.start()
self.timer = QtCore.QBasicTimer()
self.timer.start(globals.gameSpeed, self)
self.update()
#game thread
def timerEvent(self, event):
if event.timerId() == self.timer.timerId():
#moves every enemy in the list of enemies
self.mainBoard.timedLoop()
self.repaint()
else:
QtGui.QFrame.timerEvent(self, event)
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_P:
self.mainBoard.pause()
def mousePressEvent(self, event):
self.mainBoard.placeTowers()
def eventFilter(self, source, event):
if event.type() == QtCore.QEvent.MouseMove:
if event.buttons() == QtCore.Qt.NoButton and str(source).find("gameBoard") > 0:
pos = event.pos()
#print pos.x(), pos.y()
#self.edit.setText('x: %d, y: %d' % (pos.x(), pos.y()))
self.mainBoard.updateMouse(pos.x(), pos.y())
self.mainBoard.isMouseIn = True
else:
self.mainBoard.isMouseIn = False
self.mainBoard.repaint()
return QtGui.QMainWindow.eventFilter(self, source, event)
app = QtGui.QApplication(sys.argv)
towerdef = TowerDefence()
towerdef.show()
app.installEventFilter(towerdef)
sys.exit(app.exec_())