def update(self, dt): if self._sequence_name == 'walk_n': self._dx = 0 self._dy = self._speed elif self._sequence_name == 'walk_ne': self._dx = self._speed self._dy = self._speed elif self._sequence_name == 'walk_e': self._dx = self._speed self._dy = 0 elif self._sequence_name == 'walk_se': self._dx = self._speed self._dy = -self._speed elif self._sequence_name == 'walk_s': self._dx = 0 self._dy = -self._speed elif self._sequence_name == 'walk_sw': self._dx = -self._speed self._dy = -self._speed elif self._sequence_name == 'walk_w': self._dx = -self._speed self._dy = 0 elif self._sequence_name == 'walk_nw': self._dx = -self._speed self._dy = self._speed else: self._dx = 0 self._dy = 0 if game.will_collide(self, self._x+self._dx*dt, self._y+self._dy*dt): self._dx = 0 self._dy = 0 super(Mech, self).update(dt)
def on_mouse_press(self, x, y, button, modifiers): if self._build_action_instance: structure_factory = game.get_structure(self._build_action_instance.structure_id) if game.will_collide(self._build_action_instance): return # Resource requirements if len(structure_factory.tile_requirements): x, y = self.get_map_from_mouse_pos(x, y) for layer, requirement in structure_factory.tile_requirements.items(): prop, val = requirement.split(":") tile = game.get_tile_at(layer, x, y) if not tile or tile.properties.get(prop, None) != val: game.message_queue.create_message("This structure has to be place on %s " % val) return # Asset requirements try: structure_factory.pay() except AssetQuantityTooLittle as e: # Display labebl game.message_queue.create_message(str(e)) return self._build_action_instance.opacity = 255 game.structures.add(self._build_action_instance) game.collidable.add(self._build_action_instance) game.requires_upkeep.add(self._build_action_instance) if modifiers == pyglet.window.key.MOD_SHIFT: structure_id = self._build_action_instance.structure_id self._build_action_instance = None self.start_build_action(structure_id) else: self._build_action_instance = None return True else: return False