def set_screen_to_display_simulator_at_startup( self, use_second_screen_to_show_simulator): """ Set screen to use to display the simulator at startup. For windows this works only in fullscreen mode. By default set current screen to show simulator, but if use_second_screen_to_show_simulator==True then change screen to other screen. On MacOS this works for both fullscreen and none-fullscreen mode. On Windows this only works for fullscreen mode. For none-fullscreen always the first screen is used. """ # get current_screen_index screens = _arcade.get_screens() self.current_screen_index = 1 if use_second_screen_to_show_simulator and len( screens) > 1 else 0 # change screen to show simulator # HACK override default screen function to change it. # Note: arcade window class doesn't has the screen parameter which pyglet has, so by overriding # the get_default_screen method we can still change the screen parameter. def get_default_screen(): """Get the default screen as specified by the user's operating system preferences.""" return screens[self.current_screen_index] display = pyglet.canvas.get_display() display.get_default_screen = get_default_screen
def on_key_press(self, symbol: int, modifiers: int): """Called whenever a key is pressed. """ # Quit the simulator if symbol == _arcade.key.Q: self.on_close() # Toggle fullscreen between screens (only works at fullscreen mode) elif symbol == _arcade.key.T: # User hits T. When at fullscreen, then switch screen used for fullscreen. if len(_arcade.get_screens()) == 0: return if self.fullscreen: # to switch screen when in fullscreen we first have to back to normal window, and do fullscreen again self._set_full_screen(False) # Toggle between first and second screen (other screens are ignored) self.toggle_screen_used_for_fullscreen() self._set_full_screen(True) # Maximize window # note: is toggle on macOS, but not on windows elif symbol == _arcade.key.M: self.maximize() # Toggle between Fullscreen and window # keeps viewport coordinates the same STRETCHED (FULLSCREEN) # Instead of a one-to-one mapping to screen size, we use stretch/squash window to match the constants. # src: http://arcade.academy/examples/full_screen_example.html elif symbol == _arcade.key.F: self.update_current_screen() self._set_full_screen(not self.fullscreen)
def toggle_screen_used_for_fullscreen(self): """toggles between the first two screens found by arcade""" # toggle only between screen 0 and 1 (other screens are ignored) self.current_screen_index = (self.current_screen_index + 1) % 2 # override hidden screen parameter in window screens = _arcade.get_screens() self._screen = screens[self.current_screen_index]
def __init__(self, update_world_cb, world_state: WorldState, show_fullscreen: bool, show_maximized: bool, use_second_screen_to_show_simulator: bool): instance_checker = InstanceChecker(self) instance_checker.check_for_unique_instance() self.update_callback = update_world_cb self.world_state = world_state self.current_screen_index = None self.set_screen_to_display_simulator_at_startup( use_second_screen_to_show_simulator) self.size = Dimensions( get_simulation_settings()['screen_settings']['screen_width'], get_simulation_settings()['screen_settings']['screen_height']) self.msg_counter = 0 screen_title = get_simulation_settings( )['screen_settings']['screen_title'] screen_info = screen_title + f' version: {sim_version} ev3dev2 api: {api_version}' scale = self.determine_scale(self.size.width, self.size.height) if DEBUG: print('starting simulation with scaling', scale) print('arcade version: ', _arcade.version.VERSION) super(Visualiser, self).__init__( self.size.width, self.size.height, screen_info, update_rate=1 / 30, fullscreen=show_fullscreen, resizable=True, screen=_arcade.get_screens()[self.current_screen_index]) icon1 = pyglet.image.load(r'assets/images/body.png') self.set_icon(icon1) _arcade.set_background_color( get_simulation_settings()['screen_settings']['background_color']) self.sidebar = self._setup_sidebar() self.world_state.setup_pymunk_shapes(scale) self.world_state.setup_visuals(scale) if show_maximized: self.maximize() instance_checker.check_for_activation()
def update_current_screen(self): """ using the windows position and size we determine on which screen it is currently displayed and make that current screen for displaying in fullscreen!! """ screens = _arcade.get_screens() if len(screens) == 1: return top_left_x = self.get_location()[0] top_left_y = self.get_location()[1] size = self.get_size() win_width = size[0] win_height = size[1] done = False locations = [ self.get_location(), (top_left_x + win_width, top_left_y), (top_left_x, top_left_y + win_height), (top_left_x + win_width, top_left_y + win_height) ] for [loc_x, loc_y] in locations: if done: break num = 0 for screen in screens: within_screen_width = screen.x <= loc_x < (screen.x + screen.width) within_screen_height = screen.y <= (loc_y < (screen.y + screen.height)) if within_screen_width and within_screen_height: self.current_screen_index = num done = True break num += 1 # override hidden screen parameter in window self._screen = screens[self.current_screen_index]
import arcade from objects.player import Player SCREEN_POS_X = arcade.get_screens()[0].width // 2 SCREEN_POS_Y = arcade.get_screens()[0].height // 2 class MainWindow(arcade.Window): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.set_location(SCREEN_POS_X - (self.width // 2), SCREEN_POS_Y - (self.height // 2)) self.title = 'PyMMO' self.player: Player = Player() self.network = None def on_update(self, delta_time): ...
def __init__(self): global score """ Initializer """ # Call the parent class initializer super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, "Sprite Example") # Variables that will hold sprite lists self.player_list = None self.coin_list = None self.enemy_list = None self.player_bullet_list = None self.bomb_list = None self.bomb_attack_list = None self.explosion_list = None self.explosion_texture_list = [] self.score_list = None # Set up the player info self.player_sprite = None self.charge = 20 self.bomb_charge = 0 self.bomb_charge_max = 500 self.shrink_charging = False self.shrunk = False self.health = 20 self.alive = True self.healing = False self.difficulty_check = 0 self.lmb_down = False self.rmb_down = False self.last_shot = 'r' self.firing_big = False self.firing_small = False self.can_fire = True self.can_regen = True self.charge_cooling = False self.bomb = None self.bomb_white = None self.bombing = False self.bomb_color = [135, 206, 235, 255] self.how_many = 0 self.score_get = None # misc self.random_enemy = 0 self.bombs_to_spawn = 0 self.background = None self.multiplier = 1 self.multiplied = False # Don't show the mouse cursor self.set_mouse_visible(False) # Get monitor list and viewport for fullscreen self.monitors = arcade.get_screens() self.view_coords = arcade.get_viewport() arcade.set_background_color(arcade.color.AMAZON) # Load sounds # Pain sound from opengameart.com 'Fps Placeholder Sounds' self.hurt = arcade.load_sound("pain_jack_01.wav") # Impact sounds from kenny.nl self.coin_sounds = [ arcade.load_sound("impactGeneric_light_000.ogg"), arcade.load_sound("impactGeneric_light_001.ogg"), arcade.load_sound("impactGeneric_light_002.ogg"), arcade.load_sound("impactGeneric_light_003.ogg"), arcade.load_sound("impactGeneric_light_004.ogg"), arcade.load_sound("impactGlass_heavy_000.ogg"), arcade.load_sound("impactGlass_heavy_001.ogg"), arcade.load_sound("impactGlass_heavy_002.ogg"), arcade.load_sound("impactGlass_heavy_003.ogg"), arcade.load_sound("impactGlass_heavy_004.ogg") ] self.better_coin_sounds = [ arcade.load_sound("impactMining_000.ogg"), arcade.load_sound("impactMining_001.ogg"), arcade.load_sound("impactMining_002.ogg"), arcade.load_sound("impactMining_003.ogg"), arcade.load_sound("impactMining_004.ogg") ] self.bomb_empty_sound = arcade.load_sound("chipsStack1.wav") # flaunch.wav (c) by Michel Baradari apollo-music.de self.bomb_launch_sound = arcade.load_sound("flaunch.wav") self.enemy_damaged_sounds = [] self.enemy_destroyed_sounds = [] for x in range(5): self.enemy_damaged_sounds.append( arcade.load_sound("impactPunch_medium_00" + str(x) + ".ogg")) self.enemy_destroyed_sounds.append( arcade.load_sound("impactPlate_medium_00" + str(x) + ".ogg")) # bomb burst sounds from https://opengameart.org/content/100-plus-game-sound-effects-wavoggm4a self.bomb_burst_sounds = [ arcade.load_sound("Explosion.wav"), arcade.load_sound("Explosion2.wav"), arcade.load_sound("Explosion4.wav"), arcade.load_sound("Explosion5.wav"), arcade.load_sound("Explosion7.wav"), arcade.load_sound("Explosion9.wav"), arcade.load_sound("Explosion12.wav"), arcade.load_sound("Explosion20.wav") ] self.laser_shoot_sound = arcade.load_sound("Laser_Shoot7.wav") for x in range(3, 0, -1): self.explosion_texture_list.append( arcade.load_texture("pixelExplosion0" + str(x) + ".png")) for x in range(9): self.explosion_texture_list.append( arcade.load_texture("pixelExplosion0" + str(x) + ".png"))