feat: prop now destroys itself when receiving message id 1
This commit is contained in:
parent
02f48c5fb3
commit
71d8ebd45c
|
@ -12,7 +12,7 @@ Prop* MakeProp(Sprite* sprite, Shape* shape) {
|
||||||
.rigidbody = NULL,
|
.rigidbody = NULL,
|
||||||
.collisionShape = 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);
|
self->collisionShape = collider_new(Prop_as_PhysicsEntity(self), shape, 0, PHYSICS_LAYER_DEFAULT);
|
||||||
rigidbody_set_static(self->rigidbody, 1);
|
rigidbody_set_static(self->rigidbody, 1);
|
||||||
sprite_set_origin(self->sprite, MakeVector(0.5f, 1.0f));
|
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) {
|
void DestroyProp(Prop* self) {
|
||||||
sprite_destroy(self->sprite);
|
sprite_destroy(self->sprite);
|
||||||
|
physics_world_remove_entity(Prop_as_PhysicsEntity(self));
|
||||||
collider_destroy(self->collisionShape);
|
collider_destroy(self->collisionShape);
|
||||||
rigidbody_destroy(self->rigidbody);
|
rigidbody_destroy(self->rigidbody);
|
||||||
free(self);
|
free(self);
|
||||||
|
@ -59,3 +60,11 @@ Transform* PropGetTransform(Prop* self) {
|
||||||
RigidBody* PropGetRigidBody(Prop* self) {
|
RigidBody* PropGetRigidBody(Prop* self) {
|
||||||
return self->rigidbody;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -31,8 +31,14 @@ void PropOnOverlap(Prop* self, Collider* other);
|
||||||
Transform* PropGetTransform(Prop* self);
|
Transform* PropGetTransform(Prop* self);
|
||||||
RigidBody* PropGetRigidBody(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); }
|
static long PropGetDepth(Prop* self) { return -(int)(self->transform.position.y * 1000); }
|
||||||
|
|
||||||
|
impl_MessageReceiver_for(Prop,
|
||||||
|
PropReceiveMessage
|
||||||
|
)
|
||||||
|
|
||||||
impl_Transformable_for(Prop,
|
impl_Transformable_for(Prop,
|
||||||
PropGetTransform
|
PropGetTransform
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue