diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 2c935ae..6b17e1a 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -15,7 +15,6 @@ jobs: matrix: python_version: - "3.11" - - "3.10" name: Windows Python ${{ matrix.python_version }} steps: - uses: actions/checkout@v2 @@ -75,7 +74,7 @@ jobs: --include-data-file=c:\hostedtoolcache\windows\python\${{ matrix.python_version }}*\x64\lib\site-packages\pygame\libvorbisfile-3.dll=libvorbisfile-3.dll ` --include-data-file=c:\hostedtoolcache\windows\python\${{ matrix.python_version }}*\x64\lib\site-packages\pygame\libvorbis-0.dll=libvorbis-0.dll ` --windows-disable-console ` - -o ./out/pypvz-with-python${{ matrix.python_version }}-nuitka-windows-x64.exe ` + -o pypvz-with-python${{ matrix.python_version }}-nuitka-windows-x64.exe ` pypvz.py - name: Release the version built by nuitka @@ -83,7 +82,7 @@ jobs: with: allowUpdates: true tag: Dev - artifacts: ./out/*nuitka*.exe + artifacts: ./*nuitka*.exe token: ${{ secrets.GITHUB_TOKEN }} @@ -93,7 +92,6 @@ jobs: fail-fast: false matrix: python_version: - - "3.10" - "3.11" name: Ubuntu Python ${{ matrix.python_version }} steps: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7fcabcb..d257987 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,6 @@ jobs: matrix: python_version: - "3.11" - - "3.10" name: Windows Python ${{ matrix.python_version }} steps: - uses: actions/checkout@v2 @@ -77,7 +76,7 @@ jobs: --include-data-file=c:\hostedtoolcache\windows\python\${{ matrix.python_version }}*\x64\lib\site-packages\pygame\libvorbisfile-3.dll=libvorbisfile-3.dll ` --include-data-file=c:\hostedtoolcache\windows\python\${{ matrix.python_version }}*\x64\lib\site-packages\pygame\libvorbis-0.dll=libvorbis-0.dll ` --windows-disable-console ` - -o ./out/pypvz-with-python${{ matrix.python_version }}-nuitka-windows-x64.exe ` + -o pypvz-with-python${{ matrix.python_version }}-nuitka-windows-x64.exe ` pypvz.py @@ -86,7 +85,7 @@ jobs: with: allowUpdates: true tag: Latest - artifacts: ./out/*nuitka*.exe + artifacts: ./*nuitka*.exe token: ${{ secrets.GITHUB_TOKEN }} linux: @@ -95,7 +94,6 @@ jobs: fail-fast: false matrix: python_version: - - "3.10" - "3.11" name: Ubuntu Python ${{ matrix.python_version }} steps: diff --git a/README.md b/README.md index 95dadec..a328fa8 100644 --- a/README.md +++ b/README.md @@ -295,29 +295,29 @@ pyinstaller -F pypvz.py ` ## 截屏 -![截屏1](/demo/demo1.webp) -![截屏2](/demo/demo2.webp) -![截屏3](/demo/demo3.webp) -![截屏4](/demo/demo4.webp) -![截屏5](/demo/demo5.webp) -![截屏6](/demo/demo6.webp) -![截屏7](/demo/demo7.webp) -![截屏8](/demo/demo8.webp) -![截屏9](/demo/demo9.webp) -![截屏10](/demo/demo10.webp) -![截屏11](/demo/demo11.webp) -![截屏12](/demo/demo12.webp) -![截屏13](/demo/demo13.webp) -![截屏14](/demo/demo14.webp) -![截屏15](/demo/demo15.webp) -![截屏16](/demo/demo16.webp) -![截屏17](/demo/demo17.webp) -![截屏18](/demo/demo18.webp) -![截屏19](/demo/demo19.webp) -![截屏20](/demo/demo20.webp) -![截屏21](/demo/demo21.webp) -![截屏22](/demo/demo22.webp) -![截屏23](/demo/demo23.webp) +![截屏1](/screenshots/screenshot-1.webp) +![截屏2](/screenshots/screenshot-2.webp) +![截屏3](/screenshots/screenshot-3.webp) +![截屏4](/screenshots/screenshot-4.webp) +![截屏5](/screenshots/screenshot-5.webp) +![截屏6](/screenshots/screenshot-6.webp) +![截屏7](/screenshots/screenshot-7.webp) +![截屏8](/screenshots/screenshot-8.webp) +![截屏9](/screenshots/screenshot-9.webp) +![截屏10](/screenshots/screenshot-10.webp) +![截屏11](/screenshots/screenshot-11.webp) +![截屏12](/screenshots/screenshot-12.webp) +![截屏13](/screenshots/screenshot-13.webp) +![截屏14](/screenshots/screenshot-14.webp) +![截屏15](/screenshots/screenshot-15.webp) +![截屏16](/screenshots/screenshot-16.webp) +![截屏17](/screenshots/screenshot-17.webp) +![截屏18](/screenshots/screenshot-18.webp) +![截屏19](/screenshots/screenshot-19.webp) +![截屏20](/screenshots/screenshot-20.webp) +![截屏21](/screenshots/screenshot-21.webp) +![截屏22](/screenshots/screenshot-22.webp) +![截屏23](/screenshots/screenshot-23.webp) ## 关于日志与反馈 diff --git a/demo/demo1.webp b/screenshots/screenshot-1.webp similarity index 100% rename from demo/demo1.webp rename to screenshots/screenshot-1.webp diff --git a/demo/demo10.webp b/screenshots/screenshot-10.webp similarity index 100% rename from demo/demo10.webp rename to screenshots/screenshot-10.webp diff --git a/demo/demo11.webp b/screenshots/screenshot-11.webp similarity index 100% rename from demo/demo11.webp rename to screenshots/screenshot-11.webp diff --git a/demo/demo12.webp b/screenshots/screenshot-12.webp similarity index 100% rename from demo/demo12.webp rename to screenshots/screenshot-12.webp diff --git a/demo/demo13.webp b/screenshots/screenshot-13.webp similarity index 100% rename from demo/demo13.webp rename to screenshots/screenshot-13.webp diff --git a/demo/demo14.webp b/screenshots/screenshot-14.webp similarity index 100% rename from demo/demo14.webp rename to screenshots/screenshot-14.webp diff --git a/demo/demo15.webp b/screenshots/screenshot-15.webp similarity index 100% rename from demo/demo15.webp rename to screenshots/screenshot-15.webp diff --git a/demo/demo16.webp b/screenshots/screenshot-16.webp similarity index 100% rename from demo/demo16.webp rename to screenshots/screenshot-16.webp diff --git a/demo/demo17.webp b/screenshots/screenshot-17.webp similarity index 100% rename from demo/demo17.webp rename to screenshots/screenshot-17.webp diff --git a/demo/demo18.webp b/screenshots/screenshot-18.webp similarity index 100% rename from demo/demo18.webp rename to screenshots/screenshot-18.webp diff --git a/demo/demo19.webp b/screenshots/screenshot-19.webp similarity index 100% rename from demo/demo19.webp rename to screenshots/screenshot-19.webp diff --git a/demo/demo2.webp b/screenshots/screenshot-2.webp similarity index 100% rename from demo/demo2.webp rename to screenshots/screenshot-2.webp diff --git a/demo/demo20.webp b/screenshots/screenshot-20.webp similarity index 100% rename from demo/demo20.webp rename to screenshots/screenshot-20.webp diff --git a/demo/demo21.webp b/screenshots/screenshot-21.webp similarity index 100% rename from demo/demo21.webp rename to screenshots/screenshot-21.webp diff --git a/demo/demo22.webp b/screenshots/screenshot-22.webp similarity index 100% rename from demo/demo22.webp rename to screenshots/screenshot-22.webp diff --git a/demo/demo23.webp b/screenshots/screenshot-23.webp similarity index 100% rename from demo/demo23.webp rename to screenshots/screenshot-23.webp diff --git a/demo/demo3.webp b/screenshots/screenshot-3.webp similarity index 100% rename from demo/demo3.webp rename to screenshots/screenshot-3.webp diff --git a/demo/demo4.webp b/screenshots/screenshot-4.webp similarity index 100% rename from demo/demo4.webp rename to screenshots/screenshot-4.webp diff --git a/demo/demo5.webp b/screenshots/screenshot-5.webp similarity index 100% rename from demo/demo5.webp rename to screenshots/screenshot-5.webp diff --git a/demo/demo6.webp b/screenshots/screenshot-6.webp similarity index 100% rename from demo/demo6.webp rename to screenshots/screenshot-6.webp diff --git a/demo/demo7.webp b/screenshots/screenshot-7.webp similarity index 100% rename from demo/demo7.webp rename to screenshots/screenshot-7.webp diff --git a/demo/demo8.webp b/screenshots/screenshot-8.webp similarity index 100% rename from demo/demo8.webp rename to screenshots/screenshot-8.webp diff --git a/demo/demo9.webp b/screenshots/screenshot-9.webp similarity index 100% rename from demo/demo9.webp rename to screenshots/screenshot-9.webp diff --git a/source/component/plant.py b/source/component/plant.py index 3c75f04..c93fbcc 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -5,7 +5,7 @@ from .. import constants as c class Car(pg.sprite.Sprite): - def __init__(self, x, y, map_y): + def __init__(self, x:int, y:int, map_y:int): pg.sprite.Sprite.__init__(self) rect = tool.GFX[c.CAR].get_rect() @@ -19,7 +19,7 @@ class Car(pg.sprite.Sprite): self.state = c.IDLE self.dead = False - def update(self, game_info): + def update(self, game_info:dict): self.current_time = game_info[c.CURRENT_TIME] if self.state == c.WALK: self.rect.x += 5 @@ -37,9 +37,9 @@ class Car(pg.sprite.Sprite): # 豌豆及孢子类普通子弹 class Bullet(pg.sprite.Sprite): - def __init__( self, x, start_y, dest_y, name, damage, - effect=None, passed_torchwood_x=None, - damage_type=c.ZOMBIE_DEAFULT_DAMAGE): + def __init__( self, x:int, start_y:int, dest_y:int, name:str, damage:int, + effect:str=None, passed_torchwood_x:int=None, + damage_type:str=c.ZOMBIE_DEAFULT_DAMAGE): pg.sprite.Sprite.__init__(self) self.name = name diff --git a/source/state/mainmenu.py b/source/state/mainmenu.py index 1da7f3b..1fb8e9d 100644 --- a/source/state/mainmenu.py +++ b/source/state/mainmenu.py @@ -8,7 +8,7 @@ class Menu(tool.State): def __init__(self): tool.State.__init__(self) - def startup(self, current_time, persist): + def startup(self, current_time:int, persist): self.next = c.LEVEL self.persist = persist self.game_info = persist @@ -88,7 +88,7 @@ class Menu(tool.State): self.adventure_clicked = False self.option_button_clicked = False - def checkHilight(self, x, y): + def checkHilight(self, x:int, y:int): # 高亮冒险模式按钮 if self.inArea(self.adventure_rect, x, y): self.adventure_highlight_time = self.current_time @@ -112,7 +112,7 @@ class Menu(tool.State): self.littleGame_image = self.chooseHilightImage(self.littleGame_highlight_time, self.littleGame_frames) self.help_image = self.chooseHilightImage(self.help_hilight_time, self.help_frames) - def chooseHilightImage(self, hilightTime, frames): + def chooseHilightImage(self, hilightTime:int, frames): if (self.current_time - hilightTime) < 80: index= 1 else: @@ -206,7 +206,7 @@ class Menu(tool.State): self.sunflower_trophy_rect.y = 280 self.sunflower_trophy_show_info_time = 0 - def checkSunflowerTrophyInfo(self, surface, x, y): + def checkSunflowerTrophyInfo(self, surface:pg.Surface, x:int, y:int): if self.inArea(self.sunflower_trophy_rect, x, y): self.sunflower_trophy_show_info_time = self.current_time if (self.current_time - self.sunflower_trophy_show_info_time) < 80: @@ -228,7 +228,7 @@ class Menu(tool.State): # 播放点击音效 c.SOUND_BUTTON_CLICK.play() - def showCurrentVolumeImage(self, surface): + def showCurrentVolumeImage(self, surface:pg.Surface): # 由于音量可变,因此这一内容不能在一开始就结束加载,而应当不断刷新不断显示 font = pg.font.Font(c.FONT_PATH, 30) volume_tips = font.render(f"音量:{round(self.game_info[c.SOUND_VOLUME]*100):3}%", True, c.LIGHTGRAY) @@ -237,7 +237,7 @@ class Menu(tool.State): volume_tips_rect.y = 247 surface.blit(volume_tips, volume_tips_rect) - def update(self, surface, current_time, mouse_pos, mouse_click): + def update(self, surface:pg.Surface, current_time:int, mouse_pos:list, mouse_click): self.current_time = self.game_info[c.CURRENT_TIME] = current_time surface.blit(self.bg_image, self.bg_rect) diff --git a/source/tool.py b/source/tool.py index 30b6dc6..e68f99b 100755 --- a/source/tool.py +++ b/source/tool.py @@ -18,7 +18,7 @@ class State(): # 当从其他状态进入这个状态时,需要进行的初始化操作 @abstractmethod - def startup(self, current_time, persist): + def startup(self, current_time:int, persist:dict): # 前面加了@abstractmethod表示抽象基类中必须要重新定义的method(method是对象和函数的结合) pass # 当从这个状态退出时,需要进行的清除操作 @@ -27,12 +27,12 @@ class State(): return self.persist # 在这个状态运行时进行的更新操作 @abstractmethod - def update(self, surface, keys, current_time): + def update(self, surface:pg.Surface, keys, current_time:int): # 前面加了@abstractmethod表示抽象基类中必须要重新定义的method pass # 工具:范围判断函数,用于判断点击 - def inArea(self, rect, x, y): + def inArea(self, rect:pg.Rect, x:int, y:int): if (rect.x <= x <= rect.right and rect.y <= y <= rect.bottom): return True @@ -101,7 +101,7 @@ class Control(): f.write(savedata) self.game_info = c.INIT_USERDATA.copy() # 内部全是不可变对象,浅拷贝即可 - def setup_states(self, state_dict, start_state): + def setup_states(self, state_dict:dict, start_state): self.state_dict = state_dict self.state_name = start_state self.state = self.state_dict[self.state_name] @@ -155,7 +155,8 @@ class Control(): pg.display.update() self.clock.tick(self.fps) -def get_image(sheet, x, y, width, height, colorkey=c.BLACK, scale=1): +def get_image( sheet:pg.Surface, x:int, y:int, width:int, height:int, + colorkey:tuple[int]=c.BLACK, scale:int=1) -> pg.Surface: # 不保留alpha通道的图片导入 image = pg.Surface([width, height]) rect = image.get_rect() @@ -168,19 +169,21 @@ def get_image(sheet, x, y, width, height, colorkey=c.BLACK, scale=1): int(rect.height*scale))) return image -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() +def get_image_alpha(sheet:pg.Surface, x:int, y:int, width:int, height:int, + colorkey:tuple[int]=c.BLACK, scale:int=1) -> pg.Surface: + # 保留alpha通道的图片导入 + image = pg.Surface([width, height], SRCALPHA) + rect = image.get_rect() - image.blit(sheet, (0, 0), (x, y, width, height)) - image.set_colorkey(colorkey) - image = pg.transform.scale(image, - (int(rect.width*scale), - int(rect.height*scale))) - return image + image.blit(sheet, (0, 0), (x, y, width, height)) + image.set_colorkey(colorkey) + image = pg.transform.scale(image, + (int(rect.width*scale), + int(rect.height*scale))) + return image -def load_image_frames(directory, image_name, colorkey, accept): +def load_image_frames( directory:str, image_name:str, + colorkey:tuple[int], accept:tuple[str]) -> list[pg.Surface]: frame_list = [] tmp = {} # image_name is "Peashooter", pic name is "Peashooter_1", get the index 1 @@ -204,7 +207,8 @@ def load_image_frames(directory, image_name, colorkey, accept): return frame_list # colorkeys 是设置图像中的某个颜色值为透明,这里用来消除白边 -def load_all_gfx(directory, colorkey=c.WHITE, accept=(".png", ".jpg", ".bmp", ".gif", ".webp")): +def load_all_gfx( directory:str, colorkey:tuple[int]=c.WHITE, + accept:tuple[str]=(".png", ".jpg", ".bmp", ".gif", ".webp")) -> dict[str:pg.Surface]: graphics = {} for name1 in os.listdir(directory): # subfolders under the folder resources\graphics