vehicles.nim 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import
  2. sfml, chipmunk,
  3. sg_assets, sfml_stuff#, "../keineschweine"
  4. proc accel*(obj: PVehicle, dt: float) =
  5. #obj.velocity += vec2f(
  6. # cos(obj.angle) * obj.record.handling.thrust.float * dt,
  7. # sin(obj.angle) * obj.record.handling.thrust.float * dt)
  8. obj.body.applyImpulse(
  9. vectorForAngle(obj.body.getAngle()) * dt * obj.record.handling.thrust,
  10. VectorZero)
  11. proc reverse*(obj: PVehicle, dt: float) =
  12. #obj.velocity += vec2f(
  13. # -cos(obj.angle) * obj.record.handling.reverse.float * dt,
  14. # -sin(obj.angle) * obj.record.handling.reverse.float * dt)
  15. obj.body.applyImpulse(
  16. -vectorForAngle(obj.body.getAngle()) * dt * obj.record.handling.reverse,
  17. VectorZero)
  18. proc strafe_left*(obj: PVehicle, dt: float) =
  19. obj.body.applyImpulse(
  20. vectorForAngle(obj.body.getAngle()).perp() * obj.record.handling.strafe * dt,
  21. VectorZero)
  22. proc strafe_right*(obj: PVehicle, dt: float) =
  23. obj.body.applyImpulse(
  24. vectorForAngle(obj.body.getAngle()).rperp() * obj.record.handling.strafe * dt,
  25. VectorZero)
  26. proc turn_right*(obj: PVehicle, dt: float) =
  27. #obj.angle = (obj.angle + (obj.record.handling.rotation.float / 10.0 * dt)) mod TAU
  28. obj.body.setTorque(obj.record.handling.rotation)
  29. proc turn_left*(obj: PVehicle, dt: float) =
  30. #obj.angle = (obj.angle - (obj.record.handling.rotation.float / 10.0 * dt)) mod TAU
  31. obj.body.setTorque(-obj.record.handling.rotation)
  32. proc offsetAngle*(obj: PVehicle): float {.inline.} =
  33. return (obj.record.anim.angle + obj.body.getAngle())