700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【Python游戏】鸡哥教你打篮球

【Python游戏】鸡哥教你打篮球

时间:2019-07-27 21:25:30

相关推荐

【Python游戏】鸡哥教你打篮球

序言

话说在前面,我不是小黑子~

我是超级大黑子😏

表弟大周末的跑来我家,没事干天天骚扰我,搞得我都不能跟小姐姐好好聊天了,于是为了打发表弟,我决定用Python做一个小游戏来消耗一下他的精力,我思来想去,决定把他变成小黑子,于是做了一个坤坤打篮球的游戏,没想到他还挺爱玩的~

终于解放了,于是我把游戏写下来,也给大家分享一下吧~

好吧,其实并不是这样的游戏,往下慢慢看吧。

这里是引用

准备工作

开发环境

Python版本:3.7.8

相关模块:

requests模块;

tqdm模块;

pyfreeproxy模块;

pyecharts模块;

以及一些python自带的模块。

效果预览

开始界面

游戏规则

wasd 控制人物的移动,空格启动律师函炸毁全部篮球。

兄弟们学习python,有时候不知道怎么学,从哪里开始学。掌握了基本的一些语法或者做了两个案例后,不知道下一步怎么走,不知道如何去学习更加高深的知识。

那么对于这些大兄弟们,我准备了大量的免费视频教程,PDF电子书籍,以及源代码!直接在文末名片自取即可!

代码实现

导入模块

import pygameimport sysimport tracebackimport osimport CXKimport enemyimport bulletimport supplyfrom pygame.locals import *from random import *

游戏主界面

#游戏主界面def ui():#循环播放背景音乐pygame.mixer.music.play(-1)#初始化界面按键图片并获取图片的矩形位置start_game_image = pygame.image.load("images/start_game.png").convert_alpha()start_game_image_rect = start_game_image.get_rect()game_rules_image = pygame.image.load("images/game_rules.png").convert_alpha()game_rules_image_rect = game_rules_image.get_rect()game_quit_image = pygame.image.load("images/game_quit.png").convert_alpha()game_quit_image_rect = game_quit_image.get_rect()#初始化游戏规则图片并获取图片的矩形位置rules_image = pygame.image.load("images/游戏玩法.png").convert_alpha()back_image = pygame.image.load("images/back.png").convert_alpha()back_image_rect = back_image.get_rect()#标志是否在主界面is_ui = True#帧率clock = pygame.time.Clock()#主界面循环while True:#获取事件信息for event in pygame.event.get():#如果点击右上角退出if event.type == QUIT:#退出程序pygame.quit()sys.exit()#如果是主界面if is_ui:#绘制背景screen.blit(background,(0,0))#更改主界面按键图片的矩形位置并绘制主界面按键start_game_image_rect.left,start_game_image_rect.top = (width - start_game_image_rect.width)//2,height - 500screen.blit(start_game_image,start_game_image_rect)game_rules_image_rect = game_rules_image.get_rect()game_rules_image_rect.left,game_rules_image_rect.top = (width - game_rules_image_rect.width)//2,start_game_image_rect.bottom+50screen.blit(game_rules_image,game_rules_image_rect)game_quit_image_rect.left,game_quit_image_rect.top = (width - game_quit_image_rect.width)//2, game_rules_image_rect.bottom+50screen.blit(game_quit_image,game_quit_image_rect)#检测用户的鼠标操作#如果用户按下鼠标左键if pygame.mouse.get_pressed()[0]:#获取鼠标坐标pos = pygame.mouse.get_pos()#如果用户点击”开始游戏“if start_game_image_rect.left < pos[0] < start_game_image_rect.right and start_game_image_rect.top < pos[1] < start_game_image_rect.bottom:#调用主函数main()#如果用户点击”退出游戏“if game_quit_image_rect.left < pos[0] < game_quit_image_rect.right and game_quit_image_rect.top < pos[1] < game_quit_image_rect.bottom:pygame.quit()sys.exit()#如果用户点击”游戏规则“if game_rules_image_rect.left < pos[0] < game_rules_image_rect.right and game_rules_image_rect.top < pos[1] < game_rules_image_rect.bottom:#离开主界面is_ui = False

代码还蛮多,需要的记得找我领取哈!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。