Java tutorial
/* * Copyright (C) 2016 Saltosion * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNUss General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.saltosion.pixelprophecy.systems; import com.badlogic.ashley.core.ComponentMapper; import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Family; import com.badlogic.ashley.systems.IteratingSystem; import com.badlogic.gdx.math.Vector2; import org.saltosion.pixelprophecy.Comp; public class MovementSystem extends IteratingSystem { private ComponentMapper<Comp.Physics> pm = ComponentMapper.getFor(Comp.Physics.class); public MovementSystem() { super(Family.all(Comp.Physics.class).get()); } @Override protected void processEntity(Entity entity, float deltaTime) { Comp.Physics physics = pm.get(entity); Vector2 dir = physics.destination.cpy().nor(); physics.body.setLinearVelocity(dir.scl(physics.speed)); } }