add fruit reaction
This commit is contained in:
+12
-19
@@ -1,4 +1,6 @@
|
||||
// src\player.cpp
|
||||
#include <player.hpp>
|
||||
|
||||
#include<raylib.h>
|
||||
#include<entt/entt.hpp>
|
||||
|
||||
@@ -6,28 +8,24 @@
|
||||
|
||||
entt::entity player;
|
||||
|
||||
const float SPEED = 300.0f;
|
||||
|
||||
|
||||
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,300.0f,0.0f);
|
||||
registry.emplace<Velocity>(entity,SPEED,0.0f);
|
||||
registry.emplace<Player>(entity);
|
||||
registry.emplace<Sprite>(entity,texture);
|
||||
registry.emplace<Sprite>(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<const Player, const Position, 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
|
||||
|
||||
auto view = registry.view<const Player, const Position, Velocity,Sprite>();
|
||||
for (entt::entity entity : view){
|
||||
const Position& pos = view.get<Position>(entity);
|
||||
Velocity& vel = view.get<Velocity>(entity);
|
||||
const float SPEED = 350;
|
||||
Sprite& sprite = view.get<Sprite>(entity);
|
||||
|
||||
if (IsKeyPressed(KEY_W)){
|
||||
if (vel.dy > 0)
|
||||
@@ -52,16 +50,11 @@ void update_player_system(entt::registry& registry,float dt){
|
||||
vel.dy = 0;
|
||||
}
|
||||
|
||||
// if (pos.x < -50 && vel.dx < 0){
|
||||
// vel.dx *= -1;
|
||||
// } else if (pos.x > (GetScreenWidth()-250) && vel.dx > 0){
|
||||
// vel.dx *= -1;
|
||||
// }
|
||||
|
||||
// if (IsKeyPressed(KEY_SPACE)){
|
||||
// vel.dy = JUMP_FORCE;
|
||||
// }
|
||||
// vel.dy += GRAVITY * dt;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user