Skip to content

Commit 49edf3e

Browse files
committed
v1.0
No sound yet
1 parent c1fe0d9 commit 49edf3e

10 files changed

+17
-6
lines changed

__pycache__/alien.cpython-311.pyc

26 Bytes
Binary file not shown.

__pycache__/game.cpython-311.pyc

4.02 KB
Binary file not shown.

__pycache__/obstacle.cpython-311.pyc

-15 Bytes
Binary file not shown.

__pycache__/spaceship.cpython-311.pyc

414 Bytes
Binary file not shown.

alien.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, screen_width, offset):
2222
self.speed = 3
2323
else:
2424
self.speed = -3
25-
self.rect = self.image.get_rect(topleft = (x, 70))
25+
self.rect = self.image.get_rect(topleft = (x, 80))
2626

2727
def update(self):
2828
self.rect.x += self.speed

game.py

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ def check_for_collisions(self):
6565
if self.lives == 0:
6666
self.game_over()
6767

68+
if self.aliens:
69+
for alien in self.aliens:
70+
pygame.sprite.spritecollide(alien, self.obstacle_1.blocks, True)
71+
pygame.sprite.spritecollide(alien, self.obstacle_2.blocks, True)
72+
pygame.sprite.spritecollide(alien, self.obstacle_3.blocks, True)
73+
pygame.sprite.spritecollide(alien, self.obstacle_4.blocks, True)
74+
75+
if pygame.sprite.spritecollide(alien, self.spaceship, False):
76+
self.game_over()
77+
6878
def create_aliens(self):
6979
for row in range(5):
7080
for column in range(11):

highscore.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9200

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
if event.type == pygame.QUIT:
3636
pygame.quit()
3737
sys.exit()
38-
if event.type == ALIENLASER:
38+
if event.type == ALIENLASER and game.run:
3939
game.alien_shoot_laser()
4040
if event.type == MYSTERYSHIP and game.run:
4141
game.create_mystery_ship()

obstacle.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def __init__(self, x, y):
1818
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
1919
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
2020
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
21-
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
2221
[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1],
2322
[1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1],
2423
[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1]]
@@ -27,7 +26,7 @@ class Obstacle():
2726
def __init__(self, offset_x, offset_y):
2827
self.blocks = pygame.sprite.Group()
2928

30-
for row in range(14):
29+
for row in range(13):
3130
for column in range(23):
3231
if shape[row][column] == 1:
3332
x = column * 3

spaceship.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Spaceship(pygame.sprite.Sprite):
55

66
def __init__(self, screen_width, screen_height, offset):
77
super().__init__()
8+
self.offset = offset
89
self.image = pygame.image.load("Graphics/ship.png")
910
self.rect = self.image.get_rect(midbottom = ((screen_width+offset)/2, screen_height))
1011
self.speed = 5
@@ -37,8 +38,8 @@ def recharge(self):
3738
self.laser_ready = True
3839

3940
def constrain_position(self):
40-
if self.rect.left < 0:
41-
self.rect.x = 0
41+
if self.rect.left < self.offset:
42+
self.rect.x = self.offset
4243
if self.rect.right > self.screen_width:
4344
self.rect.right = self.screen_width
4445

0 commit comments

Comments
 (0)