Difference between revisions of "Ball Friction"

From ASSS Wiki
Jump to: navigation, search
m (oops, fixed mistake when I was tidying up the code)
m (renamed a variable to make it more obvious)
Line 2: Line 2:
 
fireball()
 
fireball()
 
{
 
{
   ball.workfriction = 1000000;
+
   ball.frictiontimer = 1000000;
 
}
 
}
  
Line 10: Line 10:
 
   if (ball.xspeed && ball.yspeed)
 
   if (ball.xspeed && ball.yspeed)
 
   {
 
   {
       int workfriction = ball.workfriction / 1000;
+
       int workfriction = ball.frictiontimer / 1000;
 
       ball.xspeed = ball.xspeed * workfriction / 1000;
 
       ball.xspeed = ball.xspeed * workfriction / 1000;
 
       ball.yspeed = ball.yspeed * workfriction / 1000;
 
       ball.yspeed = ball.yspeed * workfriction / 1000;
  
       ball.workfriction -= cfg_friction;
+
       ball.frictiontimer -= cfg_friction;
       if (ball.workfriction < 0)
+
       if (ball.frictiontimer < 0)
         ball.workfriction = 0;
+
         ball.frictiontimer = 0;
 
   }
 
   }
 
}
 
}
 
</pre>
 
</pre>

Revision as of 12:00, 9 March 2008

fireball()
{
   ball.frictiontimer = 1000000;
}

// call this per tick
updateball()
{
   if (ball.xspeed && ball.yspeed)
   {
      int workfriction = ball.frictiontimer / 1000;
      ball.xspeed = ball.xspeed * workfriction / 1000;
      ball.yspeed = ball.yspeed * workfriction / 1000;

      ball.frictiontimer -= cfg_friction;
      if (ball.frictiontimer < 0)
         ball.frictiontimer = 0;
   }
}