python 无情的表白机器

# -*- coding: utf-8 -*-
"""
Created on Thu Jan 13 21:52:53 2022

@author: shiyu
"""

import sys
import pygame
import time
from random import randint
import os
    
def text_rect(size,text,wordcolor,bgcolor,pos):
    f = pygame.font.Font('C:/Windows/Fonts/SimHei.ttf',size)
    text = f.render(text,True,wordcolor,bgcolor)
    textRect =text.get_rect()
    textRect.center = pos
    return [text,textRect]
    
def get_resource_path(relative_path):
    if getattr(sys,'frozen',False):
        base_path=sys._MEIPASS
    else:
        base_path=os.path.abspath('.')
    return os.path.join(base_path,relative_path)

p1_path=get_resource_path(os.path.join('resources','p1.png'))
p2_path=get_resource_path(os.path.join('resources','p2.png'))
    
pygame.init()
screen = pygame.display.set_mode((700,400))
pygame.display.set_caption('来自一位喜欢你的小哥哥')

f1 = text_rect(30,"小姐姐我观察你很久了",(0,0,0),(255,255,255),(160,100))
f2 = text_rect(20,"算了吧",(0,0,0),(230,230,230),(660,370))
f3 = text_rect(30,"做我女朋友好不好?",(0,0,0),(255,255,255),(145,150))
f4 = text_rect(20,"好啊",(0,0,0),(230,230,230),(30,370))

p1 = pygame.image.load(p1_path).convert_alpha()
p2 = pygame.image.load(p2_path).convert_alpha()
pygame.display.set_icon(p2)

while True: 
    screen.fill((255,255,255))
    screen.blit(p1, (450,100))
    screen.blit(*f1)
    screen.blit(*f3)
    screen.blit(*f2)
    screen.blit(*f4)
    x,y=pygame.mouse.get_pos()

    if f2[1].left<x<f2[1].right and f2[1].top<y<f2[1].bottom:
        p=-f2[1].left
        q=700-f2[1].right
        if p>q:
            t=p;p=q;q=t
        x_pos=randint(p,q)
        
        m=380-f2[1].bottom
        n=-f2[1].top
        if m>n:
            t=m;m=n;n=t
        y_pos=randint(m,n)
        
        f2[1]=f2[1].move(x_pos, y_pos)
    
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN and f4[1].left<x<f4[1].\
            right and f4[1].top<y<f4[1].bottom:
            pygame.quit()
            sys.exit()
#        if event.type == pygame.QUIT:
#            pygame.quit()
#            sys.exit()
            
    time.sleep(0.01)
    pygame.display.flip()

打包参考
https://blog.csdn.net/qq_42972591/article/details/122483721

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值