diff --git a/Plane_Fighting/__pycache__/bullet.cpython-310.pyc b/Plane_Fighting/__pycache__/bullet.cpython-310.pyc old mode 100755 new mode 100644 index 927a21a..a6cbdfd Binary files a/Plane_Fighting/__pycache__/bullet.cpython-310.pyc and b/Plane_Fighting/__pycache__/bullet.cpython-310.pyc differ diff --git a/Plane_Fighting/__pycache__/enemy.cpython-310.pyc b/Plane_Fighting/__pycache__/enemy.cpython-310.pyc old mode 100755 new mode 100644 index 838ac9f..bbe5c60 Binary files a/Plane_Fighting/__pycache__/enemy.cpython-310.pyc and b/Plane_Fighting/__pycache__/enemy.cpython-310.pyc differ diff --git a/Plane_Fighting/__pycache__/myplane.cpython-310.pyc b/Plane_Fighting/__pycache__/myplane.cpython-310.pyc old mode 100755 new mode 100644 index 72fdee6..e1a1836 Binary files a/Plane_Fighting/__pycache__/myplane.cpython-310.pyc and b/Plane_Fighting/__pycache__/myplane.cpython-310.pyc differ diff --git a/Plane_Fighting/__pycache__/supply.cpython-310.pyc b/Plane_Fighting/__pycache__/supply.cpython-310.pyc old mode 100755 new mode 100644 index d728678..bfd325b Binary files a/Plane_Fighting/__pycache__/supply.cpython-310.pyc and b/Plane_Fighting/__pycache__/supply.cpython-310.pyc differ diff --git a/Plane_Fighting/buildozer.spec b/Plane_Fighting/buildozer.spec index 8ca6ea5..665c3ea 100755 --- a/Plane_Fighting/buildozer.spec +++ b/Plane_Fighting/buildozer.spec @@ -16,7 +16,7 @@ source.dir = . source.include_exts = py,png,ogg,wav,ttf,dat # (list) List of inclusions using pattern matching -#source.include_patterns = assets/*,images/*.png +source.include_patterns = font/*,sound/*,images/*,record.dat # (list) Source files to exclude (let empty to not exclude anything) #source.exclude_exts = spec diff --git a/Plane_Fighting/bullet.py b/Plane_Fighting/bullet.py index 0ef1935..84ff6c3 100755 --- a/Plane_Fighting/bullet.py +++ b/Plane_Fighting/bullet.py @@ -1,10 +1,10 @@ -import pygame - +import pygame,os +abspath = os.getcwd() + "/" class Bullet1(pygame.sprite.Sprite): def __init__(self, position): pygame.sprite.Sprite.__init__(self) - self.image = pygame.image.load("images/bullet1.png").convert_alpha() + self.image = pygame.image.load(abspath + "images/bullet1.png").convert_alpha() self.rect = self.image.get_rect() self.rect.left, self.rect.top = position self.speed = 11 @@ -25,7 +25,7 @@ class Bullet2(pygame.sprite.Sprite): def __init__(self, position): pygame.sprite.Sprite.__init__(self) - self.image = pygame.image.load("images/bullet2.png").convert_alpha() + self.image = pygame.image.load(abspath + "images/bullet2.png").convert_alpha() self.rect = self.image.get_rect() self.rect.left, self.rect.top = position self.speed = 14#14 diff --git a/Plane_Fighting/enemy.py b/Plane_Fighting/enemy.py index aaa80b3..1ab4d9b 100755 --- a/Plane_Fighting/enemy.py +++ b/Plane_Fighting/enemy.py @@ -1,17 +1,17 @@ -import pygame +import pygame,os from random import * - +abspath = os.getcwd() + "/" class SmallEnemy(pygame.sprite.Sprite): def __init__(self, bg_size): pygame.sprite.Sprite.__init__(self) - self.image = pygame.image.load("images/enemy1.png").convert_alpha() + self.image = pygame.image.load(abspath + "images/enemy1.png").convert_alpha() self.destroy_images = [] self.destroy_images.extend([\ - pygame.image.load("images/enemy1_down1.png").convert_alpha(), \ - pygame.image.load("images/enemy1_down2.png").convert_alpha(), \ - pygame.image.load("images/enemy1_down3.png").convert_alpha(), \ - pygame.image.load("images/enemy1_down4.png").convert_alpha() \ + pygame.image.load(abspath + "images/enemy1_down1.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy1_down2.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy1_down3.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy1_down4.png").convert_alpha() \ ]) self.rect = self.image.get_rect() self.width, self.height = bg_size[0], bg_size[1] @@ -41,14 +41,14 @@ class MidEnemy(pygame.sprite.Sprite): def __init__(self, bg_size): pygame.sprite.Sprite.__init__(self) - self.image = pygame.image.load("images/enemy2.png").convert_alpha() - self.image_hit = pygame.image.load("images/enemy2_hit.png").convert_alpha() + self.image = pygame.image.load(abspath + "images/enemy2.png").convert_alpha() + self.image_hit = pygame.image.load(abspath + "images/enemy2_hit.png").convert_alpha() self.destroy_images = [] self.destroy_images.extend([\ - pygame.image.load("images/enemy2_down1.png").convert_alpha(), \ - pygame.image.load("images/enemy2_down2.png").convert_alpha(), \ - pygame.image.load("images/enemy2_down3.png").convert_alpha(), \ - pygame.image.load("images/enemy2_down4.png").convert_alpha() \ + pygame.image.load(abspath + "images/enemy2_down1.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy2_down2.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy2_down3.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy2_down4.png").convert_alpha() \ ]) self.rect = self.image.get_rect() self.width, self.height = bg_size[0], bg_size[1] @@ -81,17 +81,17 @@ class BigEnemy(pygame.sprite.Sprite): def __init__(self, bg_size): pygame.sprite.Sprite.__init__(self) - self.image1 = pygame.image.load("images/enemy3_n1.png").convert_alpha() - self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha() - self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha() + self.image1 = pygame.image.load(abspath + "images/enemy3_n1.png").convert_alpha() + self.image2 = pygame.image.load(abspath + "images/enemy3_n2.png").convert_alpha() + self.image_hit = pygame.image.load(abspath + "images/enemy3_hit.png").convert_alpha() self.destroy_images = [] self.destroy_images.extend([\ - pygame.image.load("images/enemy3_down1.png").convert_alpha(), \ - pygame.image.load("images/enemy3_down2.png").convert_alpha(), \ - pygame.image.load("images/enemy3_down3.png").convert_alpha(), \ - pygame.image.load("images/enemy3_down4.png").convert_alpha(), \ - pygame.image.load("images/enemy3_down5.png").convert_alpha(), \ - pygame.image.load("images/enemy3_down6.png").convert_alpha() \ + pygame.image.load(abspath + "images/enemy3_down1.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy3_down2.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy3_down3.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy3_down4.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy3_down5.png").convert_alpha(), \ + pygame.image.load(abspath + "images/enemy3_down6.png").convert_alpha() \ ]) self.rect = self.image1.get_rect() self.width, self.height = bg_size[0], bg_size[1] diff --git a/Plane_Fighting/main.py b/Plane_Fighting/main.py index 500991b..9716a85 100755 --- a/Plane_Fighting/main.py +++ b/Plane_Fighting/main.py @@ -7,7 +7,9 @@ import enemy import bullet import supply import time +import os +abspath = os.getcwd() + "/" from pygame.locals import * from random import * jj = 0 @@ -18,40 +20,41 @@ bg_size = width, height = 480, 700 screen = pygame.display.set_mode(bg_size) pygame.display.set_caption("Plane Fighting") key_pressed = pygame.key.get_pressed() -background=pygame.image.load("images/loading.png") #图片位置 +background=pygame.image.load(abspath + "images/loading.png") #图片位置 screen.blit(background,(0,0)) #对齐的坐标 pygame.display.update() #显示内容 -time.sleep(1) -background = pygame.image.load("images/background.png").convert() +pygame.mixer.music.load(abspath + "sound/game_music.ogg") +pygame.mixer.music.set_volume(0.1) +pygame.mixer.music.play(-1) +time.sleep(7.5) +background = pygame.image.load(abspath + "images/background.png").convert() BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) # 载入游戏音乐 -pygame.mixer.music.load("sound/game_music.ogg") -pygame.mixer.music.set_volume(0.1) -bullet_sound = pygame.mixer.Sound("sound/bullet.wav") +bullet_sound = pygame.mixer.Sound(abspath + "sound/bullet.wav") bullet_sound.set_volume(0.2) -bomb_sound = pygame.mixer.Sound("sound/use_bomb.wav") +bomb_sound = pygame.mixer.Sound(abspath + "sound/use_bomb.wav") bomb_sound.set_volume(0.2) -supply_sound = pygame.mixer.Sound("sound/supply.wav") +supply_sound = pygame.mixer.Sound(abspath + "sound/supply.wav") supply_sound.set_volume(0.2) -get_bomb_sound = pygame.mixer.Sound("sound/get_bomb.wav") +get_bomb_sound = pygame.mixer.Sound(abspath + "sound/get_bomb.wav") get_bomb_sound.set_volume(0.2) -get_bullet_sound = pygame.mixer.Sound("sound/get_bullet.wav") +get_bullet_sound = pygame.mixer.Sound(abspath + "sound/get_bullet.wav") get_bullet_sound.set_volume(0.2) -upgrade_sound = pygame.mixer.Sound("sound/upgrade.wav") +upgrade_sound = pygame.mixer.Sound(abspath + "sound/upgrade.wav") upgrade_sound.set_volume(0.2) -enemy3_fly_sound = pygame.mixer.Sound("sound/enemy3_flying.wav") +enemy3_fly_sound = pygame.mixer.Sound(abspath + "sound/enemy3_flying.wav") enemy3_fly_sound.set_volume(0.2) -enemy1_down_sound = pygame.mixer.Sound("sound/enemy1_down.wav") +enemy1_down_sound = pygame.mixer.Sound(abspath + "sound/enemy1_down.wav") enemy1_down_sound.set_volume(0.2) -enemy2_down_sound = pygame.mixer.Sound("sound/enemy2_down.wav") +enemy2_down_sound = pygame.mixer.Sound(abspath + "sound/enemy2_down.wav") enemy2_down_sound.set_volume(0.2) -enemy3_down_sound = pygame.mixer.Sound("sound/enemy3_down.wav") +enemy3_down_sound = pygame.mixer.Sound(abspath + "sound/enemy3_down.wav") enemy3_down_sound.set_volume(0.5) -me_down_sound = pygame.mixer.Sound("sound/me_down.wav") +me_down_sound = pygame.mixer.Sound(abspath + "sound/me_down.wav") @@ -82,7 +85,6 @@ def main(): me = myplane.MyPlane(bg_size) enemies = pygame.sprite.Group() - pygame.mixer.music.play(-1) # Enemy Level 1 @@ -122,14 +124,14 @@ def main(): # 统计得分 score = 0 - score_font = pygame.font.Font("font/font.ttf", 36) + score_font = pygame.font.Font(abspath + "font/font.ttf", 36) # 标志是否暂停游戏 paused = False - pause_nor_image = pygame.image.load("images/pause_nor.png").convert_alpha() - pause_pressed_image = pygame.image.load("images/pause_pressed.png").convert_alpha() - resume_nor_image = pygame.image.load("images/resume_nor.png").convert_alpha() - resume_pressed_image = pygame.image.load("images/resume_pressed.png").convert_alpha() + pause_nor_image = pygame.image.load(abspath + "images/pause_nor.png").convert_alpha() + pause_pressed_image = pygame.image.load(abspath + "images/pause_pressed.png").convert_alpha() + resume_nor_image = pygame.image.load(abspath + "images/resume_nor.png").convert_alpha() + resume_pressed_image = pygame.image.load(abspath + "images/resume_pressed.png").convert_alpha() paused_rect = pause_nor_image.get_rect() paused_rect.left, paused_rect.top = width - paused_rect.width - 10, 10 paused_image = pause_nor_image @@ -138,9 +140,9 @@ def main(): level = 1 # 全屏炸弹 - bomb_image = pygame.image.load("images/bomb.png").convert_alpha() + bomb_image = pygame.image.load(abspath + "images/bomb.png").convert_alpha() bomb_rect = bomb_image.get_rect() - bomb_font = pygame.font.Font("font/font.ttf", 48) + bomb_font = pygame.font.Font(abspath + "font/font.ttf", 48) bomb_num = 3 # 每30秒发放一个补给包 @@ -161,17 +163,17 @@ def main(): # 生命数量 life_num = 3 - life_image = pygame.image.load("images/life.png").convert_alpha() + life_image = pygame.image.load(abspath + "images/life.png").convert_alpha() life_rect = life_image.get_rect() # 用于阻止重复打开记录文件 recorded = False # 游戏结束画面 - gameover_font = pygame.font.Font("font/font.ttf", 48) - again_image = pygame.image.load("images/again.png").convert_alpha() + gameover_font = pygame.font.Font(abspath + "font/font.ttf", 48) + again_image = pygame.image.load(abspath + "images/again.png").convert_alpha() again_rect = again_image.get_rect() - gameover_image = pygame.image.load("images/gameover.png").convert_alpha() + gameover_image = pygame.image.load(abspath + "images/gameover.png").convert_alpha() gameover_rect = gameover_image.get_rect() # 用于切换图片 diff --git a/Plane_Fighting/myplane.py b/Plane_Fighting/myplane.py index 9fc708f..f28bffc 100755 --- a/Plane_Fighting/myplane.py +++ b/Plane_Fighting/myplane.py @@ -1,17 +1,17 @@ -import pygame - +import pygame,os +abspath = os.getcwd() + "/" class MyPlane(pygame.sprite.Sprite): def __init__(self, bg_size): pygame.sprite.Sprite.__init__(self) - self.image1 = pygame.image.load("images/me1.png").convert_alpha() - self.image2 = pygame.image.load("images/me2.png").convert_alpha() + self.image1 = pygame.image.load(abspath + "images/me1.png").convert_alpha() + self.image2 = pygame.image.load(abspath + "images/me2.png").convert_alpha() self.destroy_images = [] self.destroy_images.extend([\ - pygame.image.load("images/me_destroy_1.png").convert_alpha(), \ - pygame.image.load("images/me_destroy_2.png").convert_alpha(), \ - pygame.image.load("images/me_destroy_3.png").convert_alpha(), \ - pygame.image.load("images/me_destroy_4.png").convert_alpha() \ + pygame.image.load(abspath + "images/me_destroy_1.png").convert_alpha(), \ + pygame.image.load(abspath + "images/me_destroy_2.png").convert_alpha(), \ + pygame.image.load(abspath + "images/me_destroy_3.png").convert_alpha(), \ + pygame.image.load(abspath + "images/me_destroy_4.png").convert_alpha() \ ]) self.rect = self.image1.get_rect() self.width, self.height = bg_size[0], bg_size[1]