Skip to content

Commit

Permalink
优化太空保卫战游戏中的配置参数和玩家飞船的生命值和护盾值
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiesun committed Apr 13, 2024
1 parent 2e5f693 commit 5708e1c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
12 changes: 6 additions & 6 deletions spacedefense_wasm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"fire_sound_volume": 0.4,
"firehit_sound_volume": 0.4,
"super_bullet": {
"score_cast": 50,
"score_cast": 300,
"life_value": 500,
"speed": 4,
"acc_distance_1": 400,
"acc_distance_2": 200,
"damage": 500,
"damage": 100,
"fire_delay": 180,
"image": "images/ufo_super_bullet.webp",
"fire_sound": "sounds/super_fire.ogg",
Expand Down Expand Up @@ -69,9 +69,9 @@
"firehit_sound_volume": 0.4,
},
"myf_master": {
"life_value": 700,
"shield_value": 300,
"shield_recharge_step": 2,
"life_value": 1000,
"shield_value": 500,
"shield_recharge_step": 1,
"speed_x": 9,
"images": ["images/myf_master.webp"],
"firehit_sound": "sounds/firehit.ogg",
Expand Down Expand Up @@ -111,7 +111,7 @@
"speed": 4,
"acc_distance_1": 400,
"acc_distance_2": 300,
"damage": 300,
"damage": 100,
"fire_delay": 200,
"image": "images/super_bullet.webp",
"fire_sound": "sounds/super_fire.ogg",
Expand Down
32 changes: 21 additions & 11 deletions spacedefense_wasm/my_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,35 @@ def super_fire(self, src_group, target, particle_group):
sound.play()

def hit(self, damage: int):
"""被击中, 减少生命值"""
# 升级后伤害递减
damage - (self.level - 1) / 20

"""被击中减少生命值"""
# 伤害递减计算,确保伤害不会低于0
damage = max(0, damage - (self.level - 1) / 20)
if self.shield_value > 0:
# 如果伤害大于护盾值,则扣除超出的部分
overshoot = damage - self.shield_value
self.shield_value -= damage
if self.shield_value <= 0:
if self.shield_value < 0:
self.shield_value = 0
self.life_value += self.shield_value

# 护盾用尽后,任何剩余的伤害应该扣除生命值
if overshoot > 0:
self.life_value -= overshoot
else:
if self.life_value > 0:
self.life_value -= damage
if self.life_value <= 0:
self.life_value = 0

# 没有护盾,直接扣除生命值
self.life_value -= damage

# 如果生命值降到0或以下,玩家飞船毁灭
if self.life_value <= 0:
self.life_value = 0
# 这里可以添加飞船销毁的逻辑

# 播放被击中的声音
sound = res_manager.load_sound(self.config["firehit_sound"])
sound.set_volume(self.config["firehit_sound_volume"])
sound.play()


def dodge_fighter(self, target: pygame.sprite.Sprite):
pass

Expand Down

0 comments on commit 5708e1c

Please sign in to comment.