导语
上班摸鱼有没有玩游戏啊!
如果没有
那你也肯定没有玩坠落的小鸟主题游戏咯~
不过没有关系
木子这就放大图给你过过眼瘾:
看看这个界面还真有app游戏软件哪味儿了!
这个可是大人小孩都可以玩的游戏哦~
真的敲简单的!只要点击空格开始然后点击空格路过管道就可以啦。
当然。。。小编基本上只能过10几个管道柱子撒!再多的不行了。
那是因为小编把速度调快了~~更有挑战性~手速慢的也可以调慢点儿撒!!
正文
游戏规则:小鸟需要顺利躲过管道,不能碰撞到,不然会显示0,更新的小鸟重新到第一关,
过多少则显示得分多少,测试下你玩游戏的反应能力叭~
环境安装部分:
import cfg
import sys
import random
import pygame
导入需要的图片素材、设置的音乐等:
def main():
screen = initGame()
# 加载必要的游戏资源
# --导入音频
sounds = dict()
for key, value in cfg.AUDIO_PATHS.items():
sounds[key] = pygame.mixer.Sound(value)
# --导入数字图片
number_images = dict()
for key, value in cfg.NUMBER_IMAGE_PATHS.items():
number_images[key] = pygame.image.load(value).convert_alpha()
# --管道
pipe_images = dict()
pipe_images['bottom'] = pygame.image.load(random.choice(list(cfg.PIPE_IMAGE_PATHS.values()))).convert_alpha()
pipe_images['top'] = pygame.transform.rotate(pipe_images['bottom'], 180)
# --小鸟图片
bird_images = dict()
for key, value in cfg.BIRD_IMAGE_PATHS[random.choice(list(cfg.BIRD_IMAGE_PATHS.keys()))].items():
bird_images[key] = pygame.image.load(value).convert_alpha()
# --背景图片
backgroud_image = pygame.image.load(random.choice(list(cfg.BACKGROUND_IMAGE_PATHS.values()))).convert_alpha()
# --其他图片
other_images = dict()
for key, value in cfg.OTHER_IMAGE_PATHS.items():
other_images[key] = pygame.image.load(value).convert_alpha()
既然有管道那游戏的话需要得分过关肯定是不能碰到管道的,碰到直接更新小鸟在重新开始。
# --碰撞检测
for pipe in pipe_sprites:
if pygame.sprite.collide_mask(bird, pipe):
sounds['hit'].play()
is_game_running = False
# --更新小鸟
boundary_values = [0, base_pos[-1]]
is_dead = bird.update(boundary_values, float(clock.tick(cfg.FPS))/1000.)
if is_dead:
sounds['hit'].play()
is_game_running = False
游戏开始、结束的界面:
'''显示开始界面'''
def startGame(screen, sounds, bird_images, other_images, backgroud_image, cfg):
base_pos = [0, cfg.SCREENHEIGHT*0.79]
base_diff_bg = other_images['base'].get_width() - backgroud_image.get_width()
msg_pos = [(cfg.SCREENWIDTH-other_images['message'].get_width())/2, cfg.SCREENHEIGHT*0.12]
bird_idx = 0
bird_idx_change_count = 0
bird_idx_cycle = itertools.cycle([0, 1, 2, 1])
bird_pos = [cfg.SCREENWIDTH*0.2, (cfg.SCREENHEIGHT-list(bird_images.values())[0].get_height())/2]
bird_y_shift_count = 0
bird_y_shift_max = 9
shift = 1
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
return {'bird_pos': bird_pos, 'base_pos': base_pos, 'bird_idx': bird_idx}
sounds['wing'].play()
bird_idx_change_count += 1
if bird_idx_change_count % 5 == 0:
bird_idx = next(bird_idx_cycle)
bird_idx_change_count = 0
base_pos[0] = -((-base_pos[0] + 4) % base_diff_bg)
bird_y_shift_count += 1
if bird_y_shift_count == bird_y_shift_max:
bird_y_shift_max = 16
shift = -1 * shift
bird_y_shift_count = 0
bird_pos[-1] = bird_pos[-1] + shift
screen.blit(backgroud_image, (0, 0))
screen.blit(list(bird_images.values())[bird_idx], bird_pos)
screen.blit(other_images['message'], msg_pos)
screen.blit(other_images['base'], base_pos)
pygame.display.update()
clock.tick(cfg.FPS)
'''游戏结束界面'''
def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg):
sounds['die'].play()
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
return
boundary_values = [0, base_pos[-1]]
bird.update(boundary_values, float(clock.tick(cfg.FPS))/1000.)
screen.blit(backgroud_image, (0, 0))
pipe_sprites.draw(screen)
screen.blit(other_images['base'], base_pos)
showScore(screen, score, number_images)
bird.draw(screen)
pygame.display.update()
clock.tick(cfg.FPS)
总结
玩了坠落的小鸟游戏的新迷们!有没有超过66根管道柱子呀??期待.jpg
小编会继续再接再厉为大家谋福利哒!记得三连哦你们的支持是我的动力,奥里给
源码基地:#959755565#免费领取项目源码!!
欢迎阅读往期文章哦:
1.成语接龙游戏项目。 2.塔防游戏项目。 3.记忆翻牌游戏项目。 4.吃豆豆小游戏项目。
5.外星人入侵游戏项目。6.数织游戏项目。 7.脑力锻炼游戏项目。 8.垃圾分类小游戏项目。
9.雷霆战机游戏项目。 10.”我的兔子“游戏项目。 11.八音符游戏项目。12.拼图小游戏项目。
13.滑雪小游戏项目。 14.桌面宠物项目。 15.无敌金身小恐龙。 16.坦克大战游戏项目。
..............更多内容敬请期待...........
需要之前的游戏源码也是免费分享的哈,需要的私信小编!