Skip to content

Commit

Permalink
Fixed RGJ04
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven-Hendrik Haase committed Oct 20, 2011
1 parent 9dc980b commit ec07113
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions RGJ04/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default:
g++ -O3 -Wall -Wextra -lsfml-graphics -lsfml-window -lsfml-system -I/usr/include/bullet -lBulletCollision -lBulletDynamics src/*.cpp -opolymorphosis.bin
g++ -O3 -Wall -Wextra -Werror -Wno-unused-parameter -std=c++0x -lsfml-graphics -lsfml-window -lsfml-system -I/usr/include/bullet -lBulletCollision -lBulletDynamics src/*.cpp -opolymorphosis.bin

debug:
g++ -g -pg -lprofiler -Wall -Wextra -lsfml-graphics -lsfml-window -lsfml-system -I/usr/include/bullet -lBulletCollision -lBulletDynamics src/*.cpp -opolymorphosis.bin
g++ -g -Wall -Wextra -Werror -Wno-unused-parameter -std=c++0x -lsfml-graphics -lsfml-window -lsfml-system -I/usr/include/bullet -lBulletCollision -lBulletDynamics src/*.cpp -opolymorphosis.bin
20 changes: 9 additions & 11 deletions RGJ04/src/GameApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,45 +204,43 @@ void GameApp::Init() {

void GameApp::Run() {
while(mRenderWin->IsOpened()) {
while(mRenderWin->GetEvent(mEvent)) {
while(mRenderWin->PollEvent(mEvent)) {
if(mEvent.Type == sf::Event::Closed)
mRenderWin->Close();
if(mEvent.Type == sf::Event::KeyPressed) {
if(mEvent.Key.Code == sf::Key::Escape)
if(mEvent.Key.Code == sf::Keyboard::Escape)
mRenderWin->Close();
}
}

float time_delta = mClock.GetElapsedTime();
//float time_delta = mClock.GetElapsedTime();
mClock.Reset();

// SFML access class for real-time input
const sf::Input& input = mRenderWin->GetInput();
// get the current "frame time" (seconds elapsed since the previous frame, hopefully close to 1/60 since vsync is enabled)
float frameTime = mRenderWin->GetFrameTime();
//float frameTime = mRenderWin->GetFrameTime();

//step the Box2D physics world, with a constant time step
//note that this is kind of a bad way to do time steps, as it can get out of sync if the framerate drops (see http://gafferongames.wordpress.com/game-physics/fix-your-timestep/ for more information)
mDynamicsWorld->stepSimulation(1 / 60.f, 10);
mDynamicsWorld->clearForces();

//check for user keyboard input to control Bullet forces/torques/etc
float mag = 50.0f;
if(input.IsKeyDown(sf::Key::Left)) {
//float mag = 50.0f;
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Left)) {
btVector3 relative_force = btVector3(0, 0, -2);
mPlayerBody->applyTorque(relative_force);
}
if(input.IsKeyDown(sf::Key::Right)) {
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Right)) {
btVector3 relative_force = btVector3(0, 0, 2);
mPlayerBody->applyTorque(relative_force);
}
if(input.IsKeyDown(sf::Key::Up)) {
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Up)) {
btVector3 relativeForce = btVector3(0, 5, 0);
btMatrix3x3& boxRot = mPlayerBody->getWorldTransform().getBasis();
btVector3 correctedForce = boxRot * relativeForce;
mPlayerBody->applyCentralForce(correctedForce);
}
if(input.IsKeyDown(sf::Key::Down)) {
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Down)) {
btVector3 relativeForce = btVector3(0, -2, 0);
btMatrix3x3& boxRot = mPlayerBody->getWorldTransform().getBasis();
btVector3 correctedForce = boxRot * relativeForce;
Expand Down

0 comments on commit ec07113

Please sign in to comment.