diff --git a/game/src/Prop.c b/game/src/Prop.c index c20c940..39c760e 100644 --- a/game/src/Prop.c +++ b/game/src/Prop.c @@ -12,7 +12,7 @@ Prop* MakeProp(Sprite* sprite, Shape* shape) { .rigidbody = NULL, .collisionShape = NULL }; - self->rigidbody = rigidbody_make(Prop_as_Transformable(self)); + self->rigidbody = rigidbody_make(Prop_as_PhysicsEntity(self)); self->collisionShape = collider_new(Prop_as_PhysicsEntity(self), shape, 0, PHYSICS_LAYER_DEFAULT); rigidbody_set_static(self->rigidbody, 1); sprite_set_origin(self->sprite, MakeVector(0.5f, 1.0f)); @@ -36,6 +36,7 @@ Prop* SpawnProp(Vector location, Sprite* sprite, Shape* shape, Vector origin) { void DestroyProp(Prop* self) { sprite_destroy(self->sprite); + physics_world_remove_entity(Prop_as_PhysicsEntity(self)); collider_destroy(self->collisionShape); rigidbody_destroy(self->rigidbody); free(self); @@ -59,3 +60,11 @@ Transform* PropGetTransform(Prop* self) { RigidBody* PropGetRigidBody(Prop* self) { return self->rigidbody; } + +void* PropReceiveMessage(Prop* self, MessageID message, void* data) { + if(message == 1) { + int damage = *(int*)data; + game_world_destroy_entity(Prop_as_BehaviourEntity(self)); + } + return 0; +} diff --git a/game/src/Prop.h b/game/src/Prop.h index 305ec64..f46d77b 100644 --- a/game/src/Prop.h +++ b/game/src/Prop.h @@ -31,8 +31,14 @@ void PropOnOverlap(Prop* self, Collider* other); Transform* PropGetTransform(Prop* self); RigidBody* PropGetRigidBody(Prop* self); +void* PropReceiveMessage(Prop* self, MessageID message, void* data); + static long PropGetDepth(Prop* self) { return -(int)(self->transform.position.y * 1000); } +impl_MessageReceiver_for(Prop, + PropReceiveMessage +) + impl_Transformable_for(Prop, PropGetTransform )