#4869·pygame

游戏

作者: ghiandelcarpiom-collab创建于 2026年6月17日更新于 2026年6月17日

def init(self, x, y, color, name="Actor"): self.pos = pygame.Vector2(x, y) self.rect = pygame.Rect(x, y, 30, 48) self.vel = pygame.Vector2(0, 0) self.color = color self.name = name self.health = 100 self.alive = True self.on_ground = False self.on_wall = 0 # -1 left wall, 1 right wall self.jumps_left = 1 self.facing = 1 self.control_lock = 0.0 self.hit_flash = 0.0 def center(self): return pygame.Vector2(self.rect.center) def damage(self, amount): if not self.alive: return self.health -= amount self.hit_flash = 0.12 if self.health <= 0: self.health = 0 self.alive = False def jump(self): if not self.alive: return # Normal jump if self.on_ground: self.vel.y = -JUMP_POWER self.on_ground = False self.jumps_left = 1 # Wall jump: push in the opposite direction of the wall. elif self.on_wall != 0: self.vel.y = -JUMP_POWER * 0.92 self.vel.x = -self.on_wall * WALL_JUMP_PUSH self.jumps_left = 1 self.control_lock = 0.16 # Double jump elif self.jumps_left > 0: self.vel.y = -DOUBLE_JUMP_POWER self.jumps_left -= 1