0
간단한 게임을 작성했습니다 (문제가있는 부분 만 표시됩니다) health
점수를 제외한 모든 항목이 훌륭하게 작동합니다. 하나의 객체가 다른 객체에 충돌을 받았는지 확인하기 위해 print 문을 사용합니다. 따라서 if statement
은 입니다. 인쇄 문을 보았으므로 health
점수가 업데이트되지 않습니다. 내가 여기서 뭔가를 놓치고 있니? 도와 줘서 고마워! 당신이 health
수정되어 있지만개체가 맞았지만 점수가 업데이트되지 않습니다
sqrls = pygame.image.load("crazySquirrel1.gif")
sqrlsrect = sqrls.get_rect()
sqrls_startx = 200
sqrls_starty = 530
sqrlsrect.center = (sqrls_startx, sqrls_starty)
girl = pygame.image.load('girl1.gif')
girlrect = girl.get_rect()
x = 850
y = 278
girlrect.center = (x, y)
screen.blit(girl,(x, y))
## adding health score
health = 3
font = pygame.font.SysFont("Comic Sans MS", 20)
text = font.render("Health: " + str(health),1, RED)
## main game loop **********************************
x_change = 0
endGame = False
while not endGame:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
x_change = -2
elif event.key == pygame.K_RIGHT:
x_change = 2
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_change = 0
x += x_change
sqrlsrect = sqrlsrect.move(sqrls_speed) # moving squirrel 1
if sqrlsrect.left < 0 or sqrlsrect.right > w:
sqrls_speed[0] = -sqrls_speed[0]
if sqrlsrect.top < 0 or sqrlsrect.bottom > h:
sqrls_speed[1] = -sqrls_speed[1]
if sqrlsrect.center == girlrect.center:
print ('Ouch s!')
health -= 1
screen.blit(bg, (0, 0))
screen.blit(sqrls, sqrlsrect)
screen.blit(girl, (x, y))
screen.blit(text, (w*0.88, h*0.03))
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()
정말 고마워요! 그것은 효과가있다! 당신은 훌륭합니다! – Rish