// src\player.cpp #include #include #include #include entt::entity player; const float SPEED = 300.0f; void create_player(entt::registry& registry,Texture* texture){ const auto entity = registry.create(); registry.emplace(entity,100.0f,0.0f); registry.emplace(entity,SPEED,0.0f); registry.emplace(entity); registry.emplace(entity,texture,0.0f,0.0f,70.0f,70.0f,false,false,0.0f); } void update_player_system(entt::registry& registry,float dt){ auto view = registry.view(); for (entt::entity entity : view){ const Position& pos = view.get(entity); Velocity& vel = view.get(entity); Sprite& sprite = view.get(entity); if (IsKeyPressed(KEY_W)){ if (vel.dy > 0) continue; vel.dx = 0; vel.dy = -SPEED; } else if (IsKeyPressed(KEY_S)){ if (vel.dy < 0) continue; vel.dx = 0; vel.dy = SPEED; } else if (IsKeyPressed(KEY_A)){ if (vel.dx > 0) continue; vel.dx = -SPEED; vel.dy = 0; } else if (IsKeyPressed(KEY_D)){ if (vel.dx < 0) continue; vel.dx = SPEED; vel.dy = 0; } if (vel.dx != 0.0f || vel.dy != 0.0f) { // atan2 returns radians. Convert to degrees if your renderer expects it! float radians = std::atan2(vel.dy, vel.dx); sprite.rotation = radians * (180.0f / 3.14159265f); } } }