Как обнаружить столкновение в pygame?Python

Программы на Python
Ответить
Anonymous
 Как обнаружить столкновение в pygame?

Сообщение Anonymous »

Я составил список маркеров и список спрайтов, используя приведенные ниже классы. Как определить, что пуля сталкивается со спрайтом, а затем удалить этот спрайт и пулю?
# Define the sprite class
class Sprite:

def __init__(self, x, y, image_file):
# Define the position of the sprite.
self.x = x
self.y = y

# Load the sprite image and get it's rect.
self.image = pygame.image.load(image_file)
self.rect = self.image.get_rect()
def render(self, window):
# Render the sprite onscreen
window.blit(self.image, (self.x, self.y))

# Define the bullet class to create bullets
class Bullet:
def __init__(self, x, y):
# Define the position of the bullet.
self.x = x + 23 # Offset it
self.y = y

# Load the bullet image and get it's rect.
self.bullet = pygame.image.load("user_bullet.BMP")
self.rect = self.bullet.get_rect()
def render(self, window):
# Render the bullet onscreen.
window.blit(self.bullet, (self.x, self.y))


Подробнее здесь: https://stackoverflow.com/questions/296 ... -in-pygame
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»