added collision
This commit is contained in:
parent
f0d7ef7cce
commit
306f282d15
2 changed files with 11 additions and 1 deletions
|
|
@ -13,6 +13,13 @@ class CircleShape(pygame.sprite.Sprite):
|
|||
self.velocity = pygame.Vector2(0, 0)
|
||||
self.radius = radius
|
||||
|
||||
def is_colided(self,other_circle):
|
||||
distance = self.position.distance_to(other_circle.position)
|
||||
if other_circle.radius + self.radius <= distance:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def draw(self, screen):
|
||||
# sub-classes must override
|
||||
pass
|
||||
|
|
|
|||
5
main.py
5
main.py
|
|
@ -45,9 +45,12 @@ def main():
|
|||
|
||||
for drawable in drawables:
|
||||
drawable.draw(screen)
|
||||
|
||||
for updatable in updatables:
|
||||
updatable.update(dt)
|
||||
for asteroid in asteroids:
|
||||
if asteroid.is_colided(p1):
|
||||
print("Game Over!")
|
||||
return
|
||||
|
||||
pygame.display.flip()
|
||||
tick = clock.tick(60)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue