|
@@ -123,7 +123,15 @@ def get_player_mask(mask_surface, bgl):
|
|
|
for p in current_level.obstacle_instances.values():
|
|
for p in current_level.obstacle_instances.values():
|
|
|
if p.light:
|
|
if p.light:
|
|
|
curr.append((p.x_pos, p.y_pos, p.light))
|
|
curr.append((p.x_pos, p.y_pos, p.light))
|
|
|
- curr_key = tuple(curr)
|
|
|
|
|
|
|
+ curr_key = (
|
|
|
|
|
+ id(current_level),
|
|
|
|
|
+ current_level.scroll_x_pos,
|
|
|
|
|
+ current_level.scroll_y_pos,
|
|
|
|
|
+ mask_surface.get_width(),
|
|
|
|
|
+ mask_surface.get_height(),
|
|
|
|
|
+ bgl,
|
|
|
|
|
+ tuple(curr),
|
|
|
|
|
+ )
|
|
|
if curr_key == _last_light_states:
|
|
if curr_key == _last_light_states:
|
|
|
return mask_surface
|
|
return mask_surface
|
|
|
_last_light_states = curr_key
|
|
_last_light_states = curr_key
|
|
@@ -249,6 +257,15 @@ class Level:
|
|
|
self.transport_map_total = transport_map_total
|
|
self.transport_map_total = transport_map_total
|
|
|
self.transport_map_remain = transport_map_remain
|
|
self.transport_map_remain = transport_map_remain
|
|
|
self.transport_obstacle = []
|
|
self.transport_obstacle = []
|
|
|
|
|
+ self.water_reflect_obstacles = []
|
|
|
|
|
+ self._water_reflection_base_cache = {}
|
|
|
|
|
+ self._water_reflection_distort_cache = {}
|
|
|
|
|
+ self._water_reflection_image_cache = {}
|
|
|
|
|
+ self._water_reflection_draw_cache = {}
|
|
|
|
|
+ self._water_submerged_entity_cache = {}
|
|
|
|
|
+ self._sun_reflection_cache = {}
|
|
|
|
|
+ self._water_reflection_wave_frame = -1
|
|
|
|
|
+ self._water_reflection_cache_limit = 512
|
|
|
self.transport_resource_init_points = []
|
|
self.transport_resource_init_points = []
|
|
|
self.earth_quake_direction = None
|
|
self.earth_quake_direction = None
|
|
|
self.earth_quake_init_tick = 0 # 地震初始化tick
|
|
self.earth_quake_init_tick = 0 # 地震初始化tick
|
|
@@ -348,6 +365,7 @@ class Level:
|
|
|
|
|
|
|
|
self.haunt_Mode = False
|
|
self.haunt_Mode = False
|
|
|
self.bg_light = 0
|
|
self.bg_light = 0
|
|
|
|
|
+ self.sunny = False
|
|
|
self.underwater = False
|
|
self.underwater = False
|
|
|
self.rgb_light = [0, 0, 0]
|
|
self.rgb_light = [0, 0, 0]
|
|
|
self.special_rgb = False
|
|
self.special_rgb = False
|
|
@@ -367,6 +385,10 @@ class Level:
|
|
|
EnvironmentEffect(self.effects_screen, en)
|
|
EnvironmentEffect(self.effects_screen, en)
|
|
|
self.haunt_Mode = self.map_json["basic"].get("haunted", False)
|
|
self.haunt_Mode = self.map_json["basic"].get("haunted", False)
|
|
|
self.bg_light = self.map_json["basic"].get("bg_light", 0)
|
|
self.bg_light = self.map_json["basic"].get("bg_light", 0)
|
|
|
|
|
+ global _last_light_states
|
|
|
|
|
+ _last_light_states = None
|
|
|
|
|
+ self.mask_surface.fill((self.bg_light, self.bg_light, self.bg_light, 0))
|
|
|
|
|
+ self.sunny = bool(self.map_json["basic"].get("sunny", False))
|
|
|
self.underwater = self.map_json["basic"].get("underwater", False)
|
|
self.underwater = self.map_json["basic"].get("underwater", False)
|
|
|
G.UNDERWATER = self.underwater
|
|
G.UNDERWATER = self.underwater
|
|
|
G.WATER_DAMPING = self.map_json["basic"].get("water_damping", 200)
|
|
G.WATER_DAMPING = self.map_json["basic"].get("water_damping", 200)
|
|
@@ -586,6 +608,288 @@ class Level:
|
|
|
self.blood_bar.set_name(self.your_name)
|
|
self.blood_bar.set_name(self.your_name)
|
|
|
self.ui_instances_top.append(self.blood_bar)
|
|
self.ui_instances_top.append(self.blood_bar)
|
|
|
|
|
|
|
|
|
|
+ def draw_water_reflections(self, surface):
|
|
|
|
|
+ if not self.water_reflect_obstacles:
|
|
|
|
|
+ return
|
|
|
|
|
+ view_rect = pygame.Rect(self.scroll_x_pos, self.scroll_y_pos, G.MAIN_AREA_X_POS, G.MAIN_AREA_Y_POS)
|
|
|
|
|
+ for water in list(self.water_reflect_obstacles):
|
|
|
|
|
+ self.draw_water_reflection_for_obstacle(surface, water, view_rect)
|
|
|
|
|
+
|
|
|
|
|
+ def draw_water_reflection_for_obstacle(self, surface, water, view_rect=None):
|
|
|
|
|
+ if view_rect is None:
|
|
|
|
|
+ view_rect = pygame.Rect(self.scroll_x_pos, self.scroll_y_pos, G.MAIN_AREA_X_POS, G.MAIN_AREA_Y_POS)
|
|
|
|
|
+ if getattr(water, "state", None) == oi.ObstacleState.DEAD:
|
|
|
|
|
+ return
|
|
|
|
|
+ wave_frame = self.get_water_wave_frame()
|
|
|
|
|
+ for tile_rect, reflection in self.get_water_reflection_entries(water, wave_frame):
|
|
|
|
|
+ if tile_rect.colliderect(view_rect):
|
|
|
|
|
+ surface.blit(reflection, tile_rect.topleft)
|
|
|
|
|
+ self.draw_sun_reflections_for_obstacle(surface, water, view_rect, wave_frame)
|
|
|
|
|
+
|
|
|
|
|
+ def get_water_wave_frame(self):
|
|
|
|
|
+ wave_frame = self.current_time // 160
|
|
|
|
|
+ if wave_frame != self._water_reflection_wave_frame:
|
|
|
|
|
+ self._water_reflection_wave_frame = wave_frame
|
|
|
|
|
+ self._water_reflection_distort_cache.clear()
|
|
|
|
|
+ self._water_reflection_draw_cache.clear()
|
|
|
|
|
+ return wave_frame
|
|
|
|
|
+
|
|
|
|
|
+ def get_water_reflection_entries(self, water, wave_frame):
|
|
|
|
|
+ cache_key = (id(water), water.x, water.y, wave_frame)
|
|
|
|
|
+ cached = self._water_reflection_draw_cache.get(cache_key)
|
|
|
|
|
+ if cached is not None:
|
|
|
|
|
+ return cached
|
|
|
|
|
+ entries = []
|
|
|
|
|
+ width = water.obstacle.get("WIDTH", 1)
|
|
|
|
|
+ height = water.obstacle.get("HEIGHT", 1)
|
|
|
|
|
+ for dx in range(width):
|
|
|
|
|
+ for dy in range(height):
|
|
|
|
|
+ cell_x = water.x + dx
|
|
|
|
|
+ cell_y = water.y + dy
|
|
|
|
|
+ tile_rect = pygame.Rect(
|
|
|
|
|
+ cell_x * G.GAME_SQUARE,
|
|
|
|
|
+ cell_y * G.GAME_SQUARE,
|
|
|
|
|
+ G.GAME_SQUARE,
|
|
|
|
|
+ G.GAME_SQUARE
|
|
|
|
|
+ )
|
|
|
|
|
+ reflection = self.build_water_reflection(cell_x, cell_y, tile_rect, wave_frame)
|
|
|
|
|
+ if reflection is not None:
|
|
|
|
|
+ entries.append((tile_rect, reflection))
|
|
|
|
|
+ if len(self._water_reflection_draw_cache) > self._water_reflection_cache_limit:
|
|
|
|
|
+ self._water_reflection_draw_cache.clear()
|
|
|
|
|
+ self._water_reflection_draw_cache[cache_key] = entries
|
|
|
|
|
+ return entries
|
|
|
|
|
+
|
|
|
|
|
+ def build_water_reflection(self, cell_x, cell_y, tile_rect, wave_frame):
|
|
|
|
|
+ if cell_y <= 0:
|
|
|
|
|
+ return None
|
|
|
|
|
+ seen = set()
|
|
|
|
|
+ candidates = []
|
|
|
|
|
+ signature = []
|
|
|
|
|
+ for x in range(max(0, cell_x - 4), min(self.map_x, cell_x + 5)):
|
|
|
|
|
+ for source_y in (cell_y - 1, cell_y - 2):
|
|
|
|
|
+ if source_y < 0:
|
|
|
|
|
+ continue
|
|
|
|
|
+ obstacle_ref = self.obstacle_instances.get((x, source_y))
|
|
|
|
|
+ if obstacle_ref is None or getattr(obstacle_ref, "water_reflect", False):
|
|
|
|
|
+ continue
|
|
|
|
|
+ oid = id(obstacle_ref)
|
|
|
|
|
+ if oid in seen:
|
|
|
|
|
+ continue
|
|
|
|
|
+ image = getattr(obstacle_ref, "image", None)
|
|
|
|
|
+ rect = getattr(obstacle_ref, "rect", None)
|
|
|
|
|
+ if image is None or rect is None or image.get_width() <= 1 or image.get_height() <= 1:
|
|
|
|
|
+ continue
|
|
|
|
|
+ water_origin_y = obstacle_ref.y + obstacle_ref.obstacle.get("HEIGHT", 1)
|
|
|
|
|
+ segment_idx = cell_y - water_origin_y
|
|
|
|
|
+ if segment_idx < 0 or segment_idx > 1:
|
|
|
|
|
+ continue
|
|
|
|
|
+ if segment_idx == 1 and not self.is_water_reflect_cell(cell_x, cell_y - 1):
|
|
|
|
|
+ continue
|
|
|
|
|
+ reflected_image = self.get_water_reflection_image(image)
|
|
|
|
|
+ segment_y = 0 if segment_idx == 0 else G.GAME_SQUARE
|
|
|
|
|
+ if segment_y >= reflected_image.get_height():
|
|
|
|
|
+ continue
|
|
|
|
|
+ image_rect = pygame.Rect(rect.x, rect.y, reflected_image.get_width(), reflected_image.get_height())
|
|
|
|
|
+ overlap_left = max(image_rect.left, tile_rect.left)
|
|
|
|
|
+ overlap_right = min(image_rect.right, tile_rect.right)
|
|
|
|
|
+ if overlap_left >= overlap_right:
|
|
|
|
|
+ continue
|
|
|
|
|
+ seen.add(oid)
|
|
|
|
|
+ candidates.append((obstacle_ref, reflected_image, image_rect, overlap_left, overlap_right, segment_y, segment_idx))
|
|
|
|
|
+ signature.append((oid, id(image), image_rect.x, image_rect.width, image_rect.height, segment_idx))
|
|
|
|
|
+ if not candidates:
|
|
|
|
|
+ return None
|
|
|
|
|
+ signature = tuple(signature)
|
|
|
|
|
+ base_key = (cell_x, cell_y, signature)
|
|
|
|
|
+ tile = self._water_reflection_base_cache.get(base_key)
|
|
|
|
|
+ if tile is None:
|
|
|
|
|
+ tile = pygame.Surface((G.GAME_SQUARE, G.GAME_SQUARE), pygame.SRCALPHA, 32)
|
|
|
|
|
+ for _, image, image_rect, overlap_left, overlap_right, segment_y, segment_idx in candidates:
|
|
|
|
|
+ self.blit_obstacle_reflection(tile, image, image_rect, overlap_left, overlap_right, tile_rect, segment_y, segment_idx)
|
|
|
|
|
+ if len(self._water_reflection_base_cache) > self._water_reflection_cache_limit:
|
|
|
|
|
+ self._water_reflection_base_cache.clear()
|
|
|
|
|
+ self._water_reflection_base_cache[base_key] = tile
|
|
|
|
|
+
|
|
|
|
|
+ distorted_key = (base_key, wave_frame)
|
|
|
|
|
+ distorted = self._water_reflection_distort_cache.get(distorted_key)
|
|
|
|
|
+ if distorted is None:
|
|
|
|
|
+ distorted = self.distort_water_reflection(tile, wave_frame)
|
|
|
|
|
+ self._water_reflection_distort_cache[distorted_key] = distorted
|
|
|
|
|
+ return distorted
|
|
|
|
|
+
|
|
|
|
|
+ def draw_sun_reflections_for_obstacle(self, surface, water, view_rect, wave_frame):
|
|
|
|
|
+ if not self.sunny:
|
|
|
|
|
+ return
|
|
|
|
|
+ width = water.obstacle.get("WIDTH", 1)
|
|
|
|
|
+ height = water.obstacle.get("HEIGHT", 1)
|
|
|
|
|
+ for dx in range(width):
|
|
|
|
|
+ for dy in range(height):
|
|
|
|
|
+ cell_x = water.x + dx
|
|
|
|
|
+ cell_y = water.y + dy
|
|
|
|
|
+ tile_rect = pygame.Rect(
|
|
|
|
|
+ cell_x * G.GAME_SQUARE,
|
|
|
|
|
+ cell_y * G.GAME_SQUARE,
|
|
|
|
|
+ G.GAME_SQUARE,
|
|
|
|
|
+ G.GAME_SQUARE
|
|
|
|
|
+ )
|
|
|
|
|
+ if not tile_rect.colliderect(view_rect):
|
|
|
|
|
+ continue
|
|
|
|
|
+ sun_reflection = self.get_sun_reflection_for_water_cell(cell_x, cell_y, tile_rect, wave_frame)
|
|
|
|
|
+ if sun_reflection is not None:
|
|
|
|
|
+ surface.blit(sun_reflection, tile_rect.topleft)
|
|
|
|
|
+
|
|
|
|
|
+ def get_sun_reflection_for_water_cell(self, cell_x, cell_y, tile_rect, wave_frame):
|
|
|
|
|
+ if not self.sunny:
|
|
|
|
|
+ return None
|
|
|
|
|
+ center_x = self.scroll_x_pos + G.MAIN_AREA_X_POS // 2
|
|
|
|
|
+ center_y = self.scroll_y_pos + G.MAIN_AREA_Y_POS // 2
|
|
|
|
|
+ sun_w = 68
|
|
|
|
|
+ sun_h = 34
|
|
|
|
|
+ sun_rect = pygame.Rect(center_x - sun_w // 2, center_y - sun_h // 2, sun_w, sun_h)
|
|
|
|
|
+ overlap = sun_rect.clip(tile_rect)
|
|
|
|
|
+ if overlap.width <= 0 or overlap.height <= 0:
|
|
|
|
|
+ return None
|
|
|
|
|
+ key = (overlap.x - sun_rect.x, overlap.y - sun_rect.y, overlap.width, overlap.height)
|
|
|
|
|
+ cached = self._sun_reflection_cache.get(key)
|
|
|
|
|
+ if cached is None:
|
|
|
|
|
+ full_sun = pygame.Surface((sun_w, sun_h), pygame.SRCALPHA, 32)
|
|
|
|
|
+ pygame.draw.ellipse(full_sun, (255, 244, 202, 210), (0, 0, sun_w, sun_h))
|
|
|
|
|
+ sun_piece = full_sun.subsurface(pygame.Rect(key)).copy()
|
|
|
|
|
+ sun = pygame.Surface((G.GAME_SQUARE, G.GAME_SQUARE), pygame.SRCALPHA, 32)
|
|
|
|
|
+ sun.blit(sun_piece, (overlap.x - tile_rect.x, overlap.y - tile_rect.y))
|
|
|
|
|
+ if len(self._sun_reflection_cache) > 64:
|
|
|
|
|
+ self._sun_reflection_cache.clear()
|
|
|
|
|
+ self._sun_reflection_cache[key] = sun
|
|
|
|
|
+ cached = sun
|
|
|
|
|
+ distorted_key = ("sun", key, wave_frame)
|
|
|
|
|
+ distorted = self._water_reflection_distort_cache.get(distorted_key)
|
|
|
|
|
+ if distorted is None:
|
|
|
|
|
+ distorted = self.distort_water_reflection(cached, wave_frame)
|
|
|
|
|
+ self._water_reflection_distort_cache[distorted_key] = distorted
|
|
|
|
|
+ return distorted
|
|
|
|
|
+
|
|
|
|
|
+ def is_water_reflect_cell(self, cell_x, cell_y):
|
|
|
|
|
+ obstacle_ref = self.obstacle_instances.get((cell_x, cell_y))
|
|
|
|
|
+ return obstacle_ref is not None and getattr(obstacle_ref, "water_reflect", False)
|
|
|
|
|
+
|
|
|
|
|
+ def draw_dynamic_object(self, obj):
|
|
|
|
|
+ if not self.should_draw_water_submerged(obj):
|
|
|
|
|
+ obj.draw(self.main_area)
|
|
|
|
|
+ return
|
|
|
|
|
+ old_flag = getattr(obj, "_water_submerged_draw", False)
|
|
|
|
|
+ obj._water_submerged_draw = True
|
|
|
|
|
+ try:
|
|
|
|
|
+ obj.draw(self.main_area)
|
|
|
|
|
+ finally:
|
|
|
|
|
+ obj._water_submerged_draw = old_flag
|
|
|
|
|
+
|
|
|
|
|
+ def should_draw_water_submerged(self, obj):
|
|
|
|
|
+ if obj is not self.me and not isinstance(obj, Npc):
|
|
|
|
|
+ return False
|
|
|
|
|
+ if not hasattr(obj, "image") or obj.image is None:
|
|
|
|
|
+ return False
|
|
|
|
|
+ return self.is_water_reflect_cell(obj.x, obj.y)
|
|
|
|
|
+
|
|
|
|
|
+ def get_water_submerged_entity_image(self, image):
|
|
|
|
|
+ key = (id(image), image.get_width(), image.get_height())
|
|
|
|
|
+ cached = self._water_submerged_entity_cache.get(key)
|
|
|
|
|
+ if cached is not None:
|
|
|
|
|
+ return cached
|
|
|
|
|
+ w, h = image.get_size()
|
|
|
|
|
+ if w <= 1 or h <= 1:
|
|
|
|
|
+ return image
|
|
|
|
|
+ bottom_h = min(20, h)
|
|
|
|
|
+ result = image.copy().convert_alpha()
|
|
|
|
|
+ bottom_rect = pygame.Rect(0, h - bottom_h, w, bottom_h)
|
|
|
|
|
+ strip = image.subsurface(bottom_rect).copy()
|
|
|
|
|
+ small = pygame.transform.smoothscale(strip, (max(1, w // 2), max(1, bottom_h // 2)))
|
|
|
|
|
+ strip = pygame.transform.smoothscale(small, (w, bottom_h)).convert_alpha()
|
|
|
|
|
+ strip.set_alpha(95)
|
|
|
|
|
+ result.fill((0, 0, 0, 0), bottom_rect)
|
|
|
|
|
+ result.blit(strip, bottom_rect.topleft)
|
|
|
|
|
+ if len(self._water_submerged_entity_cache) > self._water_reflection_cache_limit:
|
|
|
|
|
+ self._water_submerged_entity_cache.clear()
|
|
|
|
|
+ self._water_submerged_entity_cache[key] = result
|
|
|
|
|
+ return result
|
|
|
|
|
+
|
|
|
|
|
+ def draw_water_submerged_image(self, screen, image, pos, split_y, alpha):
|
|
|
|
|
+ w, h = image.get_size()
|
|
|
|
|
+ split_y = max(0, min(h, int(split_y)))
|
|
|
|
|
+ if split_y >= h:
|
|
|
|
|
+ image.set_alpha(alpha)
|
|
|
|
|
+ screen.blit(image, pos)
|
|
|
|
|
+ return
|
|
|
|
|
+ if split_y > 0:
|
|
|
|
|
+ image.set_alpha(alpha)
|
|
|
|
|
+ screen.blit(image, pos, pygame.Rect(0, 0, w, split_y))
|
|
|
|
|
+ bottom_h = h - split_y
|
|
|
|
|
+ key = (id(image), w, h, split_y, alpha)
|
|
|
|
|
+ strip = self._water_submerged_entity_cache.get(key)
|
|
|
|
|
+ if strip is None:
|
|
|
|
|
+ strip = image.subsurface(pygame.Rect(0, split_y, w, bottom_h)).copy()
|
|
|
|
|
+ small = pygame.transform.smoothscale(strip, (max(1, w // 2), max(1, bottom_h // 2)))
|
|
|
|
|
+ strip = pygame.transform.smoothscale(small, (w, bottom_h)).convert_alpha()
|
|
|
|
|
+ strip.set_alpha(min(alpha, 95))
|
|
|
|
|
+ if len(self._water_submerged_entity_cache) > self._water_reflection_cache_limit:
|
|
|
|
|
+ self._water_submerged_entity_cache.clear()
|
|
|
|
|
+ self._water_submerged_entity_cache[key] = strip
|
|
|
|
|
+ screen.blit(strip, (pos[0], pos[1] + split_y))
|
|
|
|
|
+
|
|
|
|
|
+ def get_water_reflection_image(self, image):
|
|
|
|
|
+ key = (id(image), image.get_width(), image.get_height())
|
|
|
|
|
+ reflected = self._water_reflection_image_cache.get(key)
|
|
|
|
|
+ if reflected is not None:
|
|
|
|
|
+ return reflected
|
|
|
|
|
+ flipped = pygame.transform.flip(image, False, True)
|
|
|
|
|
+ reflected_h = max(1, int(image.get_height() * 0.8))
|
|
|
|
|
+ reflected = pygame.transform.smoothscale(flipped, (image.get_width(), reflected_h)).convert_alpha()
|
|
|
|
|
+ if len(self._water_reflection_image_cache) > self._water_reflection_cache_limit:
|
|
|
|
|
+ self._water_reflection_image_cache.clear()
|
|
|
|
|
+ self._water_reflection_image_cache[key] = reflected
|
|
|
|
|
+ return reflected
|
|
|
|
|
+
|
|
|
|
|
+ def blit_obstacle_reflection(self, tile, image, image_rect, overlap_left, overlap_right, tile_rect, segment_y, segment_idx):
|
|
|
|
|
+ src_x = overlap_left - image_rect.left
|
|
|
|
|
+ src_w = overlap_right - overlap_left
|
|
|
|
|
+ if segment_idx == 0:
|
|
|
|
|
+ src_h = min(G.GAME_SQUARE, image.get_height() - segment_y)
|
|
|
|
|
+ dest_h = src_h
|
|
|
|
|
+ alpha = 92
|
|
|
|
|
+ else:
|
|
|
|
|
+ src_h = image.get_height() - segment_y
|
|
|
|
|
+ dest_h = G.GAME_SQUARE
|
|
|
|
|
+ alpha = 52
|
|
|
|
|
+ return self.blit_reflection_band(tile, image, src_x, segment_y, src_w, src_h, overlap_left - tile_rect.left, 0, dest_h, alpha)
|
|
|
|
|
+
|
|
|
|
|
+ def blit_reflection_band(self, tile, image, src_x, src_y, src_w, src_h, dest_x, dest_y, dest_h, alpha):
|
|
|
|
|
+ if src_w <= 0 or src_h <= 0 or dest_h <= 0:
|
|
|
|
|
+ return False
|
|
|
|
|
+ src_rect = pygame.Rect(src_x, src_y, src_w, src_h)
|
|
|
|
|
+ src_rect = src_rect.clip(image.get_rect())
|
|
|
|
|
+ if src_rect.width <= 0 or src_rect.height <= 0:
|
|
|
|
|
+ return False
|
|
|
|
|
+ piece = image.subsurface(src_rect).copy()
|
|
|
|
|
+ if src_rect.height != dest_h:
|
|
|
|
|
+ piece = pygame.transform.smoothscale(piece, (src_rect.width, dest_h)).convert_alpha()
|
|
|
|
|
+ piece.set_alpha(alpha)
|
|
|
|
|
+ tile.blit(piece, (dest_x, dest_y))
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+ def distort_water_reflection(self, source, wave_frame):
|
|
|
|
|
+ w, h = source.get_size()
|
|
|
|
|
+ if w <= 2 or h <= 2:
|
|
|
|
|
+ return source
|
|
|
|
|
+ small = pygame.transform.smoothscale(source, (max(1, w // 2), max(1, h // 2)))
|
|
|
|
|
+ source = pygame.transform.smoothscale(small, (w, h)).convert_alpha()
|
|
|
|
|
+ result = pygame.Surface((w, h), pygame.SRCALPHA, 32)
|
|
|
|
|
+ phase = wave_frame * 0.65
|
|
|
|
|
+ band_h = 5
|
|
|
|
|
+ for y in range(0, h, band_h):
|
|
|
|
|
+ offset = int(math.sin(phase + y * 0.35) * 2)
|
|
|
|
|
+ result.blit(source, (offset, y), (0, y, w, band_h))
|
|
|
|
|
+ return result
|
|
|
|
|
+
|
|
|
def earth_quake_effect(self, strength=0.1, times=3, duration_per_time=200, decrease=True, direction=None):
|
|
def earth_quake_effect(self, strength=0.1, times=3, duration_per_time=200, decrease=True, direction=None):
|
|
|
"""屏幕震动效果,强度表示移动像素数量,times表示震动次数,duration_per_time表示每次震动持续时间"""
|
|
"""屏幕震动效果,强度表示移动像素数量,times表示震动次数,duration_per_time表示每次震动持续时间"""
|
|
|
if direction is None:
|
|
if direction is None:
|
|
@@ -624,7 +928,7 @@ class Level:
|
|
|
|
|
|
|
|
def load_floor(self):
|
|
def load_floor(self):
|
|
|
# 加载地板floor
|
|
# 加载地板floor
|
|
|
- self.floor_image = pygame.Surface((self.map_x_pos, self.map_y_pos), flags=pygame.HWSURFACE)
|
|
|
|
|
|
|
+ self.floor_image = pygame.Surface((self.map_x_pos, self.map_y_pos), flags=pygame.HWSURFACE).convert_alpha()
|
|
|
# 块区域加载
|
|
# 块区域加载
|
|
|
for f in self.map_json["floors"]:
|
|
for f in self.map_json["floors"]:
|
|
|
for square in f["squares"]:
|
|
for square in f["squares"]:
|
|
@@ -1116,16 +1420,22 @@ class Level:
|
|
|
draw = self.main_area.blit
|
|
draw = self.main_area.blit
|
|
|
while i < len(A) and j < len(B):
|
|
while i < len(A) and j < len(B):
|
|
|
if A[i][0] <= B[j][0]:
|
|
if A[i][0] <= B[j][0]:
|
|
|
- A[i][2].draw(self.main_area)
|
|
|
|
|
|
|
+ static_obj = A[i][2]
|
|
|
|
|
+ static_obj.draw(self.main_area)
|
|
|
|
|
+ if getattr(static_obj, "water_reflect", False):
|
|
|
|
|
+ self.draw_water_reflection_for_obstacle(self.main_area, static_obj)
|
|
|
i += 1
|
|
i += 1
|
|
|
else:
|
|
else:
|
|
|
- B[j][2].draw(self.main_area)
|
|
|
|
|
|
|
+ self.draw_dynamic_object(B[j][2])
|
|
|
j += 1
|
|
j += 1
|
|
|
while i < len(A):
|
|
while i < len(A):
|
|
|
- A[i][2].draw(self.main_area)
|
|
|
|
|
|
|
+ static_obj = A[i][2]
|
|
|
|
|
+ static_obj.draw(self.main_area)
|
|
|
|
|
+ if getattr(static_obj, "water_reflect", False):
|
|
|
|
|
+ self.draw_water_reflection_for_obstacle(self.main_area, static_obj)
|
|
|
i += 1
|
|
i += 1
|
|
|
while j < len(B):
|
|
while j < len(B):
|
|
|
- B[j][2].draw(self.main_area)
|
|
|
|
|
|
|
+ self.draw_dynamic_object(B[j][2])
|
|
|
j += 1
|
|
j += 1
|
|
|
|
|
|
|
|
if self.special_rgb:
|
|
if self.special_rgb:
|