def test_get_movement_vector_down(self): print("********") x, y = Grid.get_movement_vector(0,1, 0, 2, 1) print(f"x = {x}") print(f"y = {y}") self.assertAlmostEqual(x, 0) self.assertAlmostEqual(y, 2)
def render_coordinates(self): text = Display.Font['debug'].render( f"{self.param['x_coordinate']},{self.param['y_coordinate']}", True, (0, 0, 255)) text_rect = text.get_rect() text_rect.center = Grid.get_pixel_coordinates( self.param['x_coordinate'], self.param['y_coordinate']) self.surface.blit(text, text_rect)
def __init__(self, surface, image, x_coordinate, y_coordinate): Character.__init__(self, surface, image, x_coordinate=x_coordinate, y_coordinate=y_coordinate) self.center_px = Grid.get_pixel_coordinates(x_coordinate, y_coordinate) self.perma_coord = (x_coordinate, y_coordinate) self.perma_px = Grid.get_pixel_coordinates(self.perma_coord[0], self.perma_coord[1]) self.rect.midbottom = (self.perma_px[0], self.perma_px[1]) self.last_vector = (0, 0) self.mouseTheta = 0 self.instance_name = 'player'
def mouse_listener(keys): if keys[0] == 1: if engine.player.param['ready']: # pygame.display.update() if Grid.get_pixel_distance( engine.mouse_motion_pos[0], engine.mouse_motion_pos[1], engine.player.perma_px[0], engine.player.perma_px[1] ) > GameParams.config['player']['minimun_mouse_distance']: engine.player.move_by_mouse(engine.mouse_motion_pos)
def move_by_mouse(self, mouse_pos): ''' desc ''' # mouse angle relative to player self.mouseTheta = MouseClick.get_angle_from_player( (self.perma_px[0], self.perma_px[1]), mouse_pos) # translate mouse angle to direction e.g. left, right, up, down self.direction = Grid.get_direction_from_point_and_angle( self.mouseTheta) # get every coordinate around self.coordinates_around = Grid.get_all_coordinates_around( [self.param['x_coordinate'], self.param['y_coordinate']]) self.last_vector = self.coordinates_around[self.direction] self.move(self.last_vector[0], self.last_vector[1]) logger.debug( f"[PLAYER_ACTION] get_movement_from_mouse: direction:{self.direction}" )
def update(self): '''player moves for proof of concept''' self.surface.blit(self.image, self.rect, (33, 71, 32, 36)) final_position = (self.param['x_final'], self.param['y_final']) vector = final_position if self.moving: vector = Grid.get_movement_vector(self.param['pixel_x'], self.param['pixel_y'], self.param['x_final'], self.param['y_final'], self.velocity) if vector == final_position: self.moving = False self.param['ready'] = True self.param['pixel_x'] = vector[0] self.param['pixel_y'] = vector[1]
def __init__( self, surface, image, x_coordinate=0, y_coordinate=0, w=64, h=64, ): super().__init__() self.surface = surface self.param = { 'x_coordinate': x_coordinate, 'y_coordinate': y_coordinate, 'old_coordinate': (0, 0), 'w': w, 'h': h, 'ready': True, 'x_final': 0, 'y_final': 0, 'pixel_x': 0, 'pixel_y': 0 } self.rect = pygame.Rect(x_coordinate, y_coordinate, w, h) try: self.image = pygame.image.load(image) except pygame.error as e: self.image = pygame.image.load( 'assets/sprites/tile/floor/placeholder_01.png') logger.warning(f"{e}") self.param['pixel_x'], self.param[ 'pixel_y'] = Grid.get_pixel_coordinates(self.param['x_coordinate'], self.param['y_coordinate']) (self.param['x_final'], self.param['y_final']) = (self.param['pixel_x'], self.param['pixel_y']) self.get_drawpoint()
def __init__(self): self.mouse_motion_pos = (0, 0) self.mouse_btnup_pos = (0, 0) self.mouse_btndwn_pos = (0, 0) self.interupt = Interupt.EXIT self.world_tile = WorldTile(Display.Group['tile'], Display.Group['tile_fg']) self.camera = Camera( GameParams.config['window']['resolution']['width'], GameParams.config['window']['resolution']['height']) self.clock = pygame.time.Clock() self.grid = Grid() self._init_fonts() self.windows = { 'console': TextBox(Display.Surface['main'], 0, 0, 140, 32) } self.windows_list = ['console']
def get_drawpoint(self): (self.param['pixel_x'], self.param['pixel_y']) = Grid.get_pixel_coordinates( self.param['x_coordinate'], self.param['y_coordinate'])
def __init__(self): xy = Grid.get_pixel_coordinates(6, 14) self.param = {'pixel_x': xy[0], 'pixel_y': xy[1]}
def test_get_movement_vector_left(self): x, y = Grid.get_movement_vector(4, 0, 6, 0, 1) self.assertAlmostEqual(x, 5) self.assertAlmostEqual(y, 0)