mirror of
https://github.com/csd4ni3l/connect-the-current.git
synced 2026-01-01 04:13:41 +01:00
Switched to Linux and it changed the line encoding, probably, cause every file is showing as changed.
This commit is contained in:
118
game/cell.py
118
game/cell.py
@@ -1,60 +1,60 @@
|
||||
import arcade, arcade.gui
|
||||
|
||||
from utils.constants import ROTATIONS, NEIGHBOURS
|
||||
from utils.preload import TEXTURE_MAP, wire_sound_effect
|
||||
|
||||
def get_opposite(direction):
|
||||
if direction == "l":
|
||||
return "r"
|
||||
elif direction == "r":
|
||||
return "l"
|
||||
elif direction == "t":
|
||||
return "b"
|
||||
elif direction == "b":
|
||||
return "t"
|
||||
|
||||
class Cell(arcade.Sprite):
|
||||
def __init__(self, cell_type, x, y, left_neighbour, top_neighbour):
|
||||
super().__init__(TEXTURE_MAP[cell_type, ROTATIONS[cell_type][0] if cell_type in ROTATIONS else "cross", cell_type == "power_source"], center_x=x, center_y=y)
|
||||
|
||||
self.rotation = ROTATIONS[cell_type][0] if cell_type in ROTATIONS else "cross"
|
||||
self.cell_type = cell_type
|
||||
self.powered = False
|
||||
self.left_neighbour, self.top_neighbour = left_neighbour, top_neighbour
|
||||
self.right_neighbour, self.bottom_neighbour = None, None
|
||||
|
||||
def get_neighbour(self, name):
|
||||
if name == "l":
|
||||
return self.left_neighbour
|
||||
elif name == "r":
|
||||
return self.right_neighbour
|
||||
elif name == "b":
|
||||
return self.bottom_neighbour
|
||||
elif name == "t":
|
||||
return self.top_neighbour
|
||||
|
||||
def get_connected_neighbours(self, include_houses=False):
|
||||
return [
|
||||
self.get_neighbour(neighbour_direction) for neighbour_direction in NEIGHBOURS[self.rotation]
|
||||
if (
|
||||
self.get_neighbour(neighbour_direction) and
|
||||
(include_houses or self.get_neighbour(neighbour_direction).cell_type != "house") and
|
||||
get_opposite(neighbour_direction) in NEIGHBOURS[self.get_neighbour(neighbour_direction).rotation]
|
||||
)
|
||||
]
|
||||
|
||||
def update_visual(self):
|
||||
self.texture = TEXTURE_MAP[(self.cell_type, self.rotation, self.powered)]
|
||||
|
||||
def next_rotation(self, sfx, sfx_volume):
|
||||
if sfx:
|
||||
wire_sound_effect.play(volume=sfx_volume / 50)
|
||||
|
||||
current_index = ROTATIONS[self.cell_type].index(self.rotation)
|
||||
|
||||
if current_index + 1 == len(ROTATIONS[self.cell_type]):
|
||||
self.rotation = ROTATIONS[self.cell_type][0]
|
||||
else:
|
||||
self.rotation = ROTATIONS[self.cell_type][current_index + 1]
|
||||
|
||||
import arcade, arcade.gui
|
||||
|
||||
from utils.constants import ROTATIONS, NEIGHBOURS
|
||||
from utils.preload import TEXTURE_MAP, wire_sound_effect
|
||||
|
||||
def get_opposite(direction):
|
||||
if direction == "l":
|
||||
return "r"
|
||||
elif direction == "r":
|
||||
return "l"
|
||||
elif direction == "t":
|
||||
return "b"
|
||||
elif direction == "b":
|
||||
return "t"
|
||||
|
||||
class Cell(arcade.Sprite):
|
||||
def __init__(self, cell_type, x, y, left_neighbour, top_neighbour):
|
||||
super().__init__(TEXTURE_MAP[cell_type, ROTATIONS[cell_type][0] if cell_type in ROTATIONS else "cross", cell_type == "power_source"], center_x=x, center_y=y)
|
||||
|
||||
self.rotation = ROTATIONS[cell_type][0] if cell_type in ROTATIONS else "cross"
|
||||
self.cell_type = cell_type
|
||||
self.powered = False
|
||||
self.left_neighbour, self.top_neighbour = left_neighbour, top_neighbour
|
||||
self.right_neighbour, self.bottom_neighbour = None, None
|
||||
|
||||
def get_neighbour(self, name):
|
||||
if name == "l":
|
||||
return self.left_neighbour
|
||||
elif name == "r":
|
||||
return self.right_neighbour
|
||||
elif name == "b":
|
||||
return self.bottom_neighbour
|
||||
elif name == "t":
|
||||
return self.top_neighbour
|
||||
|
||||
def get_connected_neighbours(self, include_houses=False):
|
||||
return [
|
||||
self.get_neighbour(neighbour_direction) for neighbour_direction in NEIGHBOURS[self.rotation]
|
||||
if (
|
||||
self.get_neighbour(neighbour_direction) and
|
||||
(include_houses or self.get_neighbour(neighbour_direction).cell_type != "house") and
|
||||
get_opposite(neighbour_direction) in NEIGHBOURS[self.get_neighbour(neighbour_direction).rotation]
|
||||
)
|
||||
]
|
||||
|
||||
def update_visual(self):
|
||||
self.texture = TEXTURE_MAP[(self.cell_type, self.rotation, self.powered)]
|
||||
|
||||
def next_rotation(self, sfx, sfx_volume):
|
||||
if sfx:
|
||||
wire_sound_effect.play(volume=sfx_volume / 50)
|
||||
|
||||
current_index = ROTATIONS[self.cell_type].index(self.rotation)
|
||||
|
||||
if current_index + 1 == len(ROTATIONS[self.cell_type]):
|
||||
self.rotation = ROTATIONS[self.cell_type][0]
|
||||
else:
|
||||
self.rotation = ROTATIONS[self.cell_type][current_index + 1]
|
||||
|
||||
self.update_visual()
|
||||
Reference in New Issue
Block a user