예제 #1
0
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
예제 #2
0
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]
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
    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
예제 #6
0
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()
}
예제 #7
0
 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())
예제 #8
0
 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)
예제 #9
0
 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)
예제 #10
0
 def __init__(self):
     GameObject.__init__(self,
                         pos=utils.Vec2i(0, 0),
                         name='bare body',
                         sprite=None)
예제 #11
0
 def __init__(self):
     GameObject.__init__(self,
                         pos=utils.Vec2i(0, 0),
                         name='one hand axe',
                         sprite=None)
예제 #12
0
            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
예제 #13
0
 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)