Add changing speed with W and S
This commit is contained in:
parent
8138c506d9
commit
09897240d1
@ -24,6 +24,8 @@ struct PathMove {
|
|||||||
float time_passed = 0.0;
|
float time_passed = 0.0;
|
||||||
int current_point_index = 0;
|
int current_point_index = 0;
|
||||||
|
|
||||||
|
int speed_addition = 0; // 0, -1 or 1 depending on whether the speed should stay, decrease or increase
|
||||||
|
|
||||||
Path path;
|
Path path;
|
||||||
Views views;
|
Views views;
|
||||||
};
|
};
|
||||||
|
@ -58,17 +58,17 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
|||||||
if (event.key == GLFW_KEY_W) {
|
if (event.key == GLFW_KEY_W) {
|
||||||
myWorld->each<PathMove>([&](Entity *ent, ComponentHandle<PathMove> pathmove) {
|
myWorld->each<PathMove>([&](Entity *ent, ComponentHandle<PathMove> pathmove) {
|
||||||
if (event.action == GLFW_PRESS) {
|
if (event.action == GLFW_PRESS) {
|
||||||
// TODO: Velocity adder
|
pathmove->speed_addition += 1;
|
||||||
} else if (event.action == GLFW_RELEASE) {
|
} else if (event.action == GLFW_RELEASE) {
|
||||||
// TODO
|
pathmove->speed_addition -= 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (event.key == GLFW_KEY_S) {
|
} else if (event.key == GLFW_KEY_S) {
|
||||||
myWorld->each<PathMove>([&](Entity *ent, ComponentHandle<PathMove> pathmove) {
|
myWorld->each<PathMove>([&](Entity *ent, ComponentHandle<PathMove> pathmove) {
|
||||||
if (event.action == GLFW_PRESS) {
|
if (event.action == GLFW_PRESS) {
|
||||||
// TODO
|
pathmove->speed_addition -= 1;
|
||||||
} else if (event.action == GLFW_RELEASE) {
|
} else if (event.action == GLFW_RELEASE) {
|
||||||
// TODO
|
pathmove->speed_addition += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -77,6 +77,10 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
|||||||
void tick(World *pWorld, float deltaTime) override {
|
void tick(World *pWorld, float deltaTime) override {
|
||||||
pWorld->each<Transform, PathMove>(
|
pWorld->each<Transform, PathMove>(
|
||||||
[&](Entity *ent, ComponentHandle<Transform> transform, ComponentHandle<PathMove> pathmove) {
|
[&](Entity *ent, ComponentHandle<Transform> transform, ComponentHandle<PathMove> pathmove) {
|
||||||
|
// Handle change in speed
|
||||||
|
pathmove->speed += pathmove->speed_addition * deltaTime;
|
||||||
|
pathmove->speed = glm::clamp(pathmove->speed, 0.0, 10.0);
|
||||||
|
|
||||||
// Shorthand for the path (we'll use this a lot)
|
// Shorthand for the path (we'll use this a lot)
|
||||||
PathMove::Path path = pathmove->path;
|
PathMove::Path path = pathmove->path;
|
||||||
|
|
||||||
|
12
main.cpp
12
main.cpp
@ -88,13 +88,13 @@ int main() {
|
|||||||
|
|
||||||
Entity *player = world->create();
|
Entity *player = world->create();
|
||||||
player->assign<Transform>();
|
player->assign<Transform>();
|
||||||
player->assign<Movement>(glm::vec3(2.f, 2.f, 2.f));
|
//player->assign<Movement>(glm::vec3(2.f, 2.f, 2.f));
|
||||||
player->assign<MouseLook>(0.1);
|
//player->assign<MouseLook>(0.1);
|
||||||
player->assign<Camera>(70.0f, 1280, 720, 0.1f, 100.0f);
|
player->assign<Camera>(70.0f, 1280, 720, 0.1f, 100.0f);
|
||||||
/*player->assign<PathMove>(10.0, PathMove::Path(std::vector<glm::vec3>{
|
player->assign<PathMove>(3.0, PathMove::Path(std::vector<glm::vec3>{
|
||||||
glm::vec3(0.0, 2.0, 0.0),
|
glm::vec3(0.0, 2.0, 0.0),
|
||||||
glm::vec3(-2.0, 2.0, -1.0),
|
glm::vec3(0.0, 2.0, -1.0),
|
||||||
glm::vec3(-1.0, 2.0, -2.0),
|
glm::vec3(0.0, 2.0, -2.0),
|
||||||
glm::vec3(4.0, 3.0, -3.0),
|
glm::vec3(4.0, 3.0, -3.0),
|
||||||
glm::vec3(2.0, 2.0, -4.0),
|
glm::vec3(2.0, 2.0, -4.0),
|
||||||
glm::vec3(1.0, 2.0, -4.0),
|
glm::vec3(1.0, 2.0, -4.0),
|
||||||
@ -109,7 +109,7 @@ int main() {
|
|||||||
glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)),
|
glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||||
glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f))
|
glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f))
|
||||||
})
|
})
|
||||||
);*/
|
);
|
||||||
|
|
||||||
Entity *monkey = world->create();
|
Entity *monkey = world->create();
|
||||||
monkey->assign<Transform>();
|
monkey->assign<Transform>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user