fpsClock = pygame.time.Clock() windowSurfaceObj = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.DOUBLEBUF) pygame.display.set_caption("Street Pirates Vs. Ninja") fontObj = pygame.font.Font('freesansbold.ttf', 42) msg = "Hello world!" scene = Scene([ [2, 2, 0], [1, 0, 0] ]) screen = Screen(windowSurfaceObj, scene) listener = EventListener(scene) bluecolor = pygame.Color(0, 0, 255) msg = "Hello world" while True: listener.listen() screen.draw() msg = str(scene._players[0].position()) msg1 = str(scene._players[0].speed()) # msg += str(scene._players[1].position()) msgSurfaceObj = fontObj.render(msg, False, bluecolor) msgRectObj = msgSurfaceObj.get_rect() scene.update() msgRectObj.topleft = (10, 20) windowSurfaceObj.blit(msgSurfaceObj, msgRectObj) pygame.display.update() #scene.moveForward(0, 0.001) #scene.moveRight(0, .001) scene.moveLeft(0, .001) print msg + '!' + msg1
class Main: """ Main class for the game. """ def __init__(self, width, height, caption="Street Pirates Vs. Ninjas"): """ Constructor. @param self [Main] itself @param width [Int] width of the window @param height [Int] height of the window @param caption [String] caption of the window """ self.width = width self.height = height # pygame objects initialization pygame.init() icon = pygame.image.load("assets/Icone.png") pygame.display.set_icon(icon) self._soundManager = SoundManager() self._soundManager.playMenuMusic() self._fpsClock = pygame.time.Clock() self._window = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF) pygame.display.set_caption(caption) pygame.mouse.set_cursor(*pygame.cursors.tri_left) # game objects initialization self._scene = Scene([[100, 0, 0], [-100, 0, 0]], self) self._listener = EventListener(self._scene, self) self._startMenu = StartMenu(self) self._startMenu.drawSplashScreen() # just before loading self._screen = Screen(self._window, self._scene, self._startMenu) self._startMenu.draw() # main object properties initialization self.state = GameState.START_MENU self.loop = True def start(self): """ Launches the main loop of the game. @param self [Main] itself """ # main loop while self.loop: if self.state == GameState.START_MENU: self._listener.listen() self._startMenu.draw() elif self.state == GameState.IN_GAME: self._listener.listen() self._screen.draw() self._fpsClock.tick(30) def stop(self): """ Definitely stop the main loop. @param self [Main] itself """ self.loop = False def changeState(self, state): self.state = state self._soundManager.stop() if state == GameState.IN_GAME: self._soundManager.playMusic("fightmusic")