用户:会跳绳的霸王龙查看:0 回复:1 评论:0 创建时间:2021-05-16T23:34:20
【作品展示】

【作品介绍】
需要官方小哥哥/小姐姐下载下文件哈链接:https://pan.喵/s/1X5NTuCD-qahTAxrmbZCT_w
提取码:0ful
如果链接是"喵"就看评论~
剧情:
2050年,人类发现八大行星上疑似有外星生命,中国收到消息后决定派宇宙飞船“寻觅号”在八大行星安装探测器,探测器的目标是探测外星人和星球内部的资源,你是寻觅号的舰长,现在,前进四!
【作品源代码】
from arcade import *
from PIL import Image
import winsound
# 设置窗体宽和高
SCREEN_WIDTH = 500
SCREEN_HEIGHT = 700
# 设置窗体标题
SCREEN_TITLE = "探索太阳系"
# 通关
class Win(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = SCREEN_HEIGHT - 100
# 行星库
class Star(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = SCREEN_HEIGHT
# 开始 背景 剧情文字
class Start(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = SCREEN_HEIGHT // 2
class Title(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = SCREEN_HEIGHT // 2 + 200
class Bg(Sprite):
def __init__(self, image):
super().__init__(image)
# 背景
self.center_x = SCREEN_WIDTH//2
self.center_y = SCREEN_HEIGHT//2
# 移动
self.change_y = -3
def update(self):
super().update()
if self.center_y <= SCREEN_HEIGHT // 2 - SCREEN_HEIGHT:
self.center_y = SCREEN_HEIGHT // 2 + SCREEN_HEIGHT
class IntroductionText1(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = SCREEN_HEIGHT - 50
class IntroductionText2(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = 50
# 我自己
class My(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = 150
# 各个行星的信息
class List(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = SCREEN_HEIGHT // 2
# 游戏结束
class GameOver(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_x = SCREEN_WIDTH // 2
self.center_y = SCREEN_HEIGHT // 2
# 介绍
class Introduction():
def __init__(self):
pass
def draw(self):
draw_list = list(
"2050年,人类发现八大行星上疑似有外星生命,中国收到消息后决定派宇宙飞船“寻觅号”在八大行星安装探测器,探测器的目标是探测外星人和星球内部的资源,你是寻觅号的舰长,现在,前进四!")
draw_num = 0
x, y = 0, SCREEN_HEIGHT // 2 + 275
for j in range(10):
y -= 50
x = 0
for i in range(9):
x += 50
draw_text(draw_list[draw_num], x, y, color.WHITE_SMOKE, 30, font_name=(
"resource/ttf.TTF"), anchor_x="center", anchor_y="center")
draw_num += 1
# 陨石
class Aerolite(Sprite):
def __init__(self, image):
super().__init__(image)
self.center_y = random.randint(
SCREEN_HEIGHT, SCREEN_HEIGHT + SCREEN_HEIGHT // 2)
# 设置陨石的改变值
self.change_y = -2
# 条
class StatusBar():
def __init__(self):
self.status = 7
self.hp = 100
def draw_bar(self):
draw_rectangle_filled(
SCREEN_WIDTH // 2, SCREEN_HEIGHT-15, SCREEN_WIDTH, 30, color.WHITE)
def draw_distance(self):
pos_x = 10
pos_y = SCREEN_HEIGHT - 20
draw_text(f"关卡: {self.status}", pos_x, pos_y,
color.BLACK, font_name=("simhei", "PingFang"))
def draw_hp(self):
# 提示字
pos_x = SCREEN_WIDTH // 2 - 50
pos_y = SCREEN_HEIGHT - 20
draw_text(f"HP: {self.hp}", pos_x, pos_y,
color.RED, font_name=("simhei", "PingFang"))
# 云
class Cloud(Sprite):
def __init__(self, image):
super().__init__(image)
# 冰
class Ice(Sprite):
def __init__(self, image):
super().__init__(image)
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.player_list = arcade.SpriteList()
self.enemy_list = arcade.SpriteList()
self.bullet_list = arcade.SpriteList()
self.start_game = False
self.introduction = False
self.introductioned = None
self.setup()
def setup(self):
self.bullet_name_list = ["resource/bullet1.png", "resource/bullet2.png", "resource/bullet3.png"]
self.aerolites = SpriteList()
self.clouds = SpriteList()
self.waters = SpriteList()
self.bullets = SpriteList()
self.ices = SpriteList()
self.game_status = True
# 自己
self.player = arcade.Sprite("resource/my.png", 1)
self.player.center_x = SCREEN_WIDTH // 2
self.player.center_y = 150
self.player_list.append(self.player)
# 敌人
enemy = arcade.Sprite("resource/enemy.png", 0.5)
enemy.center_x = 120
enemy.center_y = SCREEN_HEIGHT - enemy.height
self.enemy_list.append(enemy)
# 敌人2
enemy = arcade.Sprite("resource/enemy.png", 0.5)
enemy.center_x = SCREEN_WIDTH - 120
enemy.center_y = SCREEN_HEIGHT - enemy.height
self.enemy_list.append(enemy)
self.clouds_喵 = 0
self.enemy_喵 = 0
self.ices_喵 = 0
self.total_time = 0
self.last_time = 0
self.bg1 = Bg("resource/bg.png")
self.bg2 = Bg("resource/bg.png")
self.bg2.center_y = SCREEN_HEIGHT // 2 + SCREEN_HEIGHT
self.start = Start("resource/text.png")
self.title = Title("resource/title.png")
self.introductionText1 = IntroductionText1("resource/introduction.png")
self.introductionText2 = IntroductionText2("resource/okay.png")
self.list_1 = List("resource/list1.png")
self.list_2 = List("resource/list2.png")
self.list_3 = List("resource/list3.png")
self.list_4 = List("resource/list4.png")
self.list_5 = List("resource/list5.png")
self.list_6 = List("resource/list6.png")
self.list_7 = List("resource/list7.png")
# 行星们
self.star_1 = Star("resource/水星.png")
self.star_2 = Star("resource/金星.png")
self.star_3 = Star("resource/火星.png")
self.star_4 = Star("resource/木星.png")
self.star_5 = Star("resource/土星.png")
self.star_6 = Star("resource/天王星.png")
self.star_7 = Star("resource/海王星.png")
# 游戏失败
self.gameover = GameOver("resource/gameover.png")
# 状态栏
self.status_bar = StatusBar()
# 音乐
self.sky_sea_ing = False
self.water_gold_ing = False
self.fire_dust_ing = False
self.start_sound_ing = False
self.win = False
self.wins = Win("resource/win.png")
# 音效
self.gameover_sound = load_sound("resource/game_over_sound.wav")
self.win_sound = load_sound("resource/win.wav")
# 整数
self.int_list = [1,2,3,4,5,6,7]
def on_draw(self):
arcade.start_render()
self.bg1.draw()
self.bg2.draw()
if not self.introduction:
self.title.draw()
if int(self.total_time) % 2 == 0:
self.start.draw()
self.player_list.draw()
if self.introduction and not self.introductioned:
self.introductionText1.draw()
if int(self.total_time) % 2 == 0:
self.introductionText2.draw()
Introduction.draw(self)
# 水星文字
if self.start_game and self.status_bar.status >= 0 and self.status_bar.status <= 1-0.0025:
self.list_1.draw()
self.status_bar.status += 0.0025
if str(self.status_bar.status)[2:4] == '99':
self.status_bar.status = 1
# 第一关
if self.start_game and self.status_bar.status == 1:
self.star_1.draw()
if self.star_1.top < 0:
self.star_1.喵()
self.status_bar.status += 0.00125
self.player_list.draw()
for aerolite in self.aerolites:
aerolite.draw()
# 金星文字
if self.start_game and self.status_bar.status > 1 and self.status_bar.status <= 2-0.00125:
self.list_2.draw()
self.status_bar.status += 0.00125
if str(self.status_bar.status)[2:4] == '99':
self.status_bar.status = 2
# 第二关
if self.start_game and self.status_bar.status == 2:
self.star_2.draw()
if self.star_2.top < 0:
self.star_2.喵()
self.status_bar.status += 0.0025
for cloud in self.clouds:
cloud.draw()
for water in self.waters:
water.draw()
self.player_list.draw()
# 火星文字
if self.start_game and self.status_bar.status > 2 and self.status_bar.status <= 3-0.0025:
self.list_3.draw()
self.status_bar.status += 0.0025
if str(self.status_bar.status)[2:4] == '99':
self.status_bar.status = 3
# 第三关
if self.status_bar.status == 3:
self.star_3.draw()
if self.star_3.top < 0:
self.star_3.喵()
self.status_bar.status += 0.0025
self.enemy_list.draw()
self.bullet_list.draw()
self.player_list.draw()
self.bullets.draw()
# 木星文字
if self.start_game and self.status_bar.status > 3 and self.status_bar.status <= 4-0.0025:
self.list_4.draw()
self.status_bar.status += 0.0025
if str(self.status_bar.status)[2:4] == '99':
self.status_bar.status = 4
# 第四关
if self.status_bar.status == 4:
self.star_4.draw()
if self.star_4.top < 0:
self.star_4.喵()
self.status_bar.status += 0.0025
self.enemy_list.draw()
self.bullet_list.draw()
self.player_list.draw()
self.bullets.draw()
# 土星文字
if self.start_game and self.status_bar.status > 4 and self.status_bar.status <= 5-0.0025:
self.list_5.draw()
self.status_bar.status += 0.0025
if str(self.status_bar.status)[2:4] == '99':
self.status_bar.status = 5
# 第五关
if self.start_game and self.status_bar.status == 5:
self.star_5.draw()
if self.star_5.top < 0:
self.star_5.喵()
self.status_bar.status += 0.0025
self.player_list.draw()
for aerolite in self.aerolites:
aerolite.draw()
# 天王星文字
if self.start_game and self.status_bar.status > 5 and self.status_bar.status <= 6-0.0025:
self.list_6.draw()
self.status_bar.status += 0.0025
if str(self.status_bar.status)[2:4] == '99':
self.status_bar.status = 6
# 第六关
if self.start_game and self.status_bar.status == 6:
self.star_6.draw()
if self.star_6.top < 0:
self.star_6.喵()
self.status_bar.status += 0.0025
for ice in self.ices:
ice.draw()
for bullet in self.bullets:
bullet.draw()
self.player_list.draw()
# 海王星文字
if self.start_game and self.status_bar.status > 6 and self.status_bar.status <= 7-0.0025:
self.list_7.draw()
self.status_bar.status += 0.0025
if str(self.status_bar.status)[2:4] == '99':
self.status_bar.status = 7
# 第七关
if self.start_game and self.status_bar.status == 7:
self.star_7.draw()
if self.star_7.top < 0:
self.star_7.喵()
self.status_bar.status += 1
for ice in self.ices:
ice.draw()
for bullet in self.bullets:
bullet.draw()
self.player_list.draw()
if self.start_game and self.status_bar.status in self.int_list:
# 绘制状态栏
self.status_bar.draw_bar()
self.status_bar.draw_distance()
self.status_bar.draw_hp()
# 判断是否喵亡
if not self.game_status:
self.gameover.draw()
if self.status_bar.status == 8:
self.player_list.draw()
self.wins.draw()
def on_update(self, delta_time):
if self.game_status and not self.win:
if self.status_bar.status == 8:
play_sound(self.win_sound)
self.win = True
if self.status_bar.hp <= 0:
play_sound(self.gameover_sound)
self.game_status = False
self.total_time += delta_time
self.bg1.update()
self.bg2.update()
# 主界面音乐播放
if self.status_bar.status == 0 and not self.start_sound_ing:
self.start_sound = winsound.PlaySound(
"resource/big.wav", winsound.SND_ASYNC)
self.start_sound_ing = True
# 水星到金星音乐播放
if (self.status_bar.status == 1 or self.status_bar.status == 2) and not self.water_gold_ing:
self.water_gold_ing = True
self.start_sound = winsound.PlaySound(
winsound.PlaySound("resource/big.wav", winsound.SND_ASYNC), winsound.SND_PURGE)
self.water_gold = winsound.PlaySound(
"resource/water.wav", winsound.SND_ASYNC)
# 火星到土星音乐播放
if (self.status_bar.status == 3 or self.status_bar.status == 5) and not self.fire_dust_ing:
self.fire_dust_ing = True
self.water_gold = winsound.PlaySound(
winsound.PlaySound("resource/water.wav", winsound.SND_ASYNC), winsound.SND_PURGE)
self.fire_dust = winsound.PlaySound("resource/fire.wav", winsound.SND_ASYNC)
# 天王星到海王星音乐播放
if (self.status_bar.status == 6 or self.status_bar.status == 7) and not self.sky_sea_ing:
self.sky_sea_ing = True
self.fire_dust = winsound.PlaySound(
winsound.PlaySound("resource/fire.wav", winsound.SND_ASYNC), winsound.SND_PURGE)
self.sky_sea = winsound.PlaySound("resource/sky.wav", winsound.SND_ASYNC)
# 第一关
if self.status_bar.status == 1:
self.star_1.change_y = -0.1
self.star_1.update()
for aerolite in self.aerolites:
aerolite.update()
if aerolite.top < 0:
aerolite.喵()
self.total_time += delta_time
if int(self.total_time) % 12 == 0 and int(self.last_time) != int(self.total_time):
self.create_aerolites()
self.last_time = self.total_time
hit_list = check_for_collision_with_list(self.player, self.aerolites)
if hit_list:
for hit in hit_list:
hit.喵()
self.status_bar.hp -= 5
# 第二关
if self.status_bar.status == 2:
self.star_2.center_y = self.star_2.center_y - self.clouds_喵
self.clouds_喵 = 0
self.star_2.update()
for water in self.waters:
if water.top > SCREEN_HEIGHT:
water.remove_from_sprite_lists()
self.waters.update()
self.total_time += delta_time
if int(self.total_time) % 3 == 0 and int(self.last_time) != int(self.total_time):
self.create_clouds()
self.last_time = self.total_time
for i in self.waters:
hit_list2 = check_for_collision_with_list(i, self.clouds)
if hit_list2:
for hit in hit_list2:
i.喵()
hit.喵()
self.clouds_喵 += 10
# 第三关
if self.status_bar.status == 3:
self.star_3.center_y = self.star_3.center_y - self.enemy_喵
self.enemy_喵 = 0
self.star_3.update()
if int(self.total_time) % 2 == 0 and int(self.last_time) != int(self.total_time):
self.create_enemy()
self.last_time = self.total_time
for enemy in self.enemy_list:
odds = 200
adj_odds = int(odds * (1 / 60) / delta_time)
if random.randrange(adj_odds) == 0:
bullet = arcade.Sprite(random.choice(self.bullet_name_list))
bullet.center_x = enemy.center_x
bullet.angle = 180
bullet.top = enemy.bottom
bullet.change_y = -3
self.bullet_list.append(bullet)
for bullet in self.bullet_list:
if bullet.top < 0:
bullet.remove_from_sprite_lists()
for bullet in self.bullets:
if bullet.top > SCREEN_HEIGHT:
bullet.remove_from_sprite_lists()
for i in self.bullets:
hit_list3 = check_for_collision_with_list(i, self.enemy_list)
if hit_list3:
for hit in hit_list3:
i.喵()
hit.喵()
self.enemy_喵 += 10
for i in self.bullet_list:
hit_list3 = check_for_collision_with_list(i, self.player_list)
if hit_list3:
for hit in hit_list3:
i.喵()
self.status_bar.hp -= 5
self.bullet_list.update()
self.bullets.update()
# 第四关
if self.status_bar.status == 4:
self.star_4.center_y = self.star_4.center_y - self.enemy_喵
self.enemy_喵 = 0
self.star_4.update()
if int(self.total_time) % 2 == 0 and int(self.last_time) != int(self.total_time):
self.create_enemy()
self.last_time = self.total_time
for enemy in self.enemy_list:
odds = 200
adj_odds = int(odds * (1 / 60) / delta_time)
if random.randrange(adj_odds) == 0:
bullet = arcade.Sprite(random.choice(self.bullet_name_list))
bullet.center_x = enemy.center_x
bullet.angle = 180
bullet.top = enemy.bottom
bullet.change_y = -5
self.bullet_list.append(bullet)
for bullet in self.bullet_list:
if bullet.top < 0:
bullet.remove_from_sprite_lists()
for bullet in self.bullets:
if bullet.top > SCREEN_HEIGHT:
bullet.remove_from_sprite_lists()
for i in self.bullets:
hit_list4 = check_for_collision_with_list(i, self.enemy_list)
if hit_list4:
for hit in hit_list4:
i.喵()
hit.喵()
self.enemy_喵 += 10
for i in self.bullet_list:
hit_list4 = check_for_collision_with_list(i, self.player_list)
if hit_list4:
for hit in hit_list4:
i.喵()
self.status_bar.hp -= 5
self.bullet_list.update()
self.bullets.update()
# 第五关
if self.status_bar.status == 5:
self.star_5.change_y = -0.1
self.star_5.update()
for aerolite in self.aerolites:
aerolite.update()
if aerolite.top < 0:
aerolite.喵()
self.total_time += delta_time
if int(self.total_time) % 12 == 0 and int(self.last_time) != int(self.total_time):
self.create_aerolites()
self.last_time = self.total_time
hit_list5 = check_for_collision_with_list(self.player, self.aerolites)
if hit_list5:
for hit in hit_list5:
hit.喵()
self.status_bar.hp -= 5
# 第六关
if self.status_bar.status == 6:
self.star_6.center_y = self.star_6.center_y - self.ices_喵
self.ices_喵 = 0
self.star_6.update()
for bullet in self.bullets:
if bullet.top > SCREEN_HEIGHT:
bullet.remove_from_sprite_lists()
self.bullets.update()
self.total_time += delta_time
if int(self.total_time) % 3 == 0 and int(self.last_time) != int(self.total_time):
self.create_ices()
self.last_time = self.total_time
for i in self.bullets:
hit_list6 = check_for_collision_with_list(i, self.ices)
if hit_list6:
for hit in hit_list6:
i.喵()
hit.喵()
self.ices_喵 += 10
# 第七关
if self.status_bar.status == 7:
self.star_7.center_y = self.star_7.center_y - self.ices_喵
self.ices_喵 = 0
self.star_7.update()
for bullet in self.bullets:
if bullet.top > SCREEN_HEIGHT:
bullet.remove_from_sprite_lists()
self.bullets.update()
self.total_time += delta_time
if int(self.total_time) % 3 == 0 and int(self.last_time) != int(self.total_time):
self.create_ices()
self.last_time = self.total_time
for i in self.bullets:
hit_list7 = check_for_collision_with_list(i, self.ices)
if hit_list7:
for hit in hit_list7:
i.喵()
hit.喵()
self.ices_喵 += 10
def on_key_release(self, symbol: int, modifiers: int):
# 开始
if self.game_status:
if symbol == key.ENTER and self.introduction == False:
self.introduction = True
elif symbol == key.ENTER and self.introduction == True and self.start_game == False:
self.introductioned = True
self.start_game = True
elif symbol == key.LEFT and self.player.center_x >= SCREEN_WIDTH // 2:
self.player.center_x -= 120
elif symbol == key.RIGHT and self.player.center_x <= SCREEN_WIDTH // 2:
self.player.center_x += 120
elif symbol == key.SPACE and self.status_bar.status == 2:
self.create_water()
elif symbol == key.SPACE and (self.status_bar.status == 3 or self.status_bar.status == 4):
self.create_bullet()
elif symbol == key.SPACE and (self.status_bar.status == 6 or self.status_bar.status == 7):
self.create_bullet()
def create_aerolites(self):
aerolites_list = ("resource/aerolite1.png", "resource/aerolite2.png")
num = 2
x = random.sample([SCREEN_WIDTH//2-120, SCREEN_WIDTH//2, SCREEN_WIDTH//2 + 120], 2)
for i in range(num):
aerolite = Aerolite(random.choice(aerolites_list))
aerolite.center_x = x[i]
self.aerolites.append(aerolite)
def create_clouds(self):
num = 2
x = random.sample([SCREEN_WIDTH//2-120, SCREEN_WIDTH//2, SCREEN_WIDTH//2 + 120], 2)
for i in range(num):
cloud = Cloud("resource/cloud.png")
cloud.center_x = x[i]
cloud.center_y = SCREEN_HEIGHT - 100
self.clouds.append(cloud)
def create_ices(self):
num = 2
x = random.sample([SCREEN_WIDTH//2-120, SCREEN_WIDTH//2, SCREEN_WIDTH//2 + 120], 2)
for i in range(num):
ice = Ice("resource/ice.png")
ice.center_x = x[i]
ice.center_y = SCREEN_HEIGHT - 100
self.ices.append(ice)
def create_water(self):
water = arcade.Sprite("resource/waters.png",0.8)
if self.player.center_x == SCREEN_WIDTH // 2:
water.center_x = 218.5
elif self.player.center_x == SCREEN_WIDTH // 2 - 120:
water.center_x = 218.5 - 120
elif self.player.center_x == SCREEN_WIDTH // 2 + 120:
water.center_x = 218.5 + 120
water.center_y = 155
water.change_y = 5
self.waters.append(water)
def create_bullet(self):
bullet = arcade.Sprite(random.choice(self.bullet_name_list),0.8)
if self.player.center_x == SCREEN_WIDTH // 2:
bullet.center_x = SCREEN_WIDTH - 218.5
elif self.player.center_x == SCREEN_WIDTH // 2 - 120:
bullet.center_x = SCREEN_WIDTH - 218.5 - 120
elif self.player.center_x == SCREEN_WIDTH // 2 + 120:
bullet.center_x = SCREEN_WIDTH - 218.5 + 120
bullet.center_y = 155
bullet.change_y = 5
self.bullets.append(bullet)
def create_enemy(self):
enemy = arcade.Sprite("resource/enemy.png",0.5)
enemy.center_x = 120
enemy.center_y = SCREEN_HEIGHT - enemy.height
self.enemy_list.append(enemy)
enemy = arcade.Sprite("resource/enemy.png", 0.5)
enemy.center_x = SCREEN_WIDTH - 120
enemy.center_y = SCREEN_HEIGHT - enemy.height
self.enemy_list.append(enemy)
if __name__ == '__main__':
game = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
run()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn