Package game.habits

Source Code of game.habits.ClickHabit$Listener

package game.habits;

import engine.geometry.Point;
import engine.geometry.Rectangle;
import engine.hierarchy.DefaultHabit;
import engine.interfaces.Clock;
import engine.interfaces.Keyboard;
import engine.interfaces.Mouse;
import engine.interfaces.Mouse.Button;
import engine.utility.Geometry;

public class ClickHabit extends DefaultHabit {
    public interface Listener {
        void onClick(ClickHabit button);
    }

    private Listener listener;
    private Rectangle bounds;

    public ClickHabit(final Listener listener, final Rectangle bounds) {
        this.listener = listener;
        this.bounds = bounds;
    }

    @Override
    public void onBeforeMove(final Keyboard keyboard, final Mouse mouse, final Clock clock) {
        Point mousePos = new Point(mouse.getX(), mouse.getY());

        if (mouse.wasReleased(Button.MB_LEFT) && Geometry.pointIntersectsRectangle(mousePos, bounds)) {
            if (listener != null) {
                listener.onClick(this);
            }
        }
    }
}
TOP

Related Classes of game.habits.ClickHabit$Listener

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.