新手作品(全原创)
本帖最后由 陈尚涵 于 2020-4-20 13:25 编辑新手做了一个全原创的作品呀,谢谢鱼C!
废话不多说,进入正题。
在目录下创建一个文件叫main.py,代码如下:
# coding:utf-8
# 导入模块
import pygame
from sys import exit
from pygame.freetype import Font
# 初始化
pygame.init()
window_size = 600, 600
window_color = 255, 255, 255
window_caption = pygame.display.set_caption('你喜欢我吗?')
window = pygame.display.set_mode(window_size)
# 导入图片
not_granted = pygame.image.load('not-granted.png')
granted = pygame.image.load('granted.png')
# 创建变量
writer = Font('C://windows//Fonts//msyh.ttc', 36)
blit_normal = 1
MouseDown = False
stop = False
PressExit = False
# 进入游戏的中心环节(死循环)
while 1:
# 不停的更新变量
mouse_pos = pygame.mouse.get_pos()
# 条件判断
for event in pygame.event.get():
if event.type == pygame.QUIT:
PressExit = True
else:
PressExit = False
if event.type == pygame.MOUSEBUTTONDOWN:
MouseDown = True
else:
MouseDown = False
if stop:
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
exit()
# 补充颜色
window.fill(window_color)
# 按照情况选择模式
if not ((mouse_pos > 325 and mouse_pos < 595) and (mouse_pos > 400 and mouse_pos < 525) and not stop):
blit_normal = 0
else:
blit_normal = 1
# 对模式进行判断并处理
if blit_normal:
window.blit(granted, (325, 400))
window.blit(not_granted, (25, 400))
if (mouse_pos > 325 and mouse_pos < 595) and (mouse_pos > 400 and mouse_pos < 525) and MouseDown and not stop:
stop = True
else:
window.blit(not_granted, (325, 400))
window.blit(granted, (25, 400))
if (mouse_pos > 25 and mouse_pos < 295) and (mouse_pos > 400 and mouse_pos < 525) and MouseDown and not stop:
stop = True
# 画一些图形,写一些文字
pygame.draw.line(window, (0, 0, 0), (0, 300), (600, 300), 10)
if not stop and not PressExit:
writer.render_to(window, (150, 50), 'Hey, 你喜欢我吗?')
elif PressExit and not stop:
writer.render_to(window, (125, 50), '我才不会退出呢!')
else:
writer.render_to(window, (10, 50), '我就知道你会喜欢我^o^(现在按下Esc退出)', size=30)
# 更新显示
pygame.display.update()
# 游戏结束
{:10_298:}{:10_298:}欢迎留言{:10_298:}{:10_298:}
图片: 图片没显示出来 现在呢? 是不是要点个赞呢{:10_256:} 陈尚涵 发表于 2020-4-20 13:26
是不是要点个赞呢
我不是跟你说过嘛,不回复他他看不见 我回复了。 陈尚涵 发表于 2020-4-20 13:30
我回复了。
没看见咱俩回复的区别吗?
你那种回复不叫回复 qiuyouzhi 发表于 2020-4-20 13:32
没看见咱俩回复的区别吗?
你那种回复不叫回复
你的意思,是这样回复吗? 陈尚涵 发表于 2020-4-20 13:32
你的意思,是这样回复吗?
对 qiuyouzhi 发表于 2020-4-20 13:32
对
那,好友好友,我这个程序好不好呢{:10_327:} 有点简单 wuqramy 发表于 2020-4-20 13:51
有点简单
毕竟我还是个新手吗
页:
[1]