|
Before Width: | Height: | Size: 79 KiB |
@ -1,58 +0,0 @@
|
||||
def find_neighbors(self, coordinates) -> list: |
||||
""" |
||||
Find and return the cells adjacent to the cell at position (coordinates). |
||||
|
||||
Adjacent cells are those directly above, below, left, right, |
||||
and all four diagonally adjacent cells. |
||||
""" |
||||
neighbors = [] |
||||
x_coord, y_coord = coordinates |
||||
|
||||
# Check all eight possible directions |
||||
for delta_x in [-1, 0, 1]: |
||||
for delta_y in [-1, 0, 1]: |
||||
new_x, new_y = x_coord + delta_x, y_coord + delta_y |
||||
|
||||
# Skip the cell itself |
||||
if delta_x == 0 and delta_y == 0: |
||||
continue |
||||
|
||||
# Check if the new coordinates are within the battlefield |
||||
if 0 <= new_x < self.width and 0 <= new_y < self.height: |
||||
if not self.battlefield[new_y][new_x]: |
||||
neighbors.append((new_x, new_y)) |
||||
|
||||
return neighbors |
||||
|
||||
def get_closest_neighbor(self, neighbors_list, target_position): |
||||
""" |
||||
Find and return the neighbor cell in the neighbors_list closest to the target position. |
||||
""" |
||||
# If there are no neighbors, return None |
||||
if not neighbors_list: |
||||
return None |
||||
|
||||
# Calculate the distance between the target position and each neighbor |
||||
distances = [((neighbor[0] - target_position[0])**2 + (neighbor[1] - target_position[1])**2)**0.5 for neighbor in neighbors_list] |
||||
|
||||
# Find the index of the smallest distance |
||||
min_distance_index = distances.index(min(distances)) |
||||
|
||||
# Return the neighbor corresponding to the smallest distance |
||||
return neighbors_list[min_distance_index] |
||||
|
||||
def iso_transform(self, x, y): |
||||
screen_x = (x - y) * self.cell_width / 2 + self.view_offset_x |
||||
screen_y = (x + y) * self.cell_height / 2 + self.view_offset_y |
||||
return screen_x, screen_y |
||||
|
||||
def inv_iso_transform(self, screen_x, screen_y): |
||||
y = ((screen_x - self.view_offset_x) / (self.cell_width / 2) + (screen_y - self.view_offset_y) / (self.cell_height / 2)) / 2 |
||||
x = ((screen_y - self.view_offset_y) / (self.cell_height / 2) - (screen_x - self.view_offset_x) / (self.cell_width / 2)) / 2 |
||||
return int(x), int(y) |
||||
|
||||
def get_distance(self, position1, position2): |
||||
x1, y1 = position1 |
||||
x2, y2 = position2 |
||||
return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 |
||||
|
||||
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
@ -1,2 +0,0 @@
|
||||
[InternetShortcut] |
||||
URL=http://donate.kenney.nl/ |
||||
@ -1,2 +0,0 @@
|
||||
[InternetShortcut] |
||||
URL=https://www.facebook.com/KenneyNL |
||||
@ -1,22 +0,0 @@
|
||||
|
||||
############################################################################### |
||||
|
||||
|
||||
Tower Defense assets (isometric) |
||||
by Kenney Vleugels for Kenney (www.kenney.nl) |
||||
|
||||
------------------------------ |
||||
|
||||
License (Creative Commons Zero, CC0) |
||||
http://creativecommons.org/publicdomain/zero/1.0/ |
||||
|
||||
You may use these graphics in personal and commercial projects. |
||||
Credit (Kenney or www.kenney.nl) would be nice but is not mandatory. |
||||
|
||||
------------------------------ |
||||
|
||||
Donate: http://donate.kenney.nl/ |
||||
Request: http://request.kenney.nl/ |
||||
|
||||
|
||||
############################################################################### |
||||
|
Before Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 725 B |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1013 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 963 B |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 950 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |