加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Trap.py 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
HURUIZHE 提交于 2022-01-17 20:45 . Our game
import pygame
class Traps:
def __init__(self, x, y, trap_type, if_visible):
self.type = trap_type # type 0: damage, type 1: freeze
self.if_v = if_visible
self.coord_x = x
self.coord_y = y
self.triggered = False
if self.type == 0:
self.image_armed = pygame.image.load(r"image/armed_explode_trap.png")
self.image_triggered = pygame.image.load(r"image/broken_explode_trap.png")
elif self.type == 1:
self.image_armed = pygame.image.load(r"image/armed_freeze_trap.png")
self.image_triggered = pygame.image.load(r"image/broken_freeze_trap.png")
if not self.if_v:
self.image_armed = pygame.image.load(r"image/blank_trap.png")
self.image = self.image_armed
# trigger current trap
def trigger(self):
if ~self.triggered:
self.triggered = True
if self.type == 0:
sound = pygame.mixer.Sound("sound/sound_effect/explode_trap.mp3")
else:
sound = pygame.mixer.Sound("sound/sound_effect/freeze.wav")
sound.set_volume(1)
sound.play()
self.image = self.image_triggered
# judge if the trap is still not triggered
def functioning(self):
if self.triggered:
return False
else:
return True
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化