Fixed character movement by ignoring key repeats
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "base_character.hpp"
|
#include "base_character.hpp"
|
||||||
|
|
||||||
|
//TODO: remove this
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
|
|
||||||
//The base class for all objects in the world
|
//The base class for all objects in the world
|
||||||
|
//TODO: write a better hierarchy
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
|
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
|
||||||
for(auto& box : boxList) {
|
for(auto& box : boxList) {
|
||||||
if (box.CheckOverlap(origin + bounds)) {
|
if (box.CheckOverlap(origin + bounds)) {
|
||||||
|
//TODO: write a better collision system
|
||||||
origin -= motion;
|
origin -= motion;
|
||||||
motion = {0, 0};
|
motion = {0, 0};
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -229,9 +229,14 @@ void World::MouseWheel(SDL_MouseWheelEvent const& event) {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::KeyDown(SDL_KeyboardEvent const& key) {
|
void World::KeyDown(SDL_KeyboardEvent const& event) {
|
||||||
|
//BUGFIX: SDL2 introduced key repeats, so I need to ignore it
|
||||||
|
if (event.repeat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//hotkeys
|
//hotkeys
|
||||||
switch(key.keysym.sym) {
|
switch(event.keysym.sym) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
//TODO: (3) the escape key should actually control menus and stuff
|
//TODO: (3) the escape key should actually control menus and stuff
|
||||||
SendLogoutRequest();
|
SendLogoutRequest();
|
||||||
@@ -243,7 +248,7 @@ void World::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector2 motion = localCharacter->GetMotion();
|
Vector2 motion = localCharacter->GetMotion();
|
||||||
switch(key.keysym.sym) {
|
switch(event.keysym.sym) {
|
||||||
case SDLK_w:
|
case SDLK_w:
|
||||||
motion.y -= CHARACTER_WALKING_SPEED;
|
motion.y -= CHARACTER_WALKING_SPEED;
|
||||||
break;
|
break;
|
||||||
@@ -270,13 +275,18 @@ void World::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
SendLocalCharacterMovement();
|
SendLocalCharacterMovement();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::KeyUp(SDL_KeyboardEvent const& key) {
|
void World::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
|
//BUGFIX: SDL2 introduced key repeats, so I need to ignore it
|
||||||
|
if (event.repeat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//character movement
|
//character movement
|
||||||
if (!localCharacter) {
|
if (!localCharacter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector2 motion = localCharacter->GetMotion();
|
Vector2 motion = localCharacter->GetMotion();
|
||||||
switch(key.keysym.sym) {
|
switch(event.keysym.sym) {
|
||||||
case SDLK_w:
|
case SDLK_w:
|
||||||
motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED);
|
motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
//pseudo-list selection
|
//pseudo-list selection
|
||||||
boundingBox = {300, 50, 200, 12};
|
boundingBox = {300, 50, 200, 12};
|
||||||
|
|
||||||
//DEBUG: hacked together a highlight box
|
//hacked together a highlight box
|
||||||
highlightImage.Create(GetRenderer(), 300, 12, {49, 150, 5, 255});
|
highlightImage.Create(GetRenderer(), 300, 12, {49, 150, 5, 255});
|
||||||
|
|
||||||
//Eat incoming packets
|
//Eat incoming packets
|
||||||
|
|||||||
+1
-1
Submodule common updated: 2dd2aead13...93a955caf9
Reference in New Issue
Block a user