鱼C论坛

 找回密码
 立即注册
查看: 5164|回复: 7

surface模块中,get_rect()的一些疑惑,求赐教。。。

[复制链接]
发表于 2021-7-16 23:10:25 | 显示全部楼层
本帖最后由 badboy991 于 2021-7-16 23:17 编辑

import pygame
import sys
from pygame.locals import *
#初始化pygame
pygame.init()

#全屏的时候有用
size = [600,500]


bg = (255,255,255)

speed = [2,0]
#全屏设置
fullscreen = False
#全屏的分辨率
full_ratio = pygame.display.list_modes()
#创建指定窗口大小
screen = pygame.display.set_mode(size,RESIZABLE)
#设置窗口标题
pygame.display.set_caption("第一个游戏")
#加载图片
turtle = pygame.image.load("wg1.png")

turtle_right = pygame.transform.rotate(turtle,90)
turtle_top = pygame.transform.rotate(turtle,180)
turtle_left = pygame.transform.rotate(turtle,270)
turtle_bottom = turtle
turtle = turtle_top
#获取图形的位置矩形

position = turtle.get_rect()


while True:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == KEYDOWN:
            # 全屏(f3)
            if event.key == K_F3:
                fullscreen = not fullscreen
                if fullscreen:
                    size = full_ratio[0]
                    screen = pygame.display.set_mode(size,FULLSCREEN | HWSURFACE)
                else:
                    size = width,height = 700,500
                    screen = pygame.display.set_mode(size)

    #图形移动
    position = position.move(speed)

    if position.right > size[0]:
        turtle = turtle_right
        speed = [0,2]
    if position.bottom > size[1]:
        turtle = turtle_bottom
        speed = [-2,0]
    if position.left < 0:
        turtle = turtle_left
        speed = [0,-2]
    if position.top < 0:
        turtle = turtle_top
        speed = [2,0]
        if position.right > size[0]:
            turtle = turtle_right
            speed = [0,2]
    #填充背景色
    screen.fill("white")
    #更新图形
    screen.blit(turtle,position)
    #更新界面
    pygame.display.flip()
    #延迟10毫秒
    pygame.time.delay(10)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-22 03:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表