Package game.habits

Source Code of game.habits.DynamicHabit

package game.habits;

import engine.geometry.Polygon;
import engine.geometry.Rectangle;
import engine.geometry.Vector;
import engine.hierarchy.DefaultHabit;
import engine.utility.Physics;
import game.scenes.LevelScene;

public class DynamicHabit extends DefaultHabit {
    private double mass;
    private Polygon polygon;
    private Vector velocity;

    public DynamicHabit(final Polygon polygon, final double mass) {
        this.polygon = polygon;
        this.mass = mass;
        this.velocity = new Vector(0, 0);
    }

    public final void applyImpulse(final Vector impulse) {
        Vector deltaVelocity = new Vector(impulse);
        deltaVelocity.divide(mass);
        velocity.add(deltaVelocity);
    }
   
    public final void addVelocity(final Vector deltaVelocity) {
        velocity.add(deltaVelocity);
    }
   
    public final double getMass() {
        return mass;
    }

    public final Polygon getPolygon() {
        return polygon;
    }

    public final Vector getVelocity() {
        return velocity;
    }

    @Override
    public final void onMove() {
        Physics.move(((LevelScene) getScene()).getBlocks(), polygon, velocity);
    }

    public final boolean onGround() {
        Rectangle check = new Rectangle(polygon.getMinX(), polygon.getMaxY(), polygon.getMaxX() - polygon.getMinX(), 1);
        return Physics.intersects(((LevelScene) getScene()).getBlocks(), check.toPolygon());
    }
}
TOP

Related Classes of game.habits.DynamicHabit

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.