def run(self): clock = pygame.time.Clock() running = True self.scene.start() while running: for event in pygame.event.get(): if event.type == sound.MUSIC_ENDEVENT: sound.end_of_music() if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.scene.take_input("left", event) elif event.key == pygame.K_RIGHT: self.scene.take_input("right", event) elif event.key == pygame.K_UP: self.scene.take_input("up", event) elif event.key == pygame.K_DOWN: self.scene.take_input("down", event) elif event.key == pygame.K_SPACE: self.scene.take_input("action", event) elif event.key == pygame.K_ESCAPE: self.scene.take_input("back", event) self.scene = levelscene.LevelScene(self, sys.argv[1]) self.scene.start() else: self.scene.take_input("other", event) if event.type == pygame.MOUSEBUTTONDOWN: event.gpos = V2(event.pos[0] / SCALE, event.pos[1] / SCALE) if event.button == 1: self.scene.take_input("click", event) if event.button == 3: self.scene.take_input("rightclick", event) if event.type == pygame.MOUSEBUTTONUP: event.gpos = V2(event.pos[0] / SCALE, event.pos[1] / SCALE) if event.button == 1: self.scene.take_input("unclick", event) if event.button == 3: self.scene.take_input("unrightclick", event) if event.type == pygame.MOUSEMOTION: event.gpos = V2(event.pos[0] / SCALE, event.pos[1] / SCALE) if event.buttons[0]: self.scene.take_input("mouse_drag", event) else: self.scene.take_input("mouse_move", event) dt = clock.tick() / 1000.0 self.scene.update(dt) self.render()
def load_level(self): print("in thread - start") self.levelscene = levelscene.LevelScene( self.game, self.galaxy['level'], self.galaxy['alien'], self.galaxy['difficulty'], self.galaxy['difficulty'], self.galaxy['name'], self.galaxy['description'] ) self.levelscene.start() print("in thread - done") return self.levelscene
def __init__(self, save): #pygame.display.set_icon(pygame.image.load(resource_path("assets/icon_2_256.png"))) pygame.mixer.pre_init(buffer=256) pygame.init() self.save = save self.scaled_screen = pygame.display.set_mode( (RES[0] * SCALE, RES[1] * SCALE)) pygame.display.set_caption("Hostile Quadrant") #sound.init() self.screen = pygame.Surface(RES) if len(sys.argv) > 1 and DEV: self.scene = levelscene.LevelScene(self, sys.argv[1]) else: self.scene = introscene.IntroScene(self) self.playing_level_index = None self.frame_time = 0
def __init__(self, save): pygame.display.set_icon(pygame.image.load(resource_path("assets/icon_2_256.png"))) pygame.mixer.pre_init(buffer=512) pygame.init() self.save = save self.scaled_screen = pygame.display.set_mode((RES[0] * SCALE, RES[1] * SCALE)) pygame.display.set_caption("Picket Puzzle") sound.init() self.screen = pygame.Surface(RES) if len(sys.argv) > 1 and DEV: if sys.argv[1] == 'credits': self.scene = creditsscene.CreditsScene(self) else: self.scene = levelscene.LevelScene(self, sys.argv[1]) else: self.scene = alphascene.AlphaScene(self) self.playing_level_index = None self.vignette = simplesprite.SimpleSprite("assets/vignette.png", (0,0))
def __init__(self, save): Game.inst = self self.debug_console = False global DEV #pygame.display.set_icon(pygame.image.load(resource_path("assets/icon_2_256.png"))) pygame.mixer.pre_init(buffer=256) pygame.init() self.save = save self.achievements = achievements.Achievements(self.save) self.intel = IntelManager(self.save) resolution = self.save.get_setting("resolution") if resolution == None: resolution = (1200,800) self.save.set_setting("resolution", resolution) self.save.save() self.set_resolution(V2(*resolution), self.save.get_setting("fullscreen")) pygame.display.set_caption("Hostile Quadrant") sound.init() text.preload() self.joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())] self.last_joy_axes = None try: self.run_info = self.save.get_run_state() if not DEV and self.run_info.anticheat_level_started: self.run_info.no_score = True self.save.set_run_state(self.run_info) self.save.save() except Exception as e: print(e) self.run_info = run.RunInfo() self.input_mode = self.INPUT_MOUSE self.player_inputs = [] self.threads = {} self.thread_return_values = {} self.thread_index = 0 if len(sys.argv) > 1: DEV = True if sys.argv[1] == "draw": self.scene = buildingcreatorscene.BuildingCreatorScene(self) elif sys.argv[1] == "editor": self.scene = leveleditorscene.LevelEditorScene(self) elif sys.argv[1] == "star": self.run_info = run.RunInfo() self.scene = starmapscene.StarMapScene(self) elif sys.argv[1] == "upgrades": self.scene = allupgradesscene.AllUpgradesScene(self) elif sys.argv[1] == "tutorial": self.scene = tutorial.tutorial1scene.Tutorial1Scene(self) elif sys.argv[1] == "game": self.scene = levelscene.LevelScene(self, "cross", "alien2", 6, 6, "Testing", "This is a test string for the description") elif sys.argv[1] == "boss": self.scene = levelscene.LevelScene(self, "boss2", "boss", 9, 9, "Boss", "It's the boss") elif sys.argv[1] == "planet": self.scene = planetgenscene.PlanetGenScene(self) elif sys.argv[1] == "new": self.scene = newgamescene.NewGameScene(self) elif sys.argv[1] == "perf": self.scene = levelscene.LevelScene(self, "choke", "alien3", 3, 3, "", "", options='performance') elif sys.argv[1] == "flowfield": self.scene = levelscene.LevelScene(self, "cross", "alien3", 1, 1, "", "", options='flowfield') elif sys.argv[1] == "multiplayer": # self.player_inputs = [ # playerinput.Player(0, playerinput.Player.INPUT_MOUSE), # playerinput.Player(1, playerinput.Player.INPUT_JOYSTICK, 0), # playerinput.Player(2, playerinput.Player.INPUT_JOYSTICK, 1), # playerinput.Player(3, playerinput.Player.INPUT_JOYSTICK, 2) # ] # self.input_mode = self.INPUT_MULTIPLAYER # self.scene = multiplayerscene.MultiplayerScene(self, 4) self.scene = multiplayermenu.MultiplayerMenu(self) else: self.scene = menuscene.MenuScene(self) else: self.scene = menuscene.MenuScene(self) #self.scene = introscene.IntroScene(self) self.playing_level_index = None self.game_speed_input = 0 self.last_joystick_pos = defaultdict(lambda:self.game_resolution / 2) self.menu_bg_cache_obj = None self.first_load = True self.frame_time = 0 self.frame_times = [] self.scale_mode = "xbr" self.fps_limited_pause = False self._profiling = False self._profile_start_time = 0 self._profiler = None
def start_level(self, level, index): self.playing_level_index = index self.scene = levelscene.LevelScene(self, level) self.scene.start()
def take_input(self, input, event): if input == "action" or input == "click": self.scene.game.scene = levelscene.LevelScene(self.scene.game) self.scene.game.scene.start()