pygame
in platformer Gamesのプラットフォーマーにスクロールを追加します。この効果はスクロールによって達成されます。これにより、ゲームの世界はプレイヤーの位置とは独立して移動できます。このオフセットは、画面に描かれたときにすべてのゲームエンティティの位置に適用されます。 def __init __(self、camera_func、幅、高さ): self.camera_func = camera_func self.state = rect(0、0、width、height) def apply(self、target): return target.rect.move(self.state.topleft) def update(self、target): self.state = self.camera_func(self.state、target.rect)
camero_func:
はカメラがプレーヤーに従う方法を決定します。 pixels。 l、t、_、_ = target_rect#l = left、t = top _、_、w、h = camera#w = width、h = height return rect(-l half_width、-t half_height、w、h)レベルの境界を維持する:
def complex_camera(カメラ、ターゲット_rect): x = -target_rect.center [0] win_width/2 y = -target_rect.center [1] win_height/2 camera.topleft =(pygame.vector2((x、y))-pygame.vector2(camera.topleft)) * 0.06#滑らかさを追加する camera.x = max( - (camera.width-win_width)、min(0、camera.x)) camera.y = max( - (camera.height-win_height)、min(0、camera.y)) カメラ
class Camera: def __init__(self, camera_func, width, height): self.camera_func = camera_func self.state = Rect(0, 0, width, height) def apply(self, target): return target.rect.move(self.state.topleft) def update(self, target): self.state = self.camera_func(self.state, target.rect)
追加の考慮事項:
免責事項: 提供されるすべてのリソースの一部はインターネットからのものです。お客様の著作権またはその他の権利および利益の侵害がある場合は、詳細な理由を説明し、著作権または権利および利益の証拠を提出して、電子メール [email protected] に送信してください。 できるだけ早く対応させていただきます。
Copyright© 2022 湘ICP备2022001581号-3