16
Graphics / RenderTexture Speed
« on: October 09, 2011, 04:49:34 pm »
Ah I misunderstood his question. I thought he meant drawing to a RenderTexture, not creating it.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Mod, please lock this thread
void Mario::Update()
{
// assume velocity is a sf::Vector2f
// jump
if( PlayerPressedJumpButton() && MarioIsOnTheGround() )
{
velocity.y -= jump_speed; // higher value = higher jump
}
// move left/right
if(PlayerWantsToMoveLeft())
{
velocity.x -= move_speed; // higher value = faster accelleration
// but not higher top-speed. Note you can have
// different values here for when mario is on the ground vs. on ice
// vs. in the air. Example the accelleration might be low when in the
// air vs. high when on the ground
if(velocity.x < -topspeed) // higher value = higher top speed
velocity.x = -topspeed;
}
if(PlayerWantsToMoveRight())
{
velocity.x += move_speed;
if(velocity.x > topspeed)
velocity.x = topspeed;
}
// gravity
if(!MarioIsOnTheGround())
{
velocity.y += gravity; // higher value = more gravity
}
// slow the player down if they are not moving
if(!PlayerWantsToMoveLeft() && !PlayerWantsToMoveRight())
{
if(velocity.x < 0)
{
velocity.x += slowdown; // higher value = quicker slowdown
// again, air, ice, ground can have different values. You could
// also just use move_speed for this I suppose
if(velocity.x > 0) // stop
velocity.x = 0;
}
else
{
velocity.x -= slowdown;
if(velocity.x < 0)
velocity.x = 0;
}
}
// terminal velocity
if(velocity.y > terminalvelocity)
velocity.y = terminalvelocity; // the highest speed at which you can fall
// move Mario
MoveMario( velocity );
DoCollisionDetectionAndStuff();
// note you might want the collision detection to alter the velocity.
// for example set velocity.y to zero if you hit a floor/ceiling, or
// velocity.x to zero if you move into a wall. Or multiply them by
// a negative constant to "bounce off" a rubber wall or something.
}
You should also make operators non-member functions as much as possible,
I would use global functions for + and - operators.