Package game.habits

Source Code of game.habits.AttractHabit

package game.habits;

import java.util.Set;

import engine.geometry.Polygon;
import engine.geometry.Vector;
import engine.hierarchy.DefaultHabit;
import engine.interfaces.Clock;
import engine.interfaces.Keyboard;
import engine.interfaces.Mouse;
import game.scenes.LevelScene;

public class AttractHabit extends DefaultHabit {
    private DynamicHabit dynamic;
    private Polygon area;

    public AttractHabit(final DynamicHabit dynamic, final Polygon area) {
        this.dynamic = dynamic;
        this.area = area;
    }

    @Override
    protected void onBeforeMove(Keyboard keyboard, Mouse mouse, Clock clock) {
        // TODO
        // - find all metal within area
        // - calculate the magnitude of the attraction / repulsion
        // - apply an impulse to the metal
        // - apply an opposite impulse to self

        Set<MetalHabit> set = ((LevelScene) getScene()).getSpace().findObjects(area, MetalHabit.class);
        for (MetalHabit m : set) {
            m.applyImpulse(new Vector(1, -1));
            dynamic.applyImpulse(new Vector(-1, 1));
        }
    }
}
TOP

Related Classes of game.habits.AttractHabit

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.