鱼C论坛

 找回密码
 立即注册
查看: 362|回复: 5

[已解决]第81讲内容

[复制链接]
发表于 2018-10-20 11:03:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
求教大神为什么报错了
最佳答案
2018-10-20 11:13:32
恩,请确认答案
1540004502(1).jpg
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-10-20 11:07:43 | 显示全部楼层
代码全部粘贴出来,应该是你定义turtle_rect的问题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-10-20 11:09:22 | 显示全部楼层
塔利班 发表于 2018-10-20 11:07
代码全部粘贴出来,应该是你定义turtle_rect的问题

import pygame
import sys
from pygame import *

pygame.init()
fullscreen = False

#设置画布大小
size = width,height = 600,400
screen = pygame.display.set_mode(size)
pygame.display.set_caption('初次见面,请多关照')
bg = (255,255,255)

#导入乌龟
turtle = pygame.image.load('23bOOOPICc0.jpg')
position = turtle.get_rect()
speed =[5,0]

turtle_right = pygame.transform.rotate(turtle,90)
turtle_bottom = turtle
turtle_left = pygame.transform.rotate(turtle,270)
turtle_top = pygame.transform.rotate(turtle,180)

while True:
    #定义退出功能
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit

    #设置全屏
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_1:
                fullscreen = not fullscreen
                if fullscreen:
                    screen = pygame.display.set_mode((1600,900),pygame.FULLSCREEN | pygame.HWSURFACE)
                    width,height = 1600,900
                else:
                    size = width,height = 600,400
                    screen = pygame.display.set_mode(size)
        
    position = position.move(speed)
    #乌龟到达边界时位置变换
    if position.right > width:
        turtle = turtle_right
        position = turtle_rect = turtle.get_rect
        position.left = width - turtle_rect.width
        speed = [0,5]
    if position.bottom > height:
        turrle = turtle_bottom
        position = turtle_rect = turtle.get_rect
        position.left = width - turtle_rect.width
        position.top = height - turtle_rect.height
        speed = [-5,0]
    if position.left < 0:
        turrle = turtle_left
        position = turtle_rect = turtle.get_rect
        position.top = height - turtle_rect.height
        speed = [0,-5]
    if position.top < 0:
        turtle = turtle_top
        position = turtle_rect = turtle.get_rect
        speed = [5,0]
   

    screen.fill(bg)
    #刷新乌龟的位置,将乌龟与背景合在一起
    screen.blit(turtle,position)
    #刷新整个界面
    pygame.display.update()
    #设置延迟
    pygame.time.delay(10)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-10-20 11:10:45 | 显示全部楼层
position = turtle_rect = turtle.get_rect
get_rect少了括号
没括号是函数名
你要的是运行结果
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-10-20 11:12:52 | 显示全部楼层
塔利班 发表于 2018-10-20 11:10
position = turtle_rect = turtle.get_rect
get_rect少了括号
没括号是函数名

奥奥,明白了,多谢大侠指导
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-10-20 11:13:32 | 显示全部楼层    本楼为最佳答案   
恩,请确认答案
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-24 01:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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