作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题在这里已经有了答案:
How to detect collisions between two rectangular objects or images in pygame
(1 个回答)
11 个月前关闭。
我试图让我的子弹与我的敌人碰撞然后消失,但它只是因为某种原因扔掉了它们
for bullet in bullets[:]:
if bullet.y + bullet.x < enemys1.hitbox[1] + enemys1.hitbox[3] and bullet.y + bullet.x > enemys1.hitbox[1]:
if bullet.x - bullet.y > enemys1.hitbox[0] and bullet.x - bullet.y < enemys1.hitbox[0] + enemys1.hitbox[2]:
enemys1.hit()
bullets.pop(bullets.index(bullet))
class projectile(object):
def __init__(self, x, y, dirx, diry, color):
self.x = x
self.y = y
self.dirx = dirx
self.diry = diry
self.slash = pygame.image.load("heart.png")
self.rect = self.slash.get_rect()
self.rect.topleft = ( self.x, self.y )
self.speed = 10
self.color = color
def move(self):
self.x += self.dirx * self.speed
self.y += self.diry * self.speed
def draw(self, window):
self.rect.topleft = (round(self.x), round(self.y))
window.blit(slash, self.rect)
最佳答案
我建议使用 pygame.Rect
命中框的对象和 colliderect()
找到交点:
for bullet in bullets[:]:
hit_rect = pygame.Rect(*enemys1.hitbox)
if bullet.rect.colliderect(hit_rect):
enemys1.hit()
关于python - 与敌人相撞后的弹丸问题如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62096426/
所以我使用 projectile 作为 emacs 的项目管理工具,我可以在我的 emacs 中执行 projectile-ag 来查找术语。 但是我想通过文件扩展名过滤我的搜索,例如有时我只想查看
简介 我正在使用 ARKit 在增强现实中设计一款 iPhone 游戏。我的游戏的一部分涉及用户滑动以将球扔向目标。我的目的是创建一个向量,其中包含目标的 y 值和 z 值,但包含用户滑动位置的 x
我是一名优秀的程序员,十分优秀!