明确变量名含义

This commit is contained in:
星外之神 2022-07-29 23:23:28 +08:00
parent b9a08ba9aa
commit ad5bd75478
5 changed files with 34 additions and 35 deletions

View File

@ -166,8 +166,8 @@ GRAVES_GRADE_INFO = (0, 4, 7, 11)
# 僵尸生成方式
SPAWN_ZOMBIES = "spawn_zombies"
SPAWN_ZOMBIES_AUTO = "auto"
SPAWN_ZOMBIES_LIST = "list"
SPAWN_ZOMBIES_AUTO = 1
SPAWN_ZOMBIES_LIST = 0
INCLUDED_ZOMBIES = "included_zombies"
NUM_FLAGS = "num_flags"
INEVITABLE_ZOMBIE_DICT = "inevitable_zombie_list"

View File

@ -433,11 +433,11 @@ class Level(tool.State):
if self.hasShovel:
# 导入小铲子
frame_rect = [0, 0, 71, 67]
self.shovel = tool.get_image_menu(tool.GFX[c.SHOVEL], *frame_rect, c.BLACK, 1.1)
self.shovel = tool.get_image_alpha(tool.GFX[c.SHOVEL], *frame_rect, c.BLACK, 1.1)
self.shovel_rect = self.shovel.get_rect()
frame_rect = [0, 0, 77, 75]
self.shovel_positon = (608, 1)
self.shovel_box = tool.get_image_menu(tool.GFX[c.SHOVEL_BOX], *frame_rect, c.BLACK, 1.1)
self.shovel_box = tool.get_image_alpha(tool.GFX[c.SHOVEL_BOX], *frame_rect, c.BLACK, 1.1)
self.shovel_box_rect = self.shovel_box.get_rect()
self.shovel_rect.x = self.shovel_box_rect.x = self.shovel_positon[0]
self.shovel_rect.y = self.shovel_box_rect.y = self.shovel_positon[1]
@ -476,14 +476,14 @@ class Level(tool.State):
def setupLittleMenu(self):
# 具体运行游戏必定有个小菜单, 导入菜单和选项
frame_rect = (0, 0, 108, 31)
self.little_menu = tool.get_image_menu(tool.GFX[c.LITTLE_MENU], *frame_rect, c.BLACK, 1.1)
self.little_menu = tool.get_image_alpha(tool.GFX[c.LITTLE_MENU], *frame_rect, c.BLACK, 1.1)
self.little_menu_rect = self.little_menu.get_rect()
self.little_menu_rect.x = 690
self.little_menu_rect.y = 0
# 弹出的菜单框
frame_rect = (0, 0, 500, 500)
self.big_menu = tool.get_image_menu(tool.GFX[c.BIG_MENU], *frame_rect, c.BLACK, 1.1)
self.big_menu = tool.get_image_alpha(tool.GFX[c.BIG_MENU], *frame_rect, c.BLACK, 1.1)
self.big_menu_rect = self.big_menu.get_rect()
self.big_menu_rect.x = 150
self.big_menu_rect.y = 0
@ -505,14 +505,14 @@ class Level(tool.State):
# 重新开始按钮
frame_rect = (0, 0, 207, 45)
self.restart_button = tool.get_image_menu(tool.GFX[c.RESTART_BUTTON], *frame_rect, c.BLACK, 1.1)
self.restart_button = tool.get_image_alpha(tool.GFX[c.RESTART_BUTTON], *frame_rect, c.BLACK, 1.1)
self.restart_button_rect = self.restart_button.get_rect()
self.restart_button_rect.x = 295
self.restart_button_rect.y = 325
# 主菜单按钮
frame_rect = (0, 0, 206, 43)
self.mainMenu_button = tool.get_image_menu(tool.GFX[c.MAINMENU_BUTTON], *frame_rect, c.BLACK, 1.1)
self.mainMenu_button = tool.get_image_alpha(tool.GFX[c.MAINMENU_BUTTON], *frame_rect, c.BLACK, 1.1)
self.mainMenu_button_rect = self.mainMenu_button.get_rect()
self.mainMenu_button_rect.x = 299
self.mainMenu_button_rect.y = 372
@ -522,7 +522,7 @@ class Level(tool.State):
font = pg.font.Font(c.FONT_PATH, 35)
font.bold = True
# 音量+
self.sound_volume_plus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
self.sound_volume_plus_button = tool.get_image_alpha(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
sign = font.render("+", True, c.YELLOWGREEN)
sign_rect = sign.get_rect()
sign_rect.x = 8
@ -531,7 +531,7 @@ class Level(tool.State):
self.sound_volume_plus_button_rect = self.sound_volume_plus_button.get_rect()
self.sound_volume_plus_button_rect.x = 500
# 音量-
self.sound_volume_minus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
self.sound_volume_minus_button = tool.get_image_alpha(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
sign = font.render("-", True, c.YELLOWGREEN)
sign_rect = sign.get_rect()
sign_rect.x = 12
@ -595,7 +595,7 @@ class Level(tool.State):
# 一大波僵尸来袭图片显示
def setupHugeWaveApprochingImage(self):
frame_rect = (0, 0, 492, 80)
self.huge_wave_approching_image = tool.get_image_menu(tool.GFX[c.HUGE_WAVE_APPROCHING], *frame_rect, c.BLACK, 1)
self.huge_wave_approching_image = tool.get_image_alpha(tool.GFX[c.HUGE_WAVE_APPROCHING], *frame_rect, c.BLACK, 1)
self.huge_wave_approching_image_rect = self.huge_wave_approching_image.get_rect()
self.huge_wave_approching_image_rect.x = 140 # 猜的
self.huge_wave_approching_image_rect.y = 250 # 猜的
@ -606,21 +606,21 @@ class Level(tool.State):
# 主进度条
frame_rect = (0, 0, 158, 26)
self.level_progress_bar_image = tool.get_image_menu(tool.GFX[c.LEVEL_PROGRESS_BAR], *frame_rect, c.BLACK, 1)
self.level_progress_bar_image = tool.get_image_alpha(tool.GFX[c.LEVEL_PROGRESS_BAR], *frame_rect, c.BLACK, 1)
self.level_progress_bar_image_rect = self.level_progress_bar_image.get_rect()
self.level_progress_bar_image_rect.x = 600
self.level_progress_bar_image_rect.y = 574
# 僵尸头
frame_rect = (0, 0, 23, 25)
self.level_progress_zombie_head_image = tool.get_image_menu(tool.GFX[c.LEVEL_PROGRESS_ZOMBIE_HEAD], *frame_rect, c.BLACK, 1)
self.level_progress_zombie_head_image = tool.get_image_alpha(tool.GFX[c.LEVEL_PROGRESS_ZOMBIE_HEAD], *frame_rect, c.BLACK, 1)
self.level_progress_zombie_head_image_rect = self.level_progress_zombie_head_image.get_rect()
self.level_progress_zombie_head_image_rect.x = self.level_progress_bar_image_rect.x + 75
self.level_progress_zombie_head_image_rect.y = self.level_progress_bar_image_rect.y - 3
# 旗帜(这里只包括最后一面)
frame_rect = (0, 0, 20, 18)
self.level_progress_flag = tool.get_image_menu(tool.GFX[c.LEVEL_PROGRESS_FLAG], *frame_rect, c.BLACK, 1)
self.level_progress_flag = tool.get_image_alpha(tool.GFX[c.LEVEL_PROGRESS_FLAG], *frame_rect, c.BLACK, 1)
self.level_progress_flag_rect = self.level_progress_flag.get_rect()
self.level_progress_flag_rect.x = self.level_progress_bar_image_rect.x - 78
self.level_progress_flag_rect.y = self.level_progress_bar_image_rect.y - 3

View File

@ -41,7 +41,7 @@ class Menu(tool.State):
frame_names = (f"{c.OPTION_ADVENTURE}_0", f"{c.OPTION_ADVENTURE}_1")
frame_rect = (0, 0, 330, 144)
for name in frame_names:
self.adventure_frames.append(tool.get_image_menu(tool.GFX[name], *frame_rect, c.BLACK, 1))
self.adventure_frames.append(tool.get_image_alpha(tool.GFX[name], *frame_rect, c.BLACK, 1))
self.adventure_image = self.adventure_frames[0]
self.adventure_rect = self.adventure_image.get_rect()
self.adventure_rect.x = 400
@ -53,7 +53,7 @@ class Menu(tool.State):
exit_frame_names = (f"{c.EXIT}_0", f"{c.EXIT}_1")
exit_frame_rect = (0, 0, 47, 27)
for name in exit_frame_names:
self.exit_frames.append(tool.get_image_menu(tool.GFX[name], *exit_frame_rect, c.BLACK, 1.1))
self.exit_frames.append(tool.get_image_alpha(tool.GFX[name], *exit_frame_rect, c.BLACK, 1.1))
self.exit_image = self.exit_frames[0]
self.exit_rect = self.exit_image.get_rect()
self.exit_rect.x = 730
@ -65,7 +65,7 @@ class Menu(tool.State):
option_button_frame_names = (f"{c.OPTION_BUTTON}_0", f"{c.OPTION_BUTTON}_1")
option_button_frame_rect = (0, 0, 81, 31)
for name in option_button_frame_names:
self.option_button_frames.append(tool.get_image_menu(tool.GFX[name], *option_button_frame_rect, c.BLACK))
self.option_button_frames.append(tool.get_image_alpha(tool.GFX[name], *option_button_frame_rect, c.BLACK))
self.option_button_image = self.option_button_frames[0]
self.option_button_rect = self.option_button_image.get_rect()
self.option_button_rect.x = 560
@ -77,7 +77,7 @@ class Menu(tool.State):
littleGame_frame_names = (c.LITTLEGAME_BUTTON + "_0", c.LITTLEGAME_BUTTON + "_1")
littleGame_frame_rect = (0, 7, 317, 135)
for name in littleGame_frame_names:
self.littleGame_frames.append(tool.get_image_menu(tool.GFX[name], *littleGame_frame_rect, c.BLACK, 1))
self.littleGame_frames.append(tool.get_image_alpha(tool.GFX[name], *littleGame_frame_rect, c.BLACK, 1))
self.littleGame_image = self.littleGame_frames[0]
self.littleGame_rect = self.littleGame_image.get_rect()
self.littleGame_rect.x = 397
@ -145,7 +145,7 @@ class Menu(tool.State):
def setupOptionMenu(self):
# 选项菜单框
frame_rect = (0, 0, 500, 500)
self.big_menu = tool.get_image_menu(tool.GFX[c.BIG_MENU], *frame_rect, c.BLACK, 1.1)
self.big_menu = tool.get_image_alpha(tool.GFX[c.BIG_MENU], *frame_rect, c.BLACK, 1.1)
self.big_menu_rect = self.big_menu.get_rect()
self.big_menu_rect.x = 150
self.big_menu_rect.y = 0
@ -170,7 +170,7 @@ class Menu(tool.State):
font = pg.font.Font(c.FONT_PATH, 35)
font.bold = True
# 音量+
self.sound_volume_plus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
self.sound_volume_plus_button = tool.get_image_alpha(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
sign = font.render("+", True, c.YELLOWGREEN)
sign_rect = sign.get_rect()
sign_rect.x = 8
@ -179,7 +179,7 @@ class Menu(tool.State):
self.sound_volume_plus_button_rect = self.sound_volume_plus_button.get_rect()
self.sound_volume_plus_button_rect.x = 500
# 音量-
self.sound_volume_minus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
self.sound_volume_minus_button = tool.get_image_alpha(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK)
sign = font.render("-", True, c.YELLOWGREEN)
sign_rect = sign.get_rect()
sign_rect.x = 12
@ -197,7 +197,7 @@ class Menu(tool.State):
frame_rect = (157, 0, 157, 269)
else:
frame_rect = (0, 0, 157, 269)
self.sunflower_trophy = tool.get_image_menu(tool.GFX[c.TROPHY_SUNFLOWER], *frame_rect, c.BLACK)
self.sunflower_trophy = tool.get_image_alpha(tool.GFX[c.TROPHY_SUNFLOWER], *frame_rect, c.BLACK)
self.sunflower_trophy_rect = self.sunflower_trophy.get_rect()
self.sunflower_trophy_rect.x = 0
self.sunflower_trophy_rect.y = 280

View File

@ -20,7 +20,7 @@ class Screen(tool.State):
# 按钮
frame_rect = (0, 0, 111, 26)
## 主菜单按钮
self.main_menu_button_image = tool.get_image_menu(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.main_menu_button_image = tool.get_image_alpha(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.main_menu_button_image_rect = self.main_menu_button_image.get_rect()
self.main_menu_button_image_rect.x = 620
### 主菜单按钮上的文字
@ -29,7 +29,7 @@ class Screen(tool.State):
main_menu_text_rect = main_menu_text.get_rect()
main_menu_text_rect.x = 29
## 继续按钮
self.next_button_image = tool.get_image_menu(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.next_button_image = tool.get_image_alpha(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.next_button_image_rect = self.next_button_image.get_rect()
self.next_button_image_rect.x = 70
### 继续按钮上的文字
@ -116,7 +116,7 @@ class AwardScreen(tool.State):
frame_rect = (0, 0, 111, 26)
if self.show_only_one_option:
## 主菜单按钮
self.main_menu_button_image = tool.get_image_menu(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.main_menu_button_image = tool.get_image_alpha(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.main_menu_button_image_rect = self.main_menu_button_image.get_rect()
self.main_menu_button_image_rect.x = 343
self.main_menu_button_image_rect.y = 520
@ -129,7 +129,7 @@ class AwardScreen(tool.State):
self.image.blit(self.main_menu_button_image, self.main_menu_button_image_rect)
else:
## 继续按钮
self.next_button_image = tool.get_image_menu(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.next_button_image = tool.get_image_alpha(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.next_button_image_rect = self.next_button_image.get_rect()
self.next_button_image_rect.x = 70
### 继续按钮上的文字
@ -138,7 +138,7 @@ class AwardScreen(tool.State):
next_text_rect = next_text.get_rect()
next_text_rect.x = 37
## 主菜单按钮
self.main_menu_button_image = tool.get_image_menu(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.main_menu_button_image = tool.get_image_alpha(tool.GFX[c.UNIVERSAL_BUTTON], *frame_rect)
self.main_menu_button_image_rect = self.main_menu_button_image.get_rect()
self.main_menu_button_image_rect.x = 620
self.next_button_image_rect.y = self.main_menu_button_image_rect.y = 540
@ -165,7 +165,7 @@ class AwardScreen(tool.State):
intro_content = "您已完成冒险模式,获得此奖励!"
else:
intro_content = "您已完成玩玩小游戏,获得此奖励!"
sunflower_trophy_image = tool.get_image_menu(tool.GFX[c.TROPHY_SUNFLOWER], *frame_rect, scale=0.7)
sunflower_trophy_image = tool.get_image_alpha(tool.GFX[c.TROPHY_SUNFLOWER], *frame_rect, scale=0.7)
sunflower_trophy_rect = sunflower_trophy_image.get_rect()
sunflower_trophy_rect.x = 348
sunflower_trophy_rect.y = 108

View File

@ -5,7 +5,7 @@ import pygame as pg
from pygame.locals import *
from . import constants as c
# an abstract class, one state of automata
# 状态机 抽象基类
class State():
def __init__(self):
self.start_time = 0
@ -17,7 +17,7 @@ class State():
# 当从其他状态进入这个状态时,需要进行的初始化操作
@abstractmethod
def startup(self, current_time, persist):
# abstract method
# 前面加了@abstractmethod表示抽象基类中必须要重新定义的methodmethod是对象和函数的结合
pass
# 当从这个状态退出时,需要进行的清除操作
def cleanup(self):
@ -26,7 +26,7 @@ class State():
# 在这个状态运行时进行的更新操作
@abstractmethod
def update(self, surface, keys, current_time):
# abstract method
# 前面加了@abstractmethod表示抽象基类中必须要重新定义的method
pass
# 工具:范围判断函数,用于判断点击
@ -47,7 +47,7 @@ class State():
data_to_save = json.dumps(userdata, sort_keys=True, indent=4)
f.write(data_to_save)
# control this game. do event loops
# 进行游戏控制 循环 事件响应
class Control():
def __init__(self):
self.screen = pg.display.get_surface()
@ -100,7 +100,7 @@ class Control():
self.state.startup(self.current_time, self.game_info)
def update(self):
# 返回自 pygame_init() 调用以来的毫秒数 * 游戏速度倍率
# 自 pygame_init() 调用以来的毫秒数 * 游戏速度倍率,即游戏时间
self.current_time = pg.time.get_ticks() * self.game_info[c.GAME_RATE]
if self.state.done:
@ -116,7 +116,6 @@ class Control():
if self.state.next == c.EXIT:
pg.quit()
os._exit(0)
# previous, self.state_name = self.state_name, self.state.next
self.state_name = self.state.next
persist = self.state.cleanup()
self.state = self.state_dict[self.state_name]
@ -162,7 +161,7 @@ def get_image(sheet, x, y, width, height, colorkey=c.BLACK, scale=1):
int(rect.height*scale)))
return image
def get_image_menu(sheet, x, y, width, height, colorkey=c.BLACK, scale=1):
def get_image_alpha(sheet, x, y, width, height, colorkey=c.BLACK, scale=1):
# 保留alpha通道的图片导入
image = pg.Surface([width, height], SRCALPHA)
rect = image.get_rect()