From: Ivan Hernandez Date: Sun, 12 Jul 2009 23:23:58 +0000 (-0500) Subject: Movement tempfix made X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=ccf78f5c42a5dd12466dc4707302c83353a5db06;p=IvanGame.git Movement tempfix made --- diff --git a/Game.cpp b/Game.cpp index db7596a..5d281d9 100644 --- a/Game.cpp +++ b/Game.cpp @@ -3,7 +3,7 @@ #include #include -const Uint32 Game::waitTime = 30; /* ms */ +const Uint32 Game::waitTime = 1000/60; /* ms */ Game::Game() : mCurrentLevel(0), mScreen(0) { @@ -24,11 +24,6 @@ Game::Game() : mCurrentLevel(0), mScreen(0) // Set the title of our application window handler SDL_WM_SetCaption("Ivan's Game", NULL); - // We activate keyboard repetition. Therefore, when a key stays pressed down - // it will keep moving the image around the screen - // To see prcisely what this toggle does, just comment the line and recompile - // the code... - SDL_EnableKeyRepeat(25, 20); SDL_ShowCursor(0); // Create the first level mLevels.push_back(new Level(mScreen)); @@ -99,6 +94,7 @@ void Game::run() getCurrentLevel()->postEvent(event); break; } + getCurrentLevel()->update(); } SDL_RemoveTimer(timer); diff --git a/Level.cpp b/Level.cpp index 3ee28be..22f223b 100644 --- a/Level.cpp +++ b/Level.cpp @@ -97,12 +97,16 @@ void Level::postEvent(SDL_Event event) { switch (event.type) { case SDL_KEYDOWN: { - Uint8 *keys = SDL_GetKeyState(NULL); - if ( keys[SDLK_LEFT] ) { mSprites[0]->xadd(-1); } - if ( keys[SDLK_RIGHT] ) { mSprites[0]->xadd(1); } - if ( keys[SDLK_UP] ) { mSprites[0]->yadd(-1); } - if ( keys[SDLK_DOWN] ) { mSprites[0]->yadd(1); } + } } } +void Level::update() +{ + Uint8 *keys = SDL_GetKeyState(NULL); + if ( keys[SDLK_LEFT] ) { mSprites[0]->xadd(-1); } + if ( keys[SDLK_RIGHT] ) { mSprites[0]->xadd(1); } + if ( keys[SDLK_UP] ) { mSprites[0]->yadd(-1); } + if ( keys[SDLK_DOWN] ) { mSprites[0]->yadd(1); } +} diff --git a/Level.h b/Level.h index 12e24ff..67a9bbf 100644 --- a/Level.h +++ b/Level.h @@ -13,6 +13,7 @@ public: void drawScene(); void LoadBG(string name); virtual void postEvent(SDL_Event event); + void update(); private: SDL_Surface *mBackground;