void Engine::getInput()
{
- SDL_GetMouseState(&mouseX, &mouseY);
-
- // Scale from window coordinates to graphics coordinates
- int w, h;
- SDL_GetWindowSize(graphics.window, &w, &h);
- mouseX = mouseX * 640 / w;
- mouseY = mouseY * 480 / h;
-
while (SDL_PollEvent(&event))
{
switch (event.type)
if (event.button.button == SDL_BUTTON_RIGHT) mouseRight = 0;
break;
+ case SDL_MOUSEMOTION:
+ mouseX = event.motion.x;
+ mouseY = event.motion.y;
+ break;
+
case SDL_KEYDOWN:
if (waitForButton)
return mouseY;
}
-void Engine::setMouse(int x, int y)
+void Engine::moveMouse(int dx, int dy)
{
- SDL_WarpMouseInWindow(graphics.window, x, y);
+ mouseX += dx;
+ mouseY += dy;
+ Math::limitInt(&mouseX, 0, 640);
+ Math::limitInt(&mouseY, 0, 480);
}
bool Engine::userAccepts()
int getMouseX() const;
int getMouseY() const;
- void setMouse(int x, int y);
+ void moveMouse(int dx, int dy);
bool userAccepts();
void clearCheatVars();
Uint32 frameLimit = SDL_GetTicks() + 16;
Uint32 now = SDL_GetTicks();
- int mouseXDelta = 0;
- int mouseYDelta = 0;
-
while (rtn == -1)
{
graphics.updateScreen();
engine.getInput();
config.populate();
+ int mouseXDelta = 0;
+ int mouseYDelta = 0;
+
if (config.isControl(CONTROL::RIGHT))
{
- mouseXDelta = 5;
+ mouseXDelta += 5;
}
if (config.isControl(CONTROL::LEFT))
{
- mouseXDelta = -5;
+ mouseXDelta -= 5;
}
if (config.isControl(CONTROL::DOWN))
{
- mouseYDelta = 5;
+ mouseYDelta += 5;
}
if (config.isControl(CONTROL::UP) || config.isControl(CONTROL::JUMP))
{
- mouseYDelta = -5;
+ mouseYDelta -= 5;
}
if ((mouseXDelta != 0) || (mouseYDelta != 0))
{
- engine.setMouse(engine.getMouseX() + (int)mouseXDelta, engine.getMouseY() + (int)mouseYDelta);
- mouseXDelta = 0;
- mouseYDelta = 0;
+ engine.moveMouse(mouseXDelta, mouseYDelta);
}
hubPoint = (HubLevel*)hubList.getHead();
}
SDL_ShowCursor(SDL_DISABLE);
- SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE);
graphics.registerEngine(&engine);
graphics.mapColors();