-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalien_tile.py
More file actions
48 lines (40 loc) · 1.58 KB
/
alien_tile.py
File metadata and controls
48 lines (40 loc) · 1.58 KB
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
from turtle import Screen, Turtle
from alien import Alien
from bullet import Bullet
from config import BULLET_COLLISION_DISTANCE, TILE_COLUMNS, TILE_ROWS, TILE_LEFT_LIMIT, TILE_SEP_X, TILE_SEP_Y, TILE_TOP_LIMIT
class Alien_Tile():
@staticmethod
def create_alien_tiles():
tiles = []
for row in range(TILE_ROWS):
for col in range(TILE_COLUMNS):
x = TILE_LEFT_LIMIT + col * TILE_SEP_X
y = TILE_TOP_LIMIT - row * TILE_SEP_Y
t = (col + row) % 3
match t:
case 0:
alien_type = "alien1"
case 1:
alien_type = "alien2"
case 2:
alien_type = "saucer1"
tile = Alien(alien_type, (x, y))
tile.showturtle()
tiles.append(tile)
return tiles
@staticmethod
def collide_alien_tiles(bullet, bullets, tiles, screen):
for tile in tiles:
#Detect collision with bullet
if bullet.distance(tile) < BULLET_COLLISION_DISTANCE:
print("Tile hit!")
bullet.delete()
bullets.remove(bullet)
tile.delete()
tiles.remove(tile)
break # Exit after first collision to prevent multiple bounces
def fire_alien_tiles(self, tiles, bullets):
for tile in tiles:
if tile.isvisible():
new_missile = Bullet("misssile", tile.position())
bullets.append(new_missile)