Entity.cpp 511 B

123456789101112131415161718192021
  1. #include "Entity.h"
  2. Entity::Entity(const Vector2& size, float mass)
  3. : size(size), inverseMass(1.0f / mass), onGround(false), jumpTicks(0) {
  4. }
  5. void Entity::addForce(const Vector2& force) {
  6. acceleration += force * inverseMass;
  7. }
  8. void Entity::preTick() {
  9. lastPosition = position;
  10. // start off with gravity for the next frame
  11. acceleration = Vector2(0.0f, -0.5f);
  12. }
  13. void Entity::tick() {
  14. // euler integration, timestep is constant
  15. velocity += acceleration;
  16. position += velocity;
  17. }