Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1.     #Simulates movement of an entity to point (x, y) assuming no collision
  2.     def simulate(self, x, y, throttle):
  3.         #Known bugs:
  4.         #ZeroDivisionError when moving to position the entity is currently at
  5.        
  6.         #Used to negate distance and accelerate faster for entities with less mass
  7.         coef    = throttle / self.mass / pythagoras(self, (x, y))
  8.         VX      = self.vx + (x - self.x) * coef     #Speed in x direction after applying thrust
  9.         VY      = self.vy + (y - self.y) * coef     #Speed in y direction after applying thrust
  10.        
  11.         X       = self.x + VX                       #X coordinate after moving
  12.         Y       = self.y + VY                       #Y coordinate after moving
  13.        
  14.         VXF     = VX * (1-self.friction)            #Speed in x direction after applying friction
  15.         VYF     = VY * (1-self.friction)            #Speed in y direction after applying friction
  16.        
  17.         return (round(X), round(Y), round(VXF), round(VYF), VX, VY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement