Package game.habits

Source Code of game.habits.GravityHabit

package game.habits;

import engine.geometry.Vector;
import engine.hierarchy.DefaultHabit;
import engine.interfaces.Clock;
import engine.interfaces.Keyboard;
import engine.interfaces.Mouse;

/**
* Applies a constant downward impulse relative to the mass.
*/
public class GravityHabit extends DefaultHabit {
    private static final double GRAVITY = 0.125;
    DynamicHabit dynamic;

    public GravityHabit(DynamicHabit dynamic) {
        this.dynamic = dynamic;
    }

    @Override
    protected void onBeforeMove(Keyboard keyboard, Mouse mouse, Clock clock) {
        dynamic.applyImpulse(new Vector(0, dynamic.getMass() * GRAVITY));
    }
}
TOP

Related Classes of game.habits.GravityHabit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.