def main(): pygame.init() #Setting up the screen screen = pygame.display.set_mode(SCREEN_SIZE) pygame.display.set_caption('TOP DOWN SHOOTER') icon = pygame.image.load(ICON_FILE).convert() pygame.display.set_icon(icon) pygame.mouse.set_visible(False) clock = pygame.time.Clock() game_controller = GameController(SCREEN_SIZE) mouse_id = game_controller.add_entity(MouseCursor()) player_id = game_controller.add_entity(Player()) game_controller.add_entity(CircleCollide()) bullets = [] #main game loop running = True while running: clock.tick(FPS) #event catching for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False #RUN CONTROLLER keys = pygame.key.get_pressed() mouse_btns = pygame.mouse.get_pressed() if mouse_btns[0]: add_bullet(bullets, game_controller, player_id) game_controller.control(keys, mouse_btns) game_controller.collide() game_controller.collide_walls() game_controller.apply_physics(clock.get_time()) player_to_mouse = pygame.mouse.get_pos( ) - game_controller.components['body'][player_id].position game_controller.components['body'][mouse_id].position = Vector2D( 0, 0) + pygame.mouse.get_pos() game_controller.components['body'][ player_id].rotation = player_to_mouse.angle_from_vector() #rendering screen.fill(BLACK) game_controller.render(screen) pygame.display.flip() pygame.quit()
def main(): pygame.init() #Setting up the screen screen = pygame.display.set_mode(SCREEN_SIZE) pygame.display.set_caption('TOP DOWN SHOOTER') icon = pygame.image.load(ICON_FILE).convert() pygame.display.set_icon(icon) pygame.mouse.set_visible(False) clock = pygame.time.Clock() game_controller = GameController(SCREEN_SIZE) mouse_id = game_controller.add_entity(MouseCursor()) player_id = game_controller.add_entity(Player()) game_controller.add_entity(CircleCollide()) bullets = [] #main game loop running = True while running: clock.tick(FPS) #event catching for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False #RUN CONTROLLER keys = pygame.key.get_pressed() mouse_btns = pygame.mouse.get_pressed() if mouse_btns[0]: add_bullet(bullets, game_controller, player_id) game_controller.control(keys, mouse_btns) game_controller.collide() game_controller.collide_walls() game_controller.apply_physics(clock.get_time()) player_to_mouse=pygame.mouse.get_pos()-game_controller.components['body'][player_id].position game_controller.components['body'][mouse_id].position = Vector2D(0, 0) + pygame.mouse.get_pos() game_controller.components['body'][player_id].rotation=player_to_mouse.angle_from_vector() #rendering screen.fill(BLACK) game_controller.render(screen) pygame.display.flip() pygame.quit()
class AppManager: """ this class is the manager of the whole app, define interface between user of the app (developer) and what this app do. simply this class manages the communication between 4 main classes (VideoSequence, HandDetector, GestureDetector, GameController)""" TAG = "AppManager" def __init__(self, output=True, debug=False, feeding=False): Logger.debug = debug Logger.out = output self.vs = Vs().start() self.hd = Hd(self.vs.getFrames("BGR")[-2]) self.gd = Gd() #self.gc = AsyncControlRepeater(Gc(ConfigReader.default()), maxBufferSize=1).start() self.gc = Gc(ConfigReader.default(), feeding=feeding) self.feeding = feeding def showAllImages(self): currFrame = self.vs.getFrames("BGR")[0] # bgModel = self.hd.getBackgroundModel() # skinBgModel = self.hd.getSkinBackgroundModel() images, titles = self.hd.getState() showImages(images, titles) showImages((currFrame, ), ('Camera', )) def step(self): startT = getTickCount() #* capturing e1 = getTickCount() frames = self.vs.process() Logger.GeneralLogger.o(timeMessage("frame process", e1), tag="TIME") #* detection e1 = getTickCount() self.hd.detect(frames("gray"), frames("BGR")[0]) Logger.GeneralLogger.o(timeMessage("hand detection", e1), tag="TIME") #* recognition e1 = getTickCount() gesture, center = self.gd.recognize(self.hd.roi, self.hd.finalOut) Logger.GeneralLogger.o("{} detected in {}".format(gesture, center), tag=self.TAG) Logger.GeneralLogger.o(timeMessage("gesture recognition", e1), tag="TIME") endT = getTickCount() #* controlling self.gc.control(gesture, center, (endT - startT) / getTickFrequency()) #self.gc.addGstRecognition(gesture, center) e1 = getTickCount() Logger.ImageLogger.o(self.vs.getFrames("BGR")[0], 'camera') Logger.GeneralLogger.o(timeMessage("imshow the image itself", e1), tag="TIME")