summary refs log tree commit diff stats
path: root/src/systems/pondering.cpp
blob: e40db1d5eb6dc1e60e4e1258d059b1fd688a4691 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "pondering.h"
#include "game.h"
#include "components/ponderable.h"
#include "components/transformable.h"

void PonderingSystem::tick(double dt)
{
  auto entities = game_.getEntityManager().getEntitiesWithComponents<
    PonderableComponent,
    TransformableComponent>();

  for (id_type entity : entities)
  {
    auto& transformable = game_.getEntityManager().getComponent<TransformableComponent>(entity);
    auto& ponderable = game_.getEntityManager().getComponent<PonderableComponent>(entity);

    // Accelerate
    ponderable.setVelocityX(ponderable.getVelocityX() + ponderable.getAccelX() * dt);
    ponderable.setVelocityY(ponderable.getVelocityY() + ponderable.getAccelY() * dt);

    // Move
    transformable.setX(transformable.getX() + ponderable.getVelocityX() * dt);
    transformable.setY(transformable.getY() + ponderable.getVelocityY() * dt);
  }
}