inital commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// src\player.cpp
|
||||
#include<raylib.h>
|
||||
#include<entt/entt.hpp>
|
||||
|
||||
#include<components.hpp>
|
||||
|
||||
entt::entity player;
|
||||
|
||||
|
||||
|
||||
void create_player(entt::registry& registry,Texture* texture){
|
||||
const auto entity = registry.create();
|
||||
registry.emplace<Position>(entity,100.0f,0.0f);
|
||||
registry.emplace<Velocity>(entity,0.0f,0.0f);
|
||||
registry.emplace<Player>(entity);
|
||||
registry.emplace<Sprite>(entity,texture);
|
||||
}
|
||||
|
||||
void update_player_system(entt::registry& registry,float dt){
|
||||
|
||||
auto view = registry.view<const Player, Velocity>();
|
||||
|
||||
// Constants for fine-tuning game feel
|
||||
const float GRAVITY = 900.0f; // Constant downward pull (pixels/sec^2)
|
||||
const float JUMP_FORCE = -350.0f; // Negative force to burst UPWARD
|
||||
|
||||
view.each([dt,GRAVITY,JUMP_FORCE](const auto &player, auto &velocity){
|
||||
if (IsKeyPressed(KEY_SPACE)){
|
||||
velocity.dy = JUMP_FORCE;
|
||||
}
|
||||
velocity.dy += GRAVITY * dt;
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user