def _init_sounds(self): # Background music BACKGROUND_MUSICS = [ ('Background0Start', 'Background0Repeat', GuiTools.time_to_cycle(40.867 - 0.001)), ] bg_music_start, bg_music_repeat, bg_music_start_duration = random.choice( BACKGROUND_MUSICS) background_music_ref = drm.new() self.scene.add_action( InstantiateBundleAsset( ref=background_music_ref, asset=Asset(bundle_name='main', asset_name='BackgroundMusic'), )) change_audio(self, background_music_ref, clip=bg_music_start) change_audio(self, background_music_ref, clip=bg_music_repeat, cycle=bg_music_start_duration) # Countdown countdown_ref = drm.new() self.scene.add_action( InstantiateBundleAsset( ref=countdown_ref, asset=Asset(bundle_name='main', asset_name='Countdown'), )) change_audio(self, countdown_ref, play=True) change_audio(self, countdown_ref, play=False, cycle=4) self.scene.add_action(EndCycle()) self.scene.add_action(EndCycle())
def _init_objects(self): sides = self.bases.keys() # Create the location base asset self.location.ref = drm.new() self.scene.add_action( InstantiateBundleAsset( ref=self.location.ref, asset=self.location.ASSET, )) # Init the sides' objects for side in sides: base = self.bases[side] # Support # Init cells for pos, cell_type in self.bases[side].c_area.items(): if cell_type == ECell.Empty: cell_type.gui_init(self, side, pos) elif cell_type == ECell.FrontlineDelivery: FrontlineDelivery.gui_init_cell(self, side, pos) elif cell_type == ECell.Material: base.warehouse.materials[pos].gui_init(self, side) elif cell_type == ECell.BacklineDelivery: base.backline_delivery.gui_init(self, side, pos) elif cell_type == ECell.Machine: base.factory.machines[pos].gui_init(self, side) # Init agents for agent in base.agents.values(): agent.gui_init(self, side) # Frontline # Init units for unit in base.units.values(): unit.gui_init(self, side) # Create the top status self._top_status_ref = drm.new() self.scene.add_action( InstantiateBundleAsset( ref=self._top_status_ref, asset=Asset(bundle_name='main', asset_name='TopStatus'), default_parent=EDefaultParent.RootCanvas, )) change_text(self, self._top_status_ref, 'Cycle/MaxCycle', str(self.max_cycles)) for side in sides: change_text(self, self._top_status_ref, '{}TeamName'.format(side), self._team_nicknames[side]) self._update_top_status(0)
def _draw_players(self): # Draw pacman pacman_angle = self._angle[self._world.pacman.direction] scene_pos = self._get_scene_position(self._world.pacman.position) self._pacman_ref = drm.new() self._scene.add_action( scene_actions.InstantiateBundleAsset(ref=self._pacman_ref, asset=scene_actions.Asset( bundle_name='main', asset_name='Pacman'))) self._scene.add_action( scene_actions.ChangeTransform( ref=self._pacman_ref, position=scene_actions.Vector3(x=scene_pos['x'], y=scene_pos['y'], z=0), rotation=scene_actions.Vector3(z=pacman_angle), change_local=False)) # Draw ghosts for ghost in self._world.ghosts: scene_pos = self._get_scene_position(ghost.position) self._ghosts_ref[ghost.id] = drm.new() color = self._ghosts_color[ghost.id % len(self._ghosts_color)] self._scene.add_action( scene_actions.InstantiateBundleAsset( ref=self._ghosts_ref[ghost.id], asset=scene_actions.Asset(bundle_name='main', asset_name='Ghost'))) self._scene.add_action( scene_actions.ChangeTransform(ref=self._ghosts_ref[ghost.id], position=scene_actions.Vector3( x=scene_pos['x'], y=scene_pos['y'], z=0), change_local=False)) # Change color self._scene.add_action( scene_actions.ChangeSprite(ref=self._ghosts_ref[ghost.id], child_ref='Body', color=color)) self._scene.add_action( scene_actions.ChangeSprite(ref=self._ghosts_ref[ghost.id], child_ref='Foots', color=color)) self._set_ghost_eyes(ghost.id, ghost.direction)
def gui_init(self, world, side, position): cell_ref = drm.new() panel_ref = drm.new() cell_offset = position.get_gui_offset() # Create cell world.scene.add_action( InstantiateBundleAsset( ref=cell_ref, parent_ref=world.location.ref, parent_child_ref='Support/{}/CellPivots'.format(side), asset=Asset(bundle_name='main', asset_name='{}Cell'.format(self.name)), )) world.scene.add_action( ChangeTransform( ref=cell_ref, position=Vector3(x=cell_offset, y=0, z=0), change_local=True, )) # Create panel panel_asset = '{}Panel'.format(self.name) if self == ECell.BacklineDelivery: panel_asset = '{}{}Panel'.format(side, self.name) world.scene.add_action( InstantiateBundleAsset( ref=panel_ref, parent_ref=world.location.ref, parent_child_ref='Support/{}/PanelPivots'.format(side), asset=Asset(bundle_name='main', asset_name=panel_asset), )) panel_extra_offset = self.get_gui_width() * 100 if side == LEFT_SIDE else 0 panel_scale = Vector3(x=-1) if side == LEFT_SIDE else None world.scene.add_action( ChangeTransform( ref=panel_ref, position=Vector3(x=cell_offset * 100 + panel_extra_offset, y=0, z=0), scale=panel_scale, change_local=True, )) change_text(world, panel_ref, 'CellIndex', 'Position: {}'.format(position.index)) return cell_ref, panel_ref
def gui_init(self, world, side): self._gui_shooting_refs = { } # key is ref, value is (remaining shoot animation cycles, delay only) self._gui_alive_refs = [] gui_alives = random.sample( range(world.location.MAX_UNITS[self.type]), min(self.num_alives(), world.location.MAX_UNITS[self.type]), ) for i in gui_alives: self._gui_alive_refs.append(drm.new()) world.scene.add_action( InstantiateBundleAsset( ref=self._gui_alive_refs[-1], parent_ref=world.location.ref, parent_child_ref='Frontline/{}/{}/{}'.format( side, self.type.name, i), asset=Asset(bundle_name='main', asset_name='{}{}'.format(side, self.type.name)), )) self._gui_update_health(world, side) self._gui_update_ammo(world, side) self._gui_update_reload_timer(world, side) self._gui_update_damage_done(world, side, 0) self._gui_update_damage_taken(world, side, 0)
def initialize(self, config): self._angle = { EDirection.Up: 90, EDirection.Right: 0, EDirection.Down: -90, EDirection.Left: 180, } self._ghost_eyes_index = { EDirection.Up: 5, EDirection.Right: 3, EDirection.Down: 1, EDirection.Left: 2, } self._ghosts_color = [ scene_actions.Vector4(x=213 / 255, y=0, z=0, w=1), scene_actions.Vector4(x=236 / 255, y=64 / 255, z=122 / 255, w=1), scene_actions.Vector4(x=100 / 255, y=181 / 255, z=246 / 255, w=1), scene_actions.Vector4(x=244 / 255, y=81 / 255, z=30 / 255, w=1), ] self._eat_delay = 0.75 self._ghost_eyes_ref = 'Eyes' self._background_music_ref = drm.new() self._wakawaka_music_ref = drm.new() self._eat_ghost_music_ref = drm.new() self._eating_food = False self._ghosts_ref = {} self._foods_ref = {} self._super_foods_ref = {} self._configure(config) self._init_camera() self._init_sounds() self._draw_board() self._draw_players() # Status self._game_status = game_status.GameStatus(self._world, self._scene, eat_delay=self._eat_delay) self._game_status.initialize() self._game_status.draw_statuses() self._scene.add_action(scene_actions.EndCycle())
def initialize(self): self._top_panel_ref = drm.new() self._health_panel_ref = 'HealthPanel' self._health_images_ref = [] self._cycle_text_ref = 'CycleText' self._super_text_ref = 'SuperText' self._pacman_score_ref = 'ScorePanel/PacmanScore' self._ghost_score_ref = 'ScorePanel/GhostScore'
def gui_init(self, world, side): self._last_gui_event = None self._gui_is_idle = True self._gui_ref = drm.new() cell_offset = self._get_gui_offset(world.bases[side].c_area) world.scene.add_action( InstantiateBundleAsset( ref=self._gui_ref, parent_ref=world.location.ref, parent_child_ref='Support/{}/AgentPivots'.format(side), asset=Asset(bundle_name='main', asset_name='Agent'), )) world.scene.add_action( ChangeTransform( ref=self._gui_ref, position=Vector3(x=cell_offset, y=0, z=0), change_local=True, )) if side == LEFT_SIDE: world.scene.add_action( ChangeTransform( ref=self._gui_ref, child_ref='Status', scale=Vector3(x=-0.01), change_local=True, )) # Status Panel self._gui_status = drm.new() world.scene.add_action( InstantiateBundleAsset( ref=self._gui_status, parent_ref=self._gui_ref, parent_child_ref='Status', asset=Asset(bundle_name='main', asset_name='{}AgentPanel'.format(side)), ))
def _init_light(self): main_light = drm.new() self.scene.add_action( CreateBasicObject( ref=main_light, type=EBasicObjectType.Light, )) self.scene.add_action( ChangeTransform( ref=main_light, rotation=Vector3(x=50, y=0, z=0), )) self.scene.add_action( ChangeLight( ref=main_light, intensity=1, shadow_type=ELightShadowType.Disabled, ))
def create_asset(world, asset_name, parent_ref=None, parent_child_ref=None, cycle=None, is_ui=False): ref = drm.new() world.scene.add_action( InstantiateBundleAsset( ref=ref, cycle=cycle, parent_ref=parent_ref, parent_child_ref=parent_child_ref, asset=Asset(bundle_name='main', asset_name=asset_name), default_parent=EDefaultParent.RootObject if not is_ui else EDefaultParent.RootCanvas, )) return ref
def create_main_light(world): main_light = drm.new() world.scene.add_action( CreateBasicObject( ref=main_light, type=EBasicObjectType.Light, )) world.scene.add_action( ChangeTransform( ref=main_light, rotation=Vector3(x=90, y=90, z=0), )) world.scene.add_action( ChangeLight( ref=main_light, intensity=1, indirect_multiplier=0, color=Vector4(x=1, y=1, z=1, w=1), shadow_type=ELightShadowType.Disabled, ))
def draw_statuses(self): self._scene.add_action( scene_actions.InstantiateBundleAsset( ref=self._top_panel_ref, asset=scene_actions.Asset(bundle_name='main', asset_name='TopPanel'), default_parent=scene_actions.EDefaultParent.RootCanvas)) # Cycle self._set_cycle_text(0) # Pacman health for _ in range(self._world.pacman.health): new_ref = drm.new() self._health_images_ref.append(new_ref) self._scene.add_action( scene_actions.InstantiateBundleAsset( ref=new_ref, asset=scene_actions.Asset(bundle_name='main', asset_name='PacmanImage'), parent_ref=self._top_panel_ref, parent_child_ref=self._health_panel_ref))
def _draw_board(self): for y in range(self._world.height): for x in range(self._world.width): cell = self._world.board[y][x] if cell == ECell.Empty: continue scene_pos = self._get_scene_position(Position(x, y)) z = 5 reference = drm.new() # if cell == ECell.Wall and (y == self._world.height - 1 or y == 0 or x == self._world.width - 1 or x == 0): # self._scene.add_action(scene_actions.InstantiateBundleAsset( # ref = reference, # asset = scene_actions.Asset(bundle_name='main', asset_name='Wall') # )) # self._scene.add_action(scene_actions.ChangeSprite( # ref = reference, # sprite_asset = scene_actions.Asset(bundle_name='main', asset_name='Walls', index=0) # )) if cell == ECell.Wall: wall_type, wall_angle = self._get_wall_type_angle(x, y) if wall_type == None: continue self._scene.add_action( scene_actions.InstantiateBundleAsset( ref=reference, asset=scene_actions.Asset(bundle_name='main', asset_name='Wall'))) self._scene.add_action( scene_actions.ChangeSprite( ref=reference, sprite_asset=scene_actions.Asset( bundle_name='main', asset_name='Walls', index=wall_type))) self._scene.add_action( scene_actions.ChangeTransform( ref=reference, rotation=scene_actions.Vector3(z=wall_angle))) elif cell == ECell.Food: self._foods_ref[x, y] = reference self._scene.add_action( scene_actions.InstantiateBundleAsset( ref=reference, asset=scene_actions.Asset(bundle_name='main', asset_name='Food'))) elif cell == ECell.SuperFood: self._super_foods_ref[x, y] = reference self._scene.add_action( scene_actions.InstantiateBundleAsset( ref=reference, asset=scene_actions.Asset(bundle_name='main', asset_name='SuperFood'))) # Set Position self._scene.add_action( scene_actions.ChangeTransform( ref=reference, position=scene_actions.Vector3(x=scene_pos['x'], y=scene_pos['y'], z=z)))
def __init__(self, world, side, delivery_duration, pivot, start_position, arrive_position, end_position, is_frontline_delivery, return_duration, ammos=None): self._gui_ref = drm.new() world.scene.add_action( InstantiateBundleAsset( ref=self._gui_ref, parent_ref=world.location.ref, parent_child_ref='Support/{}/{}'.format(side, pivot), asset=Asset(bundle_name='main', asset_name='{}Courier'.format(side)), )) world.scene.add_action( ChangeTransform( ref=self._gui_ref, position=start_position, change_local=True, )) world.scene.add_action( ChangeTransform( ref=self._gui_ref, duration_cycles=delivery_duration, position=arrive_position, change_local=True, )) world.scene.add_action( ChangeTransform( ref=self._gui_ref, cycle=delivery_duration + ARRIVE_DURATION_CYCLES, duration_cycles=return_duration, position=end_position, change_local=True, )) world.scene.add_action( Destroy( ref=self._gui_ref, cycle=delivery_duration + ARRIVE_DURATION_CYCLES + return_duration, )) change_animator_state(world, self._gui_ref, 'Arrive', cycle=delivery_duration) change_animator_state(world, self._gui_ref, 'Run', cycle=delivery_duration + ARRIVE_DURATION_CYCLES) if is_frontline_delivery: for ammo_type, ammo_count in ammos.items(): change_text(world, self._gui_ref, 'Canvas/Ammos/{}/Count'.format(ammo_type.name), str(ammo_count)) else: world.scene.add_action( ChangeIsActive( ref=self._gui_ref, child_ref='Canvas/Ammos', is_active=False, )) world.scene.add_action( ChangeRectTransform( ref=self._gui_ref, child_ref='Canvas', size=Vector2(y=40), )) self.gui_update_rem_cycles(world, delivery_duration) self.gui_update_rem_cycles(world, '-', delivery_duration)