Fixed character movement by ignoring key repeats

This commit is contained in:
2015-08-23 02:48:58 +10:00
parent 563a217237
commit 3e42371e02
6 changed files with 20 additions and 7 deletions
+1
View File
@@ -21,6 +21,7 @@
*/
#include "base_character.hpp"
//TODO: remove this
#include "config_utility.hpp"
//-------------------------
+1
View File
@@ -26,6 +26,7 @@
#include "vector2.hpp"
//The base class for all objects in the world
//TODO: write a better hierarchy
class Entity {
public:
virtual void Update();
+1
View File
@@ -26,6 +26,7 @@
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
for(auto& box : boxList) {
if (box.CheckOverlap(origin + bounds)) {
//TODO: write a better collision system
origin -= motion;
motion = {0, 0};
return true;
+15 -5
View File
@@ -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
switch(key.keysym.sym) {
switch(event.keysym.sym) {
case SDLK_ESCAPE:
//TODO: (3) the escape key should actually control menus and stuff
SendLogoutRequest();
@@ -243,7 +248,7 @@ void World::KeyDown(SDL_KeyboardEvent const& key) {
return;
}
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
switch(event.keysym.sym) {
case SDLK_w:
motion.y -= CHARACTER_WALKING_SPEED;
break;
@@ -270,13 +275,18 @@ void World::KeyDown(SDL_KeyboardEvent const& key) {
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
if (!localCharacter) {
return;
}
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
switch(event.keysym.sym) {
case SDLK_w:
motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED);
break;
+1 -1
View File
@@ -68,7 +68,7 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
//pseudo-list selection
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});
//Eat incoming packets
+1 -1
Submodule common updated: 2dd2aead13...93a955caf9