vpython 贞测碰撞_python碰撞检测?

所以我一直在为一个项目开发一个python游戏,现在我遇到了一个问题,如果我在游戏中设置了一个障碍,我就不能让它对我的图片做出响应,就像我的图片与它发生碰撞一样,游戏就结束了。我已经做了很长一段时间了,但是我不知道代码。任何我们将非常感谢您的帮助。我非常需要帮助这个。拜托并不是说我是初学者,而且我刚开始学习python一个月以前。所以请试着去理解。我附上了下面的代码。在import pygame, random, sys

from pygame.locals import *

BACKGROUNDCOLOR = (181, 230, 29)

FPS = 30

pixels = 5

pygame.init()

mainClock = pygame.time.Clock()

windowSurface = pygame.display.set_mode((990, 557))

pygame.display.set_caption('Clumsy Claire :D')

background = pygame.image.load('grass.jpg')

backgroundRect = background.get_rect()

size = (990, 557)

background.get_size()

image = pygame.image.load('snail 2.png')

imageRect = image.get_rect()

stone1 = pygame.image.load('rock.PNG')

stone1Rect = stone1.get_rect()

stone2 = pygame.image.load('rock.PNG')

stone2Rect = stone2.get_rect()

BROWN = (128,64,0)

pygame.draw.line(background, BROWN, (98, 555), (98,69), 12)

pygame.draw.line(background, BROWN, (98, 16), (98,1), 12)

pygame.draw.line(background, BROWN, (94, 3), (283, 3),12)

pygame.draw.line(background, BROWN, (278, 457), (278, 3),12)

pygame.draw.line(background, BROWN, (278, 554), (278, 512),12)

pygame.draw.line(background, BROWN, (274, 554), (470, 554),12)

pygame.draw.line(background, BROWN, (465, 554), (465, 90),12)

pygame.draw.line(background, BROWN, (465, 35), (465, 0),12)

pygame.draw.line(background, BROWN, (465, 3), (657, 3),12)

pygame.draw.line(background, BROWN, (652,555 ), (652, 502),12)

pygame.draw.line(background, BROWN, (652, 449), (652, 0),12)

pygame.draw.line(background, BROWN, (648, 553), (844, 553),12)

pygame.draw.line(background, BROWN, (838, 553 ), (838, 138),12)

pygame.draw.line(background, BROWN, (838, 84 ), (838, 0),12)

while True:

imageRect.topleft = (10,488)

moveLeft = False

moveRight = False

moveUp = False

moveDown = False

while True:

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

if event.type == KEYDOWN:

if event.key == K_LEFT:

moveLeft = True

if event.key == K_RIGHT:

moveRight = True

if event.key == K_UP:

moveUp = True

if event.key == K_DOWN:

moveDown = True

if event.type == KEYUP:

if event.key == K_LEFT:

moveLeft = False

if event.key == K_RIGHT:

moveRight = False

if event.key == K_UP:

moveUp = False

if event.key == K_DOWN:

moveDown = False

if moveLeft and imageRect.left > 0:

imageRect.move_ip(-1 * pixels, 0)

if moveRight and imageRect.right < 990:

imageRect.move_ip(pixels, 0)

if moveUp and imageRect.top > 0:

imageRect.move_ip(0, -1 * pixels)

if moveDown and imageRect.bottom < 557:

imageRect.move_ip(0, pixels)

windowSurface.blit(background, backgroundRect)

windowSurface.blit(image, imageRect)

rock1 = background.blit(stone1,(658,337))

rock2 = background.blit(stone2,(225,150))

pygame.display.update()

mainClock.tick(FPS)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值