【发布时间】:2017-05-11 21:15:21
【问题描述】:
我正在制作一个基本游戏,其中有一个表面,每次单击该表面时,它都会向右移动 5 个像素。该程序在没有 checkCollide(event) 函数的情况下工作得很好,但是当我设置那个条件时它不会移动。怎么了?
到目前为止我的代码是这样的
import pygame, sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((300,300))
def checkCollide(event):
k = 0
a,b = event.pos
x = P1[0].get_rect()
if x.collidepoint(a,b):
return True
return False
CP1 = [(150, 150)
,(155, 150)
,(160, 150)
,(165, 150)
,(170, 150)
,(175, 150)
,(180, 150)
,(185, 150)
,(190, 150)]
statp1_1 = 0
WHITE = (255,255,255)
DISPLAYSURF.fill(WHITE)
while True: # the main game loop
P1 = [pygame.image.load('PAzul.png'),CP1[statp1_1],statp1_1]
DISPLAYSURF.blit(P1[0], P1[1])
e = pygame.event.get()
for event in e:
if event.type == MOUSEBUTTONUP:
a = checkCollide(event)
if a:
DISPLAYSURF.fill(WHITE)
statp1_1 +=1
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
谢谢
【问题讨论】:
-
那么看起来
x.collidepoint(a,b)总是返回比较 False 的值。 -
您可以回答自己的问题并将其标记为已解决。
标签: python python-2.7 pygame