python小游戏——像素鸟代码开源_像素游戏 代码语言,吃一堑长一智

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新大数据全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注大数据)
img

正文

# --背景图片
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()
# 游戏开始界面
game_start_info = startGame(screen, sounds, bird_images, other_images, backgroud_image, cfg)
# 进入主游戏
score = 0
bird_pos, base_pos, bird_idx = list(game_start_info.values())
base_diff_bg = other_images['base'].get_width() - backgroud_image.get_width()
clock = pygame.time.Clock()
# --管道类
pipe_sprites = pygame.sprite.Group()
for i in range(2):
    pipe_pos = Pipe.randomPipe(cfg, pipe_images.get('top'))
    pipe_sprites.add(Pipe(image=pipe_images.get('top'), position=(cfg.SCREENWIDTH+200+i*cfg.SCREENWIDTH/2, pipe_pos.get('top')[-1])))
    pipe_sprites.add(Pipe(image=pipe_images.get('bottom'), position=(cfg.SCREENWIDTH+200+i*cfg.SCREENWIDTH/2, pipe_pos.get('bottom')[-1])))
# --bird类
bird = Bird(images=bird_images, idx=bird_idx, position=bird_pos)
# --是否增加pipe
is_add_pipe = True
# --游戏是否进行中
is_game_running = True
while is_game_running:
    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:
                bird.setFlapped()
                sounds['wing'].play()
    # --碰撞检测
    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
    # --移动base实现小鸟往前飞的效果
    base_pos[0] = -((-base_pos[0] + 4) % base_diff_bg)
    # --移动pipe实现小鸟往前飞的效果
    flag = False
    for pipe in pipe_sprites:
        pipe.rect.left -= 4
        if pipe.rect.centerx < bird.rect.centerx and not pipe.used_for_score:
            pipe.used_for_score = True
            score += 0.5
            if '.5' in str(score):
                sounds['point'].play()
        if pipe.rect.left < 5 and pipe.rect.left > 0 and is_add_pipe:
            pipe_pos = Pipe.randomPipe(cfg, pipe_images.get('top'))
            pipe_sprites.add(Pipe(image=pipe_images.get('top'), position=pipe_pos.get('top')))
            pipe_sprites.add(Pipe(image=pipe_images.get('bottom'), position=pipe_pos.get('bottom')))
            is_add_pipe = False
        elif pipe.rect.right < 0:
            pipe_sprites.remove(pipe)
            flag = True
    if flag: is_add_pipe = True
    # --绑定必要的元素在屏幕上
    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)
endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg)

‘’‘run’‘’
if name == ‘main’:
while True:
main()


### 三.cfg


'''配置文件'''  
 import os


  
 # FPS  
 FPS = 60  
 # 屏幕  
 SCREENWIDTH = 288  
 SCREENHEIGHT = 512  
 # 管道之间的空隙  
 PIPE\_GAP\_SIZE = 100  
 # 图片  
 NUMBER\_IMAGE\_PATHS = {  
     '0': os.path.join(os.getcwd(), 'resources/images/0.png'),  
     '1': os.path.join(os.getcwd(), 'resources/images/1.png'),  
     '2': os.path.join(os.getcwd(), 'resources/images/2.png'),  
     '3': os.path.join(os.getcwd(), 'resources/images/3.png'),  
     '4': os.path.join(os.getcwd(), 'resources/images/4.png'),  
     '5': os.path.join(os.getcwd(), 'resources/images/5.png'),  
     '6': os.path.join(os.getcwd(), 'resources/images/6.png'),  
     '7': os.path.join(os.getcwd(), 'resources/images/7.png'),  
     '8': os.path.join(os.getcwd(), 'resources/images/8.png'),  
     '9': os.path.join(os.getcwd(), 'resources/images/9.png')  
 }  
 BIRD\_IMAGE\_PATHS = {  
     'red': {  
         'up': os.path.join(os.getcwd(), 'resources/images/redbird-upflap.png'),  
         'mid': os.path.join(os.getcwd(), 'resources/images/redbird-midflap.png'),  
         'down': os.path.join(os.getcwd(), 'resources/images/redbird-downflap.png')  
     },  
     'blue': {  
         'up': os.path.join(os.getcwd(), 'resources/images/bluebird-upflap.png'),  
         'mid': os.path.join(os.getcwd(), 'resources/images/bluebird-midflap.png'),  
         'down': os.path.join(os.getcwd(), 'resources/images/bluebird-downflap.png')  
     },  
     'yellow': {  
         'up': os.path.join(os.getcwd(), 'resources/images/yellowbird-upflap.png'),  
         'mid': os.path.join(os.getcwd(), 'resources/images/yellowbird-midflap.png'),  
         'down': os.path.join(os.getcwd(), 'resources/images/yellowbird-downflap.png')  
     }  
 }  
 BACKGROUND\_IMAGE\_PATHS = {  
     'day': os.path.join(os.getcwd(), 'resources/images/background-day.png'),  
     'night': os.path.join(os.getcwd(), 'resources/images/background-night.png')  
 }  
 PIPE\_IMAGE\_PATHS = {  
     'green': os.path.join(os.getcwd(), 'resources/images/pipe-green.png'),  
     'red': os.path.join(os.getcwd(), 'resources/images/pipe-red.png')  
 }  
 OTHER\_IMAGE\_PATHS = {  
     'gameover': os.path.join(os.getcwd(), 'resources/images/gameover.png'),  
     'message': os.path.join(os.getcwd(), 'resources/images/message.png'),  
     'base': os.path.join(os.getcwd(), 'resources/images/base.png')  
 }  
 # 音频路径  
 AUDIO\_PATHS = {  
     'die': os.path.join(os.getcwd(), 'resources/audios/die.wav'),  
     'hit': os.path.join(os.getcwd(), 'resources/audios/hit.wav'),  
     'point': os.path.join(os.getcwd(), 'resources/audios/point.wav'),  
     'swoosh': os.path.join(os.getcwd(), 'resources/audios/swoosh.wav'),  
     'wing': os.path.join(os.getcwd(), 'resources/audios/wing.wav')  
 }


## 四.README


# Introduction  
 https://mp.weixin.qq.com/s/44CZjwvjnH0kkkKIn5U9Uw


# Environment  

OS: Windows10
Python: Python3.5+(have installed necessary dependencies)



# Usage  

Step1:
pip install -r requirements.txt
Step2:
run “python Game6.py”



# Game Display  
![外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=demonstration%2Frunning.gif&pos_id=img-6FyAMoyZ-1713318210742)




**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)**
![img](https://img-blog.csdnimg.cn/img_convert/667fe168dae5ba45ba7367683de7f7d0.png)

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)**
[外链图片转存中...(img-c3OL55MZ-1713318210742)]

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值