def __init__(self, width: int, height: int, update_rate: float): Window.__init__(self, width, height, update_rate=update_rate) self.set_fullscreen(FULL_SCREEN) self.set_caption(__title__) self.settings = Settings() # shared with Game self.sound_player = AudioPlayer() self.save_manager = SaveManager('saved_games', 'scenarios') self._updated: List[Updateable] = [] # Settings, gameobjects configs, game-progress data, etc. self.configs = read_csv_files('resources/configs') # views: self._current_view: Optional[LoadableWindowView] = None self.menu_view: Menu = Menu() self.game_view: Optional[Game] = None self.show_view(LoadingScreen(loaded_view=self.menu_view)) # cursor-related: self.cursor = MouseCursor(self, get_path_to_file('normal.png')) # store viewport data to avoid redundant get_viewport() calls and call # get_viewport only when viewport is actually changed: self.current_viewport = self.get_viewport() # keyboard-related: self.keyboard = KeyboardHandler(window=self)
def main(): defaults = dict( center_x=0, center_y=0, ) window = Window() view = UIView() style = UIStyle.default_style() style.set_class_attrs(UILabel.__name__, ) layout = ListLayout() layout.pack(UILabel(text="1. Red Sun", **defaults), space=15) layout.pack(UILabel(text="2. Green Gras", **defaults)) layout.pack(UILabel(text="3. Blue Sky", **defaults), space=20) view.manager.add_layout(layout) layout = ListLayout(vertical=False) layout.pack(UILabel(text="4. Red Sun", **defaults), space=15) layout.pack(UILabel(text="5. Green Gras", **defaults)) layout.pack(UILabel(text="6. Blue Sky", **defaults), space=20) view.manager.add_layout(layout) window.show_view(view) arcade.run()
def main(): """ Main method """ arcadeWindow: Window = Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) gameView: PyTrekView = PyTrekView() arcadeWindow.set_exclusive_keyboard(exclusive=False) arcadeWindow.show_view(gameView) gameView.setup() arcadeRun()
def on_draw(player: arcade.Window): arcade.start_render() arcade.draw_text("Buffs", 20, 570, arcade.color.BLACK, 50) arcade.draw_text("Item Count:", 20, 520, arcade.color.BLACK, 30) arcade.draw_text(str(len(player.buff_list)), 250, 520, arcade.color.BLACK, 30) arcade.draw_text("Q - Sort", 30, 30, arcade.color.BLACK, 60) arcade.draw_text("E - Search", 370, 30, arcade.color.BLACK, 60) arcade.draw_xywh_rectangle_outline(10, 405, 450, 70, arcade.color.GRAY, 3) arcade.draw_xywh_rectangle_outline(5, 290, 460, 90, arcade.color.BLACK, 5) arcade.draw_xywh_rectangle_outline(10, 193, 450, 70, arcade.color.GRAY, 3) if player.get_pointer() - 1 != -1: arcade.draw_text( "{}: {}".format(player.buff_list[player.get_pointer() - 1].name, player.buff_list[player.get_pointer() - 1].effect), 20, 425, arcade.color.BLACK, 20) arcade.draw_text( "{}: {}".format(player.buff_list[player.get_pointer()].name, player.buff_list[player.get_pointer()].effect), 20, 320, arcade.color.BLACK, 20) if player.get_pointer() + 1 != len(player.buff_list): arcade.draw_text( "{}: {}".format(player.buff_list[player.get_pointer() + 1].name, player.buff_list[player.get_pointer() + 1].effect), 20, 213, arcade.color.BLACK, 20) arcade.draw_triangle_filled(475, 335, 495, 315, 495, 355, arcade.color.BLACK) arcade.draw_xywh_rectangle_outline(500, 210, 250, 250, arcade.color.BLACK, 10) arcade.draw_texture_rectangle( 625, 335, 240, 240, player.buff_list[player.get_pointer()].texture) arcade.draw_text( "Amount: {}".format(str( player.buff_list[player.get_pointer()].amount)), 465, 150, arcade.color.BLACK, 50) if player.search_menu: arcade.draw_xywh_rectangle_filled(100, 100, 568, 440, arcade.color.BLACK) arcade.draw_xywh_rectangle_filled(110, 110, 548, 420, arcade.color.WHITE) arcade.draw_text("Enter Pokemon Number:", 140, 450, arcade.color.BLACK, 35) arcade.draw_text(" " + player.search_number, 140, 200, arcade.color.BLACK, 220) if player.sort_menu: arcade.draw_xywh_rectangle_filled(100, 100, 568, 440, arcade.color.BLACK) arcade.draw_xywh_rectangle_filled(110, 110, 548, 420, arcade.color.WHITE) arcade.draw_text("Do you want to sort", 115, 380, arcade.color.BLACK, 50) arcade.draw_text("the bag?", 175, 310, arcade.color.BLACK, 50)
def test_on_hide_view_called(): window = Window() view1 = View(window) view2 = View(window) window.show_view(view1) hide_mock = Mock() view1.on_hide_view = hide_mock window.show_view(view2) hide_mock.assert_called_once() window.close()
def load_game_screen(window: arcade.Window, gameview: arcade.View): """ Function that loads the actual game screen after reading available data from the saved file """ # Checking if the data directory exists or not. If not, create one create_data_dir() # Trying to load from a save file loaded_data = load_game() if first_time(): level = 1 gameview.setup(level=level) print("Game running for the first time") else: level = loaded_data.get("level") gameview.setup(level=level, load_game=True, loaded_game_data=loaded_data) window.show_view(gameview)
def main(): TestBase.setUpLogging() SettingsCommon.determineSettingsLocation() window: Window = Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) startView: TestEventScheduler = TestEventScheduler() window.show_view(startView) startView.setup() arcadeRun()
def __init__(self): arcadeWindow: Window = Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) warpEffect: WarpEffect = WarpEffect(screenWidth=SCREEN_WIDTH, screenHeight=SCREEN_HEIGHT) arcadeWindow.set_exclusive_keyboard(exclusive=True) arcadeWindow.show_view(warpEffect) schedule(function_pointer=self.checkEffectComplete, interval=1.0) warpEffect.setup() self._warpEffect: WarpEffect = warpEffect
def test_on_show_view_called(): window = Window() view = View(window) show_mock = Mock() view.on_show_view = show_mock window.show_view(view) show_mock.assert_called_once() window.close()
def main(): """ Main method """ TestBase.setUpLogging() SettingsCommon.determineSettingsLocation() arcadeWindow: Window = Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) shootingView: TestShooting = TestShooting() arcadeWindow.set_exclusive_keyboard(exclusive=True) arcadeWindow.show_view(shootingView) shootingView.setup() arcadeRun()
def main(): TestBase.setUpLogging() SettingsCommon.determineSettingsLocation() arcadeWindow: Window = Window(title=SCREEN_TITLE, width=SCREEN_WIDTH, height=SCREEN_HEIGHT) arcadeWindow.background_color = color.BLACK arcadeWindow.clear() warpDialog: WarpDialog = WarpDialog(window=arcadeWindow, completeCallback=completeCallback) arcadeWindow.show_view(warpDialog) arcadeRun()
def on_draw(player: arcade.Window): arcade.start_render() arcade.draw_text("Potion", 20, 570, arcade.color.BLACK, 50) arcade.draw_text("Q - Sort", 30, 30, arcade.color.BLACK, 60) arcade.draw_xywh_rectangle_outline(10, 405, 450, 70, arcade.color.GRAY, 3) arcade.draw_xywh_rectangle_outline(5, 290, 460, 90, arcade.color.BLACK, 5) arcade.draw_xywh_rectangle_outline(10, 193, 450, 70, arcade.color.GRAY, 3) if player.get_pointer() - 1 != -1: arcade.draw_text( "{}: {}".format(player.heal_list[player.get_pointer() - 1].name, player.heal_list[player.get_pointer() - 1].effect), 20, 425, arcade.color.BLACK, 20) arcade.draw_text( "{}: {}".format(player.heal_list[player.get_pointer()].name, player.heal_list[player.get_pointer()].effect), 20, 320, arcade.color.BLACK, 30) if player.get_pointer() + 1 != len(player.heal_list): arcade.draw_text( "{}: {}".format(player.heal_list[player.get_pointer() + 1].name, player.heal_list[player.get_pointer() + 1].effect), 20, 213, arcade.color.BLACK, 20) arcade.draw_triangle_filled(475, 335, 495, 315, 495, 355, arcade.color.BLACK) arcade.draw_xywh_rectangle_outline(500, 210, 250, 250, arcade.color.BLACK, 10) arcade.draw_texture_rectangle( 625, 335, 240, 240, player.heal_list[player.get_pointer()].texture) arcade.draw_text( "Amount: {}".format(str( player.heal_list[player.get_pointer()].amount)), 465, 150, arcade.color.BLACK, 50) if player.sort_menu: arcade.draw_xywh_rectangle_filled(100, 100, 568, 440, arcade.color.BLACK) arcade.draw_xywh_rectangle_filled(110, 110, 548, 420, arcade.color.WHITE) arcade.draw_text("Do you want to sort", 115, 380, arcade.color.BLACK, 50) arcade.draw_text("by hp healed?", 175, 310, arcade.color.BLACK, 50)
def view_to_png(window: arcade.Window, view: arcade.View, path: Path): # window.clear() ctx = window.ctx offscreen = ctx.framebuffer( color_attachments=[ctx.texture(window.get_size(), components=4)]) offscreen.clear() offscreen.use() window.show_view(view) window.dispatch_event('on_draw') window.dispatch_events() ctx.finish() image = Image.frombuffer('RGBA', offscreen.size, offscreen.read(components=4)).convert('RGB') image = image.transpose(Image.FLIP_TOP_BOTTOM) image.save(str(path)) # arcade.get_image().convert('RGB').save(str(path)) ctx.screen.use()
def test_create_border(self): if conf.PRODUCTION: return Window(width=5, height=5) config = { 'depth': 15, 'color': '(255, 255, 255)', 'type': 'border', 'outer_spacing': 23 } large_board_height = 1273 large_board_width = 1273 scale = 0.60 border = Border.from_config(large_board_width, large_board_height, config) border.create_shape(scale) top = [(13.800000000000011, 741.0), (13.800000000000011, 750.0), (750.0, 750.0), (750.0, 741.0)] right = [(741.0, 13.800000000000011), (741.0, 750.0), (750.0, 750.0), (750.0, 13.800000000000011)] bottom = [(13.800000000000011, 13.799999999999997), (13.800000000000011, 22.799999999999997), (750.0, 22.799999999999997), (750.0, 13.799999999999997)] left = [(13.799999999999997, 13.800000000000011), (13.799999999999997, 750.0), (22.799999999999997, 750.0), (22.799999999999997, 13.800000000000011)] self.assertEqual(border.top_points, top) self.assertEqual(border.right_points, right) self.assertEqual(border.bottom_points, bottom) self.assertEqual(border.left_points, left) self.assertEqual(len(border.get_shapes()), 4)
shapes.append(shape) # Add border print(shape.center_x, shape.center_y) rect = create_rectangle_outline( shape.center_x, shape.center_y, len(tile.lines) * PIXEL, len(tile.lines) * PIXEL, RED, # border_width=1, ) shapes.append(rect) return shapes def on_draw(self): arcade.start_render() for shape in self.shapes: shape.draw() if __name__ == "__main__": lines = Path("test_input.txt").read_text().splitlines() tiles = solution.parse(lines) win = Window() win.show_view(TileView(tiles)) arcade.run()
def main(): window = Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) game = MainView() window.show_view(game) run()
def search_logic(player: arcade.Window, key): if key == arcade.key.W: if player.get_pointer() != 0: player.edit_pointer(player.get_pointer() - 1) elif key == arcade.key.S: if player.get_pointer() != len(player.buff_list) - 1: player.edit_pointer(player.get_pointer() + 1) if key == arcade.key.E or player.search_menu: player.search_menu = True player.sort_menu = False if key == arcade.key.KEY_0: if len(player.search_number) < 2: player.search_number += "0" elif key == arcade.key.KEY_1: if len(player.search_number) < 2: player.search_number += "1" elif key == arcade.key.KEY_2: if len(player.search_number) < 2: player.search_number += "2" elif key == arcade.key.KEY_3: if len(player.search_number) < 2: player.search_number += "3" elif key == arcade.key.KEY_4: if len(player.search_number) < 2: player.search_number += "4" elif key == arcade.key.KEY_5: if len(player.search_number) < 2: player.search_number += "5" elif key == arcade.key.KEY_6: if len(player.search_number) < 2: player.search_number += "6" elif key == arcade.key.KEY_7: if len(player.search_number) < 2: player.search_number += "7" elif key == arcade.key.KEY_8: if len(player.search_number) < 2: player.search_number += "8" elif key == arcade.key.KEY_9: if len(player.search_number) < 2: player.search_number += "9" elif key == arcade.key.BACKSPACE: player.search_number = player.search_number[:-1] if key == arcade.key.L and player.search_number != "": found = binary_search(int(player.search_number), player.buff_list) if found != -1: player.edit_pointer(found) player.search_menu = False player.search_number = "" elif key == arcade.key.K: player.search_menu = False player.search_number = "" if key == arcade.key.Q or player.sort_menu: player.sort_menu = True player.search_menu = False if key == arcade.key.L: player.buff_list = merge_sort(player.buff_list) player.sort_menu = False elif key == arcade.key.K: player.sort_menu = False if key == arcade.key.K: player.cur_screen = "bag"
def __init__(self, window: arcade.Window, coordinates: tuple): super().__init__(window, coordinates, ":resources:images/animated_characters/zombie/zombie_idle.png", CHARACTER_SCALING) window.player_sprite = self window.player_list.append(self)
def main(): window = Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) view = IntroductionView() window.show_view(view) run()