From 851b90e50d108d37fb8f1356fc72eefc2e911692 Mon Sep 17 00:00:00 2001 From: Aspect1103 Date: Fri, 16 Feb 2024 21:04:58 +0000 Subject: [PATCH] r --- hades_extensions/game_objects/components/__init__.pyi | 1 + src/hades/views/game.py | 6 +++--- src/hades_extensions/src/binding.cpp | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hades_extensions/game_objects/components/__init__.pyi b/hades_extensions/game_objects/components/__init__.pyi index e7fe5223..77eb4491 100644 --- a/hades_extensions/game_objects/components/__init__.pyi +++ b/hades_extensions/game_objects/components/__init__.pyi @@ -73,6 +73,7 @@ class MovementForce(Stat): ... class KinematicComponent(ComponentBase): def __init__(self: KinematicComponent, vertices: list[cpVect]) -> None: ... + def get_position(self: KinematicComponent) -> cpVect: ... class StatusEffect: value: float diff --git a/src/hades/views/game.py b/src/hades/views/game.py index bdf4bbda..c162d058 100644 --- a/src/hades/views/game.py +++ b/src/hades/views/game.py @@ -252,11 +252,11 @@ def on_update(self: Game, delta_time: float) -> None: GameObjectType.ENEMY, [], ): - entity.position = self.registry.get_component( + pos = self.registry.get_component( entity.game_object_id, KinematicComponent, - ).body.p - # TODO: Need to get position + ).get_position() + entity.position = (pos.x, pos.y) # Update the indicator bars for indicator_bar in self.indicator_bars: diff --git a/src/hades_extensions/src/binding.cpp b/src/hades_extensions/src/binding.cpp index e83c7779..67cc09df 100644 --- a/src/hades_extensions/src/binding.cpp +++ b/src/hades_extensions/src/binding.cpp @@ -611,7 +611,11 @@ PYBIND11_MODULE(hades_extensions, module) { // NOLINT .def(pybind11::init>(), pybind11::arg("vertices"), "Initialise the object.\n\n" "Args:\n" - " vertices: The vertices of the shape."); + " vertices: The vertices of the shape.") + .def("get_position", [](const KinematicComponent &kinematic_component) { return cpBodyGetPosition(*kinematic_component.body); }, + "Get the position of the game object.\n\n" + "Returns:\n" + " The position of the game object."); pybind11::class_>( systems, "PhysicseSystem", "Provides facilities to manipulate game object's physics.") .def(pybind11::init(), pybind11::arg("registry"),