当前位置: 首页 > news >正文

网站建设寻求/b2b平台是什么意思啊

网站建设寻求,b2b平台是什么意思啊,上海设计网站开发,wordpress增强插件最近在玩Pygame小游戏,因而想把一些部分整理下来供往后学习参考。效果大概是这样的:游戏的名称:Starting Screen,两个游戏按钮Play 和 Exit,当鼠标碰触时按钮会发生高亮。点击按钮退出Startting_Screen函数&#xff0c…
最近在玩Pygame小游戏,因而想把一些部分整理下来供往后学习参考。

效果大概是这样的:

145f8cb35ed15894e932fb5812589b14.png
游戏的名称:Starting Screen,两个游戏按钮Play 和 Exit,当鼠标碰触时按钮会发生高亮。点击按钮退出Startting_Screen函数,正常游戏中会进入到游戏的主页面

导入pygame

为了效果好一些,我选了张背景图bg.jpg,剩下的部分就是设定好屏幕的宽、高
pygame的初始化还是需要的
import pygamedisplay_width = 1200
display_height = 600WHITE = (255, 255, 255)
RED = (255, 0, 0)
bg_location = 'bg.jpg'pygame.init()

按钮类 Class Button

说是Button,其实就是设定特定的text要在屏幕的哪个地方显示,而当鼠标移到这个text所占的区域的时候(or 点击),程序再做出对应的操作
class Button(object):def __init__(self, text, color, x=None, y=None, **kwargs):self.surface = font.render(text, True, color)self.WIDTH = self.surface.get_width()self.HEIGHT = self.surface.get_height()if 'centered_x' in kwargs and kwargs['centered_x']:self.x = display_width // 2 - self.WIDTH // 2else:self.x = xif 'centered_y' in kwargs and kwargs['cenntered_y']:self.y = display_height // 2 - self.HEIGHT // 2else:self.y = ydef display(self):screen.blit(self.surface, (self.x, self.y))def check_click(self, position):x_match = position[0] > self.x and position[0] < self.x + self.WIDTHy_match = position[1] > self.y and position[1] < self.y + self.HEIGHTif x_match and y_match:return Trueelse:return False

开始页面 Starting Screen

开始页面做的,,就是加载背景、Button,如果加了音乐的话,还需要这里进行音乐的播放
在Button的显示上,这边设置了当鼠标移到Button上就显示红色高亮,这个也是通过加载text中实现的,一个while中的条件判读
def starting_screen():screen.blit(bg, (0,0))game_title = font.render('Starting Screen', True, WHITE)screen.blit(game_title, (display_width//2 - game_title.get_width()//2, 150))play_button = Button('Play', RED, None, 350, centered_x=True)exit_button = Button('Exit', WHITE, None, 400, centered_x=True)play_button.display()exit_button.display()pygame.display.update()while True:if play_button.check_click(pygame.mouse.get_pos()):play_button = Button('Play', RED, None, 350, centered_x=True)else:play_button = Button('Play', WHITE, None, 350, centered_x=True)if exit_button.check_click(pygame.mouse.get_pos()):exit_button = Button('Exit', RED, None, 400, centered_x=True)else:exit_button = Button('Exit', WHITE, None, 400, centered_x=True)play_button.display()exit_button.display()pygame.display.update()for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()raise SystemExitif pygame.mouse.get_pressed()[0]:if play_button.check_click(pygame.mouse.get_pos()):breakif exit_button.check_click(pygame.mouse.get_pos()):break

调用函数

这边到了实现的部分,你需要一个screen作为基础,然后加载背景图,加载字体,之后再调用Starting_scrreen函数
screen = pygame.display.set_mode((display_width, display_height))
bg = pygame.image.load(bg_location)
font_addr = pygame.font.get_default_font()
font = pygame.font.Font(font_addr, 36)starting_screen()

总结:

Pygame所涉及的模块并不多,实现的2D小游戏也没有多少市场了,但编程的初学者可以用来了解项目的流程及熟悉Python及面向对象编程。

http://www.lbrq.cn/news/804763.html

相关文章:

  • 网站怎么收录/门户网站
  • 内容类网站如何 流量/整合营销策略
  • 磐安住房和城乡建设部网站/百度新闻网
  • 知名商城网站建设公司/免费b2b平台推广
  • 长春哪家做网站做的好/外链是什么意思
  • 广东省网站建设网站/免费产品推广网站
  • 中国空间站的意义/网址怎么弄
  • 51ape是谁做的网站/今日新闻最新事件
  • 河南网站建设报价/安徽疫情最新情况
  • wordpress 设置字体/aso优化渠道
  • 2008如何添加iis做网站/seo实战视频
  • 网站制作_做网站_耐思智慧/百度seo排名公司
  • 东莞大岭山网站制作/seo网站内容优化
  • 什么是管理/佛山旺道seo
  • 印刷设计营销网站/深圳百度seo培训
  • 做网站用windows还是linux/网络推广公司十大排名
  • 网站怎么做来流量/重庆seo整站优化系统
  • 互联网服务平台登录/百度seo排名原理
  • 网络设备/泽成seo网站排名
  • 做网站需要多少钱卖片可以吗/千峰培训可靠吗?
  • 高端网站设计定制公司/脚上起小水泡还很痒是什么原因
  • 健康管理公司网站建设/关键词林俊杰歌词
  • 免费素材网站可商用/安徽网站推广
  • 网站建设 安庆/百度输入法下载
  • 网站策划书如何做/网络营销的10个特点
  • qq短网址生成/seo优化文章网站
  • 三亚市住房和城乡建设局/河南seo和网络推广
  • 网站建设的常用技术有哪些/seo 优化 工具
  • 工商局网站建设查不到/网站推广的目的是什么
  • 如何在网站添加代码/教育机构
  • 机试01-C++基础语法与库函数
  • SpringMVC的高级特性
  • Rockchip RK3568J +FPGA边缘智能系统及储能网关
  • 今日矩阵系列
  • ASP.NET Core中使用NLog和注解实现日志记录
  • 【n8n教程笔记——工作流Workflow】文本课程(第二阶段)——1 理解数据结构 (Understanding the data structure)