我正在尝试编写一个看起来像雷达地图的程序。我有一条旋转360度的线,雷达上的“柏忌”图像。我试图找出热线以使线条与矩形碰撞,但我得到了这个错误。 AttributeError:'pygame.Rect'对象没有属性'get_rect'
基本上,我的问题是如何让一条画线与一张blitted图像碰撞?
感谢。
import pygame
import math
from colors import *
from pygame.locals import *
pygame.init()
bkrd = pygame.image.load("radar//radar2.jpg")
bkrdrect = bkrd.get_rect()
bogey = pygame.image.load("radar//bogey2.png")
bogeyrect = bogey.get_rect()
window_size = window_width, window_height = 1101,822
window = pygame.display.set_mode( window_size, pygame.RESIZABLE )
pygame.display.set_caption( "Radar" )
clock = pygame.time.Clock()
FPS = 60
pygame.time.set_timer(USEREVENT + 1, 100)
pygame.key.set_repeat(0,0)
window.blit(bkrd,bkrdrect)
pygame.display.update()
angle = 0
eta = 0
bogey_one_x = 532
bogey_one_y = 210
def mainloop():
global angle,eta,bogey_one_x,bogey_one_y
while True:
angle +=1
eta +=1
bogey_one_x += .05
bogey_one_y +=.02
window.blit(bkrd,bkrdrect)
window.blit(bogey,(bogey_one_x,bogey_one_y))
radar = (685,413)
radar_len = 253
x = radar[0] + math.cos(math.radians(angle)) * radar_len
y = radar[1] + math.sin(math.radians(angle)) * radar_len
line = pygame.draw.line(window, (green), radar, (x,y), 1)
linerect = line.get_rect()
if linerect.colliderect(bogeyrect):
print "collide"
pygame.display.update()
for event in pygame.event.get():
if ( event.type == pygame.QUIT ) or \
( event.type == pygame.KEYDOWN and \
( event.key == pygame.K_ESCAPE) ):
running = False
pygame.quit()
mainloop()