def update(self): super().update() if self.state == state.ON_MOVE: if abs(self.from_x - self.center_x) >= GRID_SIZE or abs( self.from_y - self.center_y) >= GRID_SIZE: self.change_x = 0 self.change_y = 0 self.x += self.dx self.y += self.dy # self.fighter.wait += self.fighter.speed self.dx, self.dy = 0, 0 self.from_x, self.from_y = self.center_x, self.center_y self.state = state.TURN_END self.form = form.NORMAL if self.state == state.TURN_END: self.change_x = 0 self.change_y = 0 self.center_x, self.center_y = grid_to_pixel(self.x, self.y) elif self.state == state.READY: self.change_x = 0 self.change_y = 0 self.center_x, self.center_y = grid_to_pixel(self.x, self.y)
def apply_damage(skill, engine, x, y, results): position = grid_to_pixel(x, y) # print(f"{pixel_x}{pixel_y} apply pixel_x_y") sprites = arcade.get_sprites_at_point( position, engine.cur_level.actor_sprites) for sprite in sprites: if sprite.fighter and not sprite.is_dead: result = sprite.fighter.skill_process(skill) if result: results.extend(result)
def draw_select_mouse_location(self): """ マウス操作時のグリッド表示""" mouse_x, mouse_y = self.mouse_position grid_x, grid_y = pixel_to_grid(mouse_x, mouse_y) center_x, center_y = grid_to_pixel(grid_x, grid_y) arcade.draw_rectangle_outline(center_x=center_x, center_y=center_y, width=SPRITE_SIZE * SPRITE_SCALE, height=SPRITE_SIZE * SPRITE_SCALE, color=arcade.color.RAJAH, border_width=2)
def items_set(self): """itemをgame_mapタイル番号から設定する """ item_sprites = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=32) for x in range(self.width): for y in range(self.height): if type(self.item_tiles[x][y]) is int: item = get_random_items_by_challenge(self.item_tiles[x][y]) item.x = x item.y = y cx, cy = grid_to_pixel(x, y) item.center_x = cx item.center_y = cy item_sprites.append(item) return item_sprites
def actor_set(self): """actorをgame_mapタイル番号から設定する """ actor_sprites = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=32) for x in range(self.width): for y in range(self.height): if type(self.actor_tiles[x][y]) == int: monster = get_random_monster_by_challenge( self.actor_tiles[x][y]) # monster = make_monster_sprite(monster_tile_number) monster.x = x monster.y = y cx, cy = grid_to_pixel(x, y) monster.center_x = cx monster.center_y = cy actor_sprites.append(monster) # ここをコメントアウトすると敵無しに return actor_sprites
def update(self): self.d_time -= 2 if 40 > self.d_time: self.d_time = 170 ############# try: if self.engine.skill_shape: for line in Bresenham( (self.engine.player.x, self.engine.player.y), (self.dx, self.dy)): line = grid_to_pixel(*line) arcade.draw_rectangle_filled(line[0], line[1], GRID_SIZE, GRID_SIZE, [ 255, 251, 160, 100, ]) except: pass
def items_point_set(self): items_point_sprites = arcade.SpriteList(use_spatial_hash=False, spatial_hash_cell_size=32) for x in range(self.width): for y in range(self.height): if type(self.item_tiles[x][y]) is int: item = Actor(image=IMAGE_ID["items_point"], scale=1.2, x=x, y=y, color=COLORS["black"], visible_color=COLORS["light_ground"], not_visible_color=COLORS["light_ground"]) item.x = x item.y = y cx, cy = grid_to_pixel(x, y) item.center_x = cx item.center_y = cy items_point_sprites.append(item) return items_point_sprites
def grid_cursor(self): self.sprites = [ self.engine.cur_level.actor_sprites, self.engine.cur_level.item_sprites ] self.dx += self.grid_select[0] self.dy += self.grid_select[1] self.x, self.y = grid_to_pixel(self.dx, self.dy) if self.x < self.viewport_left: print(f"{self.x=} {self.viewport_left=}") # グリッド囲い線の描写 arcade.draw_rectangle_outline(center_x=self.x, center_y=self.y, width=SPRITE_SIZE * SPRITE_SCALE, height=SPRITE_SIZE * SPRITE_SCALE, color=arcade.color.LIGHT_BLUE, border_width=3) # 点滅するグリッド内部 arcade.draw_rectangle_filled(center_x=self.x, center_y=self.y, width=SPRITE_SIZE * SPRITE_SCALE - 2, height=SPRITE_SIZE * SPRITE_SCALE - 2, color=[255, 255, 255, self.d_time]) if self.engine.skill_shape: for x, y in self.engine.skill_shape: arcade.draw_rectangle_filled( center_x=self.x + (x * 64), center_y=self.y + (y * 64), width=SPRITE_SIZE * SPRITE_SCALE, height=SPRITE_SIZE * SPRITE_SCALE, color=[200, 115, 155, self.d_time]) try: # グリッド囲い線の中にあるオブジェクトの情報の表示 actor_at_point = arcade.get_sprites_at_exact_point( (self.x, self.y), self.sprites[0]) item_at_point = arcade.get_sprites_at_exact_point((self.x, self.y), self.sprites[1]) if actor_at_point or item_at_point: y = 20 for actor in chain(actor_at_point, item_at_point): if actor.ai: arcade.draw_text( text= f"{actor.name.capitalize()}\n{actor.fighter.hp}/{actor.fighter.max_hp}", start_x=self.viewport_left + SCREEN_WIDTH - STATES_PANEL_WIDTH + 10, start_y=self.viewport_bottom + SCREEN_HEIGHT - 400 - y, color=arcade.color.RED_PURPLE, font_size=20, ) y += 20 y += 10 if not actor.ai: arcade.draw_text( text=f"{actor.__class__.__name__}", start_x=self.viewport_left + SCREEN_WIDTH - STATES_PANEL_WIDTH + 10, start_y=self.viewport_bottom + SCREEN_HEIGHT - 400 - y, color=arcade.color.GREEN_YELLOW, font_size=20, ) y += 30 if actor.explanatory_text: arcade.draw_text( text=f"{actor.explanatory_text}", start_x=self.viewport_left + SCREEN_WIDTH - STATES_PANEL_WIDTH + 10, start_y=self.viewport_bottom + SCREEN_HEIGHT - 400 - y, color=arcade.color.WHITE, font_size=14, ) y += 20 except: pass
def on_draw(self): """全画像の表示""" arcade.start_render() # minimap start ------------------------------------------------------------------------------------------------------------ """minimap draw""" if self.engine.game_state == GAME_STATE.NORMAL: self.offscreen.use() # self.offscreen.clear(arcade.color.BLACK) arcade.set_viewport(0, GAME_GROUND_WIDTH, 0, GAME_GROUND_HEIGHT+GRID_SIZE*2) self.engine.cur_level.map_point_sprites.draw() arcade.draw_rectangle_filled(center_x=self.engine.player.center_x, center_y=self.engine.player.center_y, width=45, height=45, color=arcade.color.BLUE) self.engine.cur_level.item_point_sprites.draw() self.use() self.color_attachment.use(0) self.quad_fs.render(self.program) # minimap end ------------------------------------------------------------------------------------------------------------- # アタック時はビューポート固定する if self.engine.game_state == GAME_STATE.NORMAL: if self.engine.player.state == state.ON_MOVE: viewport(self.engine.player.center_x, self.engine.player.center_y) # viewport(self.engine.player.from_x, self.engine.player.from_y) else: x, y = (grid_to_pixel(self.engine.player.x, self.engine.player.y)) viewport(x,y) # ビューポート情報取得(この位置で取得しないとバグる) self.viewports = arcade.get_viewport() # arcadeの光源効果 with self.engine.light_layer: self.draw_sprites() self.engine.light_layer.draw(ambient_color=(1,1,1)) # ノーマルステート時の画面表示 if self.engine.game_state == GAME_STATE.NORMAL or self.engine.game_state == GAME_STATE.DELAY_WINDOW: self.normal_UI.draw_in_normal_state(self.viewports) # damage表示 for i in self.engine.damage_pop: if i.dist > 40: self.engine.damage_pop.remove(i) elif i.dist < 30: i.draw() # Character_Screen表示 elif self.engine.game_state == GAME_STATE.CHARACTER_SCREEN: self.character_UI.draw_character_screen(arcade.get_viewport(), self.engine.selected_item) # inventory表示 elif self.engine.game_state == GAME_STATE.INVENTORY: draw_inventory(self.engine, self.engine.selected_item, self.viewports) # level_up画面表示 elif self.engine.game_state == GAME_STATE.LEVEL_UP_WINDOW: self.level_up_window.window_pop(self.viewports, self.engine) elif self.engine.game_state == GAME_STATE.LEVEL_UP_FLOWER: self.level_up_flower.window_pop(self.viewports) # LOOKシステム elif self.engine.game_state == GAME_STATE.SELECT_LOCATION or self.engine.game_state == GAME_STATE.LOOK: # lookカーソルにviewportを渡す x, y = grid_to_pixel(self.select_UI.grid_select[0]+self.engine.player.x, self.select_UI.grid_select[1]+self.engine.player.y) viewport(x, y) # Lookメイン関数 self.select_UI.draw_in_select_ui(self.viewports, self.engine) # draw the mini_map(この位置に置かないとバグる) if self.engine.game_state == GAME_STATE.NORMAL: self.color_attachment.use(0) self.mini_map_quad.render(self.program)
def recalculate_fov(engine, radius): """ Fovの計算を行う """ player = engine.player char_x, char_y = player.position_xy sprite_lists = [ engine.cur_level.wall_sprites, engine.cur_level.floor_sprites, engine.cur_level.actor_sprites, engine.cur_level.item_sprites, engine.cur_level.map_obj_sprites, engine.cur_level.map_point_sprites, engine.cur_level.item_point_sprites ] # 最初に渡された全てのスプライトリストをループし、is_visible等をFalseにして画面から隠す for sprite_list in sprite_lists: for sprite in sprite_list: if sprite.is_visible: sprite.is_visible = False sprite.color = sprite.not_visible_color if Tag.npc in sprite.tag: sprite.alpha = 0 resolution = 12 circumference = 2 * math.pi * radius radians_per_point = 2 * math.pi / (circumference * resolution) point_count = int(round(circumference)) * resolution for i in range(point_count): radians = i * radians_per_point x = math.sin(radians) * radius + char_x y = math.cos(radians) * radius + char_y ray_checks = radius for j in range(ray_checks): v1 = char_x, char_y v2 = x, y x2, y2 = arcade.lerp_vec(v1, v2, j / ray_checks) x2 = round(x2) y2 = round(y2) pixel_point = grid_to_pixel(x2, y2) blocks = False for sprite_list in sprite_lists: sprites_at_point = arcade.get_sprites_at_exact_point( pixel_point, sprite_list) # 探索済みならis_visibleをTrueにする for sprite in sprites_at_point: sprite.is_visible = True if sprite.block_sight: blocks = True if hasattr(sprite.ai, "visible_check"): if sprite.ai.visible_check == False: engine.damage_pop.append( DamagePop("!", (250, 240, 0), sprite, 15, size=30)) engine.move_switch = False sprite.ai.visible_check = True if blocks: break # 全てのスプライトを再度ループし、is_visibleがTrueなら画面に表示する for sprite_list in sprite_lists: for sprite in sprite_list: if sprite.is_visible: sprite.color = sprite.visible_color sprite.alpha = 255
def position_xy(self, value): self._x, self._y = value self.center_x, self.center_y = grid_to_pixel(self._x, self._y)
def y(self, value): self._y = value self.center_x, self.center_y = grid_to_pixel(self._x, self._y)