Movement tempfix made
authorIvan Hernandez <iturtleman128@gmail.com>
Sun, 12 Jul 2009 23:23:58 +0000 (18:23 -0500)
committerIvan Hernandez <iturtleman128@gmail.com>
Sun, 12 Jul 2009 23:23:58 +0000 (18:23 -0500)
Game.cpp
Level.cpp
Level.h

index db7596a..5d281d9 100644 (file)
--- a/Game.cpp
+++ b/Game.cpp
@@ -3,7 +3,7 @@
 #include <string>
 #include <iostream>
 
-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);
index 3ee28be..22f223b 100644 (file)
--- 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 (file)
--- 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;