May 2019
Intermediate to advanced
542 pages
13h 37m
English
In this game, each tank will only be allowed one bullet on the screen at a time. This simplifies our game code, but also keeps the game relatively challenging.
To implement these bullets, we'll create another QGraphicsObject object called Bullet, which is animated to move along the y axis.
Let's start our Bullet class as follows:
class Bullet(qtw.QGraphicsObject): hit = qtc.pyqtSignal() def __init__(self, y_pos, up=True): super().__init__() self.up = up self.y_pos = y_pos
The bullet class starts by defining a hit signal indicating that it has hit an enemy tank. The constructor takes a y_pos argument to define the starting point of the bullet, and a Boolean indicating whether the bullet is to travel up or down. These arguments ...
Read now
Unlock full access