def adhoc_dot_sprite(tile_size_pixels: utils.Vec2i, boldness: int, transparency: int) -> pygame.Surface: dot_sprite: pygame.Surface = pygame.Surface(tile_size_pixels.to_tuple(), flags=pygame.SRCALPHA) dot_sprite.fill(color=(0, 0, 0, 0)) tile_center_xy = tile_size_pixels // 2 for i in range(-boldness, boldness): for j in range(-boldness, boldness): t = tile_center_xy + utils.Vec2i(1, 0) * i + utils.Vec2i(0, 1) * j dot_sprite.set_at(t.to_tuple(), (255, 255, 255, transparency)) return dot_sprite
class AIRandMoveIC(IntentionChannel): __moves = [ actor_intention.ActorWaitIntention(), # Stand actor_intention.ActorMoveIntention(utils.Vec2i(1, 0)), # Move right actor_intention.ActorMoveIntention(utils.Vec2i(-1, 0)), # Move left actor_intention.ActorMoveIntention(utils.Vec2i(0, 1)), # Move top actor_intention.ActorMoveIntention(utils.Vec2i(0, -1)), # Move bot ] def request_command(self) -> Union[None, actor_intention.ActorIntention]: move_num = random.randint(0, 4) return self.__moves[move_num]
def update(self, *, visual_owner: Visualisation) -> Union[None, IVisualState]: current_time = global_parameters.current_frame_time_ms / 1000 elapsed = current_time - self.enter_time r = elapsed / self.time_to_move new_pose = utils.Vec2i(0, abs( self.amplitude * sin(pi * r)**2)) + self.original_xy visual_owner.set_corner_xy(new_pose) return None
def update(self, *, visual_owner: Visualisation) -> Union[None, IVisualState]: current_time = global_parameters.current_frame_time_ms / 1000 elapsed_time = current_time - self.time_begin if elapsed_time > self.time_to_move: self.ready_flag = True return Standing(self.initial_offset_xy + self.dxy) r = min(1.0, elapsed_time / self.time_to_move) new_pose = utils.Vec2i(0, abs(self.amplitude * sin( pi * r)**2)) + self.initial_offset_xy + (self.dxy * r) visual_owner.set_corner_xy(new_pose) return None
def __init__(self, model: ModelGame, screen_size: Tuple[int, int], layers_num: int, tile_size_pixels: Tuple[int, int], timings: Timings): Observer.__init__(self) Subject.__init__(self) self._model = model self._timings = timings self._display = Display(screen_size, layers_num) self._tile_size_pixels = utils.Vec2i(*tile_size_pixels) self._visualisations: VisualisationsContainer = VisualisationsContainer( self._tile_size_pixels) self._visualisations.synchronize_with_model(model) self._gobj_event_handler = ModelEventHandler(timings, self._tile_size_pixels, self._visualisations) # User interactions with GUI # TODO: Class for user input! self._user_keyboard = UserKeyboardProcessor(delay=0.3) self._keys_to_commands = KEYS_TO_COMMANDS
from gamelogic.view.settings.user_moves import PlayerCommand from gamelogic.model import actor_intention from common.utils import utils USER_MOVES_TO_COMMAND = { PlayerCommand.MOVE_UP: actor_intention.ActorMoveIntention(utils.Vec2i(0, 1)), PlayerCommand.MOVE_DOWN: actor_intention.ActorMoveIntention(utils.Vec2i(0, -1)), PlayerCommand.MOVE_LEFT: actor_intention.ActorMoveIntention(utils.Vec2i(-1, 0)), PlayerCommand.MOVE_RIGHT: actor_intention.ActorMoveIntention(utils.Vec2i(1, 0)), PlayerCommand.MOVE_WAIT: actor_intention.ActorWaitIntention() }
def __init__(self, tile_size_pixels: utils.Vec2i): self._visuals: Dict[GameObject, Visualisation] = dict() self._player_character: Union[None, Character] = None self._tile_size_pixels = tile_size_pixels self._camera = camera.Camera(utils.Vec2i(0, 0), camera_states.CameraBaseState())
def __noise_func(self, r) -> utils.Vec2i: radius = 2 * self.amplitude * r * (1 - r) x = radius * math.sin(math.pi * 2 * r) y = radius * math.cos(math.pi * 2 * r) return utils.Vec2i(x, y)
def cell_ij_to_pixel(self, ij: utils.Vec2i) -> utils.Vec2i: x = ij[0] * self._tile_size_pixels[0] y = ij[1] * self._tile_size_pixels[1] return utils.Vec2i(x, y)
def __init__(self): GameObject.__init__(self, pos=utils.Vec2i(0, 0), name='bare body', sprite=None)
def __init__(self): GameObject.__init__(self, pos=utils.Vec2i(0, 0), name='one hand axe', sprite=None)
result = False return result def put_on_lefthand(self, item: items.IEquipment) -> bool: result = True try: self.character_items.left_hand.put_item(item) except body_cells.WrongItemType as e: result = False return result def put_on_righthand(self, item: items.IEquipment) -> bool: result = True try: self.character_items.right_hand.put_item(item) except body_cells.WrongItemType as e: result = False return result if __name__ == '__main__': ch_attrs = CharacterAttributes(12, 12, 15, 16, 14) character = Character(pos=utils.Vec2i(0, 0), name='Wizard', sprite=pygame.Surface((32, 32)), attributes=ch_attrs, inventory_capacity=10) b = BareArmor() character.inventory.get_cell(pos=11) pass
def __init__(self, screen_size: Tuple[int, int], layers_num: int): self._screen_size = utils.Vec2i(*screen_size) self._monitor_center: utils.Vec2i = self._screen_size // 2 self._display: pygame.Surface = pygame.display.set_mode(screen_size) self._layers: Layers = Layers(layers_num)