版权声明:原创不易,本文禁止抄袭、转载,侵权必究!
因为历届冬奥会的会徽被外星人窃取了,英雄(冰墩墩或雪容融)临危受命,去夺会会徽,在太空站(导航,追踪等功能)的帮助下,由此踏上冰雪英雄会的路,当集齐完24枚会徽,英雄冰墩墩和雪容融成功会师,此次任务圆满结束,冰墩墩或雪容融光荣返回北京冬奥会。但冰雪英雄的故事远远没有结束……这样让玩家在玩游戏的时候能了解冬奥会的历史
主要功能如下:
基本功能如下,仅展示部分代码:
huihui_images = []
for i in range(1,25):
huihui_images_dir = path.join(img_dir,'{}.jpg'.format(i))
huihui_image = pygame.image.load(huihui_images_dir).convert()
huihui_images.append(huihui_image)
def show_beign_menu():
menu = pygame_menu.Menu(600,
800,
'Welcome',
theme=pygame_menu.themes.THEME_ORANGE)
# menu.add_text_input('Player', default='John')
menu.add_selector('Hero', [('Bing dundun', 1), ('Xue rongrong', 2)],
onchange=set_difficulty)
menu.add_selector('Difficulty', [('Easy', 1), ('Hard', 2)],
onchange=set_difficulty)
menu.add_button('Play', main)
menu.add_button('Quit', pygame_menu.events.EXIT)
menu.add_button('About')
menu.mainloop(screen)
img_dir = path.join(path.dirname(__file__),'img')
background_dir = path.join(img_dir,'space.png')
background_img1 = pygame.image.load(background_dir).convert()
background_img2 = pygame.image.load(background_dir).convert()
background_img3 = pygame.image.load('img/lantian.jpg').convert()
background_rect = background_img1.get_rect()
player_dir = path.join(img_dir,'hero_bingdundun.jpg')
player_img = pygame.image.load(player_dir).convert()
player_img_small = pygame.transform.scale(player_img,(35,40))
player_img_small.set_colorkey((0,0,0))
hits = pygame.sprite.spritecollide(player,powerups,True)
for hit in hits:
if hit.type == 'add_hp':
player.hp += 50
if player.hp > 100:
player.hp = 100
elif hit.type == 'add_life':
player.lives += 1
if player.lives > 3:
player.lives = 3
else:
player.fire_missile()
hits = pygame.sprite.spritecollide(player,huihuis,True)
for hit in hits:
player.huihui += 1
if player.huihui == 24:
game_over == True
show_success_menu()
def draw_ui():
pygame.draw.rect(screen,(0,255,0),(10,10,player.hp,15))
if player.hp < 50:
pygame.draw.rect(screen,(255,0,0),(10,10,player.hp,15))
pygame.draw.rect(screen,(255,255,255),(10,10,100,15),2)
# draw_text('scores:' + str(player.score),screen,(0,255,0),20,WIDTH/2,10)
draw_text('会徽:' + str(player.huihui),screen,(0,255,0),20,WIDTH/2,10)
img_rect = player_img_small.get_rect()
img_rect.right = WIDTH - 10
img_rect.top = 10
for _ in range(player.lives):
screen.blit(player_img_small,img_rect)
img_rect.x -= img_rect.width + 10
class Dynamic_Background1(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.transform.flip(background_img1,False,False)
self.rect = self.image.get_rect()
self.speed = 3
self.last_time = pygame.time.get_ticks()
def update(self):
now = pygame.time.get_ticks()
if now - self.last_time > 5:
self.rect.y += self.speed
self.last_time = now
while self.rect.y >= HEIGHT:
self.rect.y = -self.rect.height
dynamic_background2.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over == True
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_ESCAPE:
game_over == True
screen.blit(dynamic_background1.image,dynamic_background1.rect)
screen.blit(dynamic_background2.image,dynamic_background2.rect)
screen.blit(player.image,player.rect)
screen.blit(spaceship_zhan_shiwu.image,spaceship_zhan_shiwu.rect)
# screen.blit(space_plant_entity.image,space_plant_entity.rect)
enemys.draw(screen)
xuehuas.draw(screen)
bullets.draw(screen)
missiles.draw(screen)
explosions.draw(screen)
powerups.draw(screen)
huihuis.draw(screen)
spaceships.draw(screen)
spaceship_bullets.draw(screen)
explosion_animation = []
for i in range(9):
explosion_dir = path.join(img_dir,'regularExplosion0{}.png'.format(i))
explosion_img = pygame.image.load(explosion_dir).convert()
explosion_animation.append(explosion_img)
if self.hidden and now - self.hide_time > 1000:
self.hidden = False
self.rect.bottom = HEIGHT
self.hp = 100
if self.hp < 50:
pygame.draw.rect(screen,(255,0,0),(10,10,player.hp,15))
if self.is_missile_firing:
if now - self.start_missile_time <= MISSILE_LIFETIME:
if now - self.last_missile_time > MISSILE_INTERVAL:
missile = Missile(self.rect.center)
missiles.add(missile)
self.last_missile_time = now
else:
self.is_missile_firing = False
pygame游戏开发源码下载:
原创不易,如果觉得有点用,希望可以随手点个赞,拜谢各位老铁!
作者:小鸿的摸鱼日常,Goal:让编程更有趣!
原创微信公众号:『小鸿星空科技』,专注于算法、爬虫,网站,游戏开发,数据分析、自然语言处理,AI等,期待你的关注,让我们一起成长、一起Coding!
版权说明:本文禁止抄袭、转载 ,侵权必究!