Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. package com.kharin.evolution.world.klib;
  2.  
  3. /**
  4.  * Created by AlexKharin on 20.02.17.
  5.  */
  6.  
  7. public class KTimer {
  8.     private float maxTimerValue = 1;
  9.     private float timerValue = maxTimerValue;
  10.     private TimerListener listener;
  11.     private boolean isStop;
  12.  
  13.     public KTimer(float maxTimerValue, boolean isStop, TimerListener listener) {
  14.         this.maxTimerValue = maxTimerValue;
  15.         this.timerValue = maxTimerValue;
  16.         this.listener = listener;
  17.         this.isStop = isStop;
  18.     }
  19.  
  20.     public void stop() {
  21.         isStop = true;
  22.     }
  23.  
  24.     public void start() {
  25.         isStop = false;
  26.     }
  27.  
  28.     public void update(float delta) {
  29.         if (isStop) return;
  30.         if (timerValue <= 0) {
  31.             timerValue = maxTimerValue;
  32.             if (listener != null) listener.onFinish();
  33.         }
  34.         timerValue -= delta;
  35.     }
  36.  
  37.     public void reset() {
  38.         this.timerValue = maxTimerValue;
  39.     }
  40.  
  41.     public void finish() {
  42.         this.timerValue = 0;
  43.         if (listener != null)
  44.             listener.onFinish();
  45.     }
  46.  
  47.     public float getTimerValue() {
  48.         return timerValue;
  49.     }
  50.  
  51.     public void setTimerValue(float val) {
  52.         this.timerValue = val;
  53.     }
  54.  
  55.     public void setMaxTimerValue(float maxTimerValue) {
  56.         this.maxTimerValue = maxTimerValue;
  57.     }
  58.  
  59.     public float getProgress() {
  60.         return timerValue / maxTimerValue;
  61.     }
  62.  
  63.     public interface TimerListener {
  64.         void onFinish();
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement