Skip to content

Instantly share code, notes, and snippets.

@acdimalev
Created May 2, 2010 20:39
Show Gist options
  • Save acdimalev/387427 to your computer and use it in GitHub Desktop.
Save acdimalev/387427 to your computer and use it in GitHub Desktop.
steer = 0;
gas = 0;
/* Input */
// Xbox 360 Controller
steer = steer - SDL_JoystickGetAxis(joystick, 0) / 32768.0;
gas = gas + ( SDL_JoystickGetAxis(joystick, 4) / 32768.0 + 1 ) / 2.0;
// Keyboard
steer = steer + keystate[SDLK_LEFT];
steer = steer - keystate[SDLK_RIGHT];
gas = gas + keystate[SDLK_UP];
/* Normalization */
if (steer < -1) { steer = -1; }
if (steer > 1) { steer = 1; }
if (gas > 1) { gas = 1; }
/* Physics */
tvel = tvel + steer * taccel*2*M_PI / fps;
vel[0] = vel[0] + gas * accel * -sin(t) / fps;
vel[1] = vel[1] + gas * accel * cos(t) / fps;
t = t + tvel / fps;
pos[0] = pos[0] + vel[0] / fps;
pos[1] = pos[1] + vel[1] / fps;
tvel = tvel * pow(1.0 - tdrag, 1.0/fps);
vel[0] = vel[0] * pow(1.0 - drag, 1.0/fps);
vel[1] = vel[1] * pow(1.0 - drag, 1.0/fps);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment