feat(player): player now implements physics entity
This commit is contained in:
		
							parent
							
								
									a70658bab6
								
							
						
					
					
						commit
						333ada2752
					
				| 
						 | 
				
			
			@ -3,6 +3,7 @@
 | 
			
		|||
#include "debug.h"
 | 
			
		||||
#include "game_world.h"
 | 
			
		||||
#include "input_axis.h"
 | 
			
		||||
#include "physics_world.h"
 | 
			
		||||
 | 
			
		||||
const Vector PLAYER_SPEED = MakeVector(1.0f, 0.70f);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -25,6 +26,13 @@ Player* MakePlayer() {
 | 
			
		|||
    
 | 
			
		||||
    *self = (Player) {
 | 
			
		||||
        .transform = IdentityTransform,
 | 
			
		||||
        .rigidbody = NULL,
 | 
			
		||||
        .collisionShape = shape_new((Vector[]){
 | 
			
		||||
            MakeVector(-0.5, -0.25),
 | 
			
		||||
            MakeVector( 0.5, -0.25),
 | 
			
		||||
            MakeVector( 0.5,  0.25),
 | 
			
		||||
            MakeVector(-0.5,  0.25)
 | 
			
		||||
        }, 4),
 | 
			
		||||
        .playerInput = playerinput_new(self, -1),
 | 
			
		||||
        .moveInput = ZeroVector,
 | 
			
		||||
        .attackInput = 0,
 | 
			
		||||
| 
						 | 
				
			
			@ -35,6 +43,9 @@ Player* MakePlayer() {
 | 
			
		|||
        .jab_b = NULL,
 | 
			
		||||
        .animationStateMachine = NULL,
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    self->rigidbody = rigidbody_make(Player_as_Transformable(self));
 | 
			
		||||
    
 | 
			
		||||
    sprite_set_origin(self->sprite, MakeVector(0.45f, 1.f));
 | 
			
		||||
    
 | 
			
		||||
    self->idle = animation_sprite_new(self->sprite, spritesheet_load("assets/Player_Idle.png", IVectorFrom(512)), 1.5f, LoopMode_Loop);
 | 
			
		||||
| 
						 | 
				
			
			@ -50,7 +61,10 @@ Player* MakePlayer() {
 | 
			
		|||
Player* SpawnPlayer(Vector location) {
 | 
			
		||||
    Player* self = MakePlayer();
 | 
			
		||||
    self->transform.position = location;
 | 
			
		||||
    
 | 
			
		||||
    game_world_add_entity(Player_as_BehaviourEntity(self));
 | 
			
		||||
    physics_world_add_entity(Player_as_PhysicsEntity(self));
 | 
			
		||||
    
 | 
			
		||||
    Internal_PlayerInitInput(self);
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -84,3 +98,18 @@ void PlayerUpdate(Player* self, float deltaTime) {
 | 
			
		|||
void PlayerDraw(Player* self) {
 | 
			
		||||
    animation_sprite_draw(self->currentAnimation, &self->transform);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Transform* PlayerGetTransform(Player* self) {
 | 
			
		||||
    return &self->transform;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RigidBody* PlayerGetRigidBody(Player* self) {
 | 
			
		||||
    return self->rigidbody;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Shape* PlayerGetCollisionShape(Player* self) {
 | 
			
		||||
    return self->collisionShape;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PlayerOnCollision(Player* self, Collision collision) {}
 | 
			
		||||
void PlayerOnOverlap(Player* self, PhysicsEntity other) {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,12 +9,17 @@
 | 
			
		|||
#include "vmath.h"
 | 
			
		||||
#include "transform.h"
 | 
			
		||||
#include "player_input.h"
 | 
			
		||||
#include "rigidbody.h"
 | 
			
		||||
#include "shape.h"
 | 
			
		||||
 | 
			
		||||
extern const Vector PLAYER_SPEED;
 | 
			
		||||
 | 
			
		||||
typedef struct Player {
 | 
			
		||||
    Transform transform;
 | 
			
		||||
    
 | 
			
		||||
    RigidBody* rigidbody;
 | 
			
		||||
    Shape* collisionShape;
 | 
			
		||||
    
 | 
			
		||||
    PlayerInput* playerInput;
 | 
			
		||||
    
 | 
			
		||||
    Vector moveInput;
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +49,13 @@ void PlayerStart(Player* self);
 | 
			
		|||
void PlayerUpdate(Player* self, float deltaTime);
 | 
			
		||||
void PlayerDraw(Player* self);
 | 
			
		||||
 | 
			
		||||
Transform* PlayerGetTransform(Player* self);
 | 
			
		||||
 | 
			
		||||
RigidBody* PlayerGetRigidBody(Player* self);
 | 
			
		||||
Shape* PlayerGetCollisionShape(Player* self);
 | 
			
		||||
void PlayerOnCollision(Player* self, Collision collision);
 | 
			
		||||
void PlayerOnOverlap(Player* self, PhysicsEntity other);
 | 
			
		||||
 | 
			
		||||
impl_Drop_for(Player,
 | 
			
		||||
    DestroyPlayer
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -54,4 +66,15 @@ impl_BehaviourEntity_for(Player,
 | 
			
		|||
    PlayerDraw
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
impl_Transformable_for(Player,
 | 
			
		||||
    PlayerGetTransform
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
impl_PhysicsEntity_for(Player,
 | 
			
		||||
    PlayerGetRigidBody,
 | 
			
		||||
    PlayerGetCollisionShape,
 | 
			
		||||
    PlayerOnCollision,
 | 
			
		||||
    PlayerOnOverlap
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
#endif // !FIGHT_PLAYER_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue