Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kharin.evolution.world.klib;
- /**
- * Created by AlexKharin on 20.02.17.
- */
- public class KTimer {
- private float maxTimerValue = 1;
- private float timerValue = maxTimerValue;
- private TimerListener listener;
- private boolean isStop;
- public KTimer(float maxTimerValue, boolean isStop, TimerListener listener) {
- this.maxTimerValue = maxTimerValue;
- this.timerValue = maxTimerValue;
- this.listener = listener;
- this.isStop = isStop;
- }
- public void stop() {
- isStop = true;
- }
- public void start() {
- isStop = false;
- }
- public void update(float delta) {
- if (isStop) return;
- if (timerValue <= 0) {
- timerValue = maxTimerValue;
- if (listener != null) listener.onFinish();
- }
- timerValue -= delta;
- }
- public void reset() {
- this.timerValue = maxTimerValue;
- }
- public void finish() {
- this.timerValue = 0;
- if (listener != null)
- listener.onFinish();
- }
- public float getTimerValue() {
- return timerValue;
- }
- public void setTimerValue(float val) {
- this.timerValue = val;
- }
- public void setMaxTimerValue(float maxTimerValue) {
- this.maxTimerValue = maxTimerValue;
- }
- public float getProgress() {
- return timerValue / maxTimerValue;
- }
- public interface TimerListener {
- void onFinish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement