【发布时间】:2013-06-11 02:54:08
【问题描述】:
我的程序允许图像跟随我的鼠标光标,但我无法使用Attack 方法绘制圆圈,因为我必须在移动方法中使用suface.fill(移动方法是followMeLittleBoy)我可以让圆圈画一秒钟,但只能在移动时画,它只是大麦。这是我的完整代码,而不是我的导入等
class Hero ():
def __init__(self):
self.dead = False
pygame.mouse.set_visible(False)
self.X_MOVE_AMT = 5
self.Y_MOVE_AMT = 5
self.space = pygame.image.load ("hero_sprite.jpg")
self.spaceRect = self.space.get_rect()
self.spaceRect.topleft = (100,100)
surface.blit (self.space, self.spaceRect)
pygame.display.update()
def followMeLittleBoy (self):
amntTuple = pygame.mouse.get_pos()
self.X_MOVE_AMT = math.ceil((amntTuple[0] - self.spaceRect.left)*0.2)
self.Y_MOVE_AMT = math.ceil((amntTuple[1] - self.spaceRect.top)*0.2)
self.spaceRect.left += self.X_MOVE_AMT
self.spaceRect.top += self.Y_MOVE_AMT
surface.blit (self.space, self.spaceRect)
pygame.display.update()
def Attack (self):
surface.fill ((255,255,255))
amntTuple = pygame.mouse.get_pos()
pygame.draw.circle(surface, pygame.Color(0,0,255), amntTuple, 20, 2)
surface.blit (self.space, self.spaceRect)
var = Hero ()
while True:
surface.fill((255,255,255))
for event in pygame.event.get():
var.followMeLittleBoy ()
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_SPACE:
var.Attack()
【问题讨论】:
标签: python-3.x pygame