feat: prop now destroys itself when receiving message id 1

This commit is contained in:
Sara 2023-11-27 17:41:44 +01:00
parent 02f48c5fb3
commit 71d8ebd45c
2 changed files with 16 additions and 1 deletions

View file

@ -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;
}

View file

@ -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
)