fixed colision crash
This commit is contained in:
parent
306f282d15
commit
7b27ac29e8
2 changed files with 4 additions and 6 deletions
|
|
@ -15,10 +15,7 @@ class CircleShape(pygame.sprite.Sprite):
|
||||||
|
|
||||||
def is_colided(self,other_circle):
|
def is_colided(self,other_circle):
|
||||||
distance = self.position.distance_to(other_circle.position)
|
distance = self.position.distance_to(other_circle.position)
|
||||||
if other_circle.radius + self.radius <= distance:
|
return distance <= other_circle.radius + self.radius
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def draw(self, screen):
|
def draw(self, screen):
|
||||||
# sub-classes must override
|
# sub-classes must override
|
||||||
|
|
|
||||||
5
main.py
5
main.py
|
|
@ -1,4 +1,5 @@
|
||||||
import pygame
|
import pygame
|
||||||
|
import sys
|
||||||
from constants import *
|
from constants import *
|
||||||
from player import Player
|
from player import Player
|
||||||
from asteroidfield import AsteroidField
|
from asteroidfield import AsteroidField
|
||||||
|
|
@ -48,9 +49,9 @@ def main():
|
||||||
for updatable in updatables:
|
for updatable in updatables:
|
||||||
updatable.update(dt)
|
updatable.update(dt)
|
||||||
for asteroid in asteroids:
|
for asteroid in asteroids:
|
||||||
if asteroid.is_colided(p1):
|
if p1.is_colided(asteroid):
|
||||||
print("Game Over!")
|
print("Game Over!")
|
||||||
return
|
sys.exit()
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
tick = clock.tick(60)
|
tick = clock.tick(60)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue