All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.mostlyoriginal.api.system.physics.GravitySystem Maven / Gradle / Ivy

The newest version!
package net.mostlyoriginal.api.system.physics;

import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Wire;
import com.artemis.systems.EntityProcessingSystem;
import com.artemis.systems.IteratingSystem;
import net.mostlyoriginal.api.component.physics.Gravity;
import net.mostlyoriginal.api.component.physics.Physics;

/**
 * Applies gravity on Y axis to Entity.
 *
 * @author Daan van Yperen
 * @see net.mostlyoriginal.api.component.physics.Gravity
 */
@Wire
public class GravitySystem extends IteratingSystem {

    public static final int GRAVITY_FACTOR = 50;

    ComponentMapper pm;
    ComponentMapper gm;

    public GravitySystem() {
        super(Aspect.all(Gravity.class, Physics.class));
    }

    @Override
    protected void process(int e) {
        final Physics physics = pm.get(e);
        final Gravity gravity = gm.get(e);

        physics.vy += gravity.y * GRAVITY_FACTOR * world.delta;
        physics.vx += gravity.x * GRAVITY_FACTOR * world.delta;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy