class TestGame(RBGame): def __init__(self): super(TestGame, self).__init__() self.initGraphics(200, 200) self.testGraphics = self._graphics self.initController() self.testController = self._controller self.testController.registerKeyFunction("q", self.quit) self.testPlayer = TestPlayer(0, 0, "ship.png") self.testController.registerKeyFunction("Left", self.testPlayer.moveLeft) self.testController.registerKeyFunction("Right", self.testPlayer.moveRight) self.testImage = RBImage("ship.png", RB2DPosition(100, 100)) self.testText = RBText("SHIP", RB2DPosition(100, 50)) self._running = True def update(self): count = 0 while self._running: super(TestGame, self).update() self.testPlayer.draw(self.testGraphics) count += 1 if count == 30: self.testImage.undraw(self.testGraphics) self.testText.undraw(self.testGraphics) elif count < 30: self.testImage.draw(self.testGraphics, 100, 100) self.testText.draw(self.testGraphics) def quit(self): self._running = False
class Ball: def __init__(self, img): self._velocity = RBVelocity(1, 135) self._pos = RB2DPosition(100, 0) self._img = RBImage(img, RB2DPosition(100, 0)) def update(self): self._pos.movePos(self._velocity.getVelocityX(), self._velocity.getVelocityY()) if self._pos.getX() < 0 or self._pos.getX() > 350: self._velocity.changeAngle(90) self._velocity.changeSpeed(1) elif self._pos.getY() < 0 or self._pos.getY() > 450: self._velocity.changeAngle(90) self._velocity.changeSpeed(1) def draw(self, graphics): if self._img: self._img.draw(graphics, self._pos.getX(), self._pos.getY())