-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (50 loc) · 1.51 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from turtle import Screen
from player import Player
from bullet import Bullet
from scoreboard import Scoreboard
from enemies import Enemy
import time
import random
screen = Screen()
screen.tracer(0)
screen.title("Space Invaders")
screen.bgcolor("black")
screen.setup(width=800, height=600)
player = Player((0, -250))
bullet = Bullet((player.xcor(), player.ycor()))
enemies = []
x_position = -360
y_position = 150
for i in range(15):
enemy = Enemy(x_position, y_position)
enemies.append(enemy)
x_position += 50
screen.onkeypress(player.player_left, "Left")
screen.onkeypress(player.player_right, "Right")
lives = Scoreboard((-100, 200))
points = Scoreboard((100, 200))
game_is_on = True
while game_is_on:
screen.listen()
bullet.bullet_move()
time.sleep(bullet.move_speed)
screen.update()
special = random.choice(enemies)
special.enemy_move()
if bullet.ycor() > 150:
bullet.reset_position((player.xcor(), player.ycor()))
for brick in enemies:
if bullet.distance(brick) < 15:
print(bullet.move_speed)
bullet.reset_position((player.xcor(), player.ycor()))
brick.hideturtle()
enemies.remove(brick)
points.update_points()
if special.ycor() == -280:
print("crossed")
lives.update_points()
enemies.remove(special)
if len(enemies) == 0 or lives.points > 3:
points.game_over()
game_is_on = False
screen.exitonclick()