Modifies path creation and deletion
This commit is contained in:
1 parent
00fb80382b
commit
8c414fe294
4 files changed
+81
-36
No files matched your search
+26
-12
@@ -1,3 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import cast
|
||||
|
||||
from pyglet.shapes import Circle, Line
|
||||
from libs.ecs.world import World
|
||||
from components import (
|
||||
@@ -6,7 +9,7 @@ from components import (
|
||||
Position,
|
||||
Radius,
|
||||
SpaceShipMarker,
|
||||
Target,
|
||||
Destination,
|
||||
)
|
||||
from random import choice, randint, sample
|
||||
from settings import (
|
||||
@@ -19,12 +22,19 @@ from settings import (
|
||||
SPACESHIP_PATH_COLOR,
|
||||
SPACESHIP_RADIUS,
|
||||
)
|
||||
from libs.ecs.state import BaseGameState
|
||||
|
||||
|
||||
@dataclass
|
||||
class GameState(BaseGameState):
|
||||
selected_planet: int | None = None
|
||||
routes: dict[tuple[int, int], "Line"] = field(default_factory=dict)
|
||||
|
||||
|
||||
def create_planet(
|
||||
world: World,
|
||||
x: int,
|
||||
y: int,
|
||||
x: float,
|
||||
y: float,
|
||||
radius: int,
|
||||
color: tuple[int, int, int, int],
|
||||
) -> int:
|
||||
@@ -39,26 +49,30 @@ def create_planet(
|
||||
|
||||
def create_spaceship(
|
||||
world: World,
|
||||
src_x: int,
|
||||
src_y: int,
|
||||
dest_x: int,
|
||||
dest_y: int,
|
||||
src_x: float,
|
||||
src_y: float,
|
||||
dest_x: float,
|
||||
dest_y: float,
|
||||
approach_radius: int,
|
||||
):
|
||||
return world.spawn(
|
||||
SpaceShipMarker(),
|
||||
Position(x=src_x, y=src_y),
|
||||
Target(x=dest_x, y=dest_y),
|
||||
Destination(x=dest_x, y=dest_y),
|
||||
Radius(approach_radius),
|
||||
Circle(x=src_x, y=src_y, radius=SPACESHIP_RADIUS, color=SPACESHIP_COLOR),
|
||||
Line(x=src_x, y=src_y, x2=dest_x, y2=dest_y, color=SPACESHIP_PATH_COLOR),
|
||||
Circle(
|
||||
x=src_x,
|
||||
y=src_y,
|
||||
radius=SPACESHIP_RADIUS,
|
||||
color=SPACESHIP_COLOR,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def generate_random_planet(world: World) -> int:
|
||||
radius: int = randint(MIN_PLANET_RADIUS, MAX_PLANET_RADIUS)
|
||||
x: int = randint(radius, SCREEN_WIDTH - radius)
|
||||
y: int = randint(radius, SCREEN_HEIGHT - radius)
|
||||
x: float = float(randint(radius, SCREEN_WIDTH - radius))
|
||||
y: float = float(randint(radius, SCREEN_HEIGHT - radius))
|
||||
# color = (randint(0, 255), randint(0, 255), randint(0, 255), 255)
|
||||
color = choice(PLANET_COLORS) + (255,)
|
||||
return create_planet(world, x, y, radius, color)
|
||||
|
||||
Reference in new issue
Block a user