#include <string>
#include <iostream>
-const Uint32 Game::waitTime = 30; /* ms */
+const Uint32 Game::waitTime = 1000/60; /* ms */
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));
getCurrentLevel()->postEvent(event);
break;
}
+ getCurrentLevel()->update();
}
SDL_RemoveTimer(timer);
{
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); }
+}
void drawScene();
void LoadBG(string name);
virtual void postEvent(SDL_Event event);
+ void update();
private:
SDL_Surface *mBackground;