Advertisement
Demintika

RPGM VX Ace - DMTK Analog Clock

Feb 3rd, 2015
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.19 KB | None | 0 0
  1. #==============================================================================
  2. # * Config
  3. #==============================================================================
  4. module Clock
  5.   #--------------------------------------------------------------------------
  6.   # |0       1|
  7.   # |         |
  8.   # |         |
  9.   # |2       3|
  10.   #--------------------------------------------------------------------------
  11.   @position = 0
  12.   #--------------------------------------------------------------------------
  13.   # You can change position later with Clock.position = new-position
  14.   # Example: Clock.position = 2
  15.   #--------------------------------------------------------------------------
  16. #==============================================================================
  17. # * Config Ends.
  18. #==============================================================================
  19.   #--------------------------------------------------------------------------
  20.   # *
  21.   #--------------------------------------------------------------------------
  22.   def self.position=(pos)
  23.     @position = pos
  24.     @clock.x, @clock.ox, @clock.y, @clock.oy = *clock_pos
  25.   end
  26.  
  27.   #--------------------------------------------------------------------------
  28.   # *
  29.   #--------------------------------------------------------------------------
  30.   def self.clock_pos
  31.     x = @position % 2 == 0 ? 0 : Graphics.width
  32.     ox = x == 0 ? 0 : 50
  33.     y = @position / 2 == 0 ? 0 : Graphics.height
  34.     oy = y == 0 ? 0 : 24
  35.     return x, ox, y, oy
  36.   end
  37.  
  38.   #--------------------------------------------------------------------------
  39.   # *
  40.   #--------------------------------------------------------------------------
  41.   def self.start
  42.     @clock = Sprite.new
  43.     @clock.z = 1000
  44.     @clock.x, @clock.ox, @clock.y, @clock.oy = *clock_pos
  45.     @bitmap = Bitmap.new(50,24)
  46.     @clock.bitmap = @bitmap
  47.   end
  48.  
  49.   #--------------------------------------------------------------------------
  50.   # *
  51.   #--------------------------------------------------------------------------
  52.   def self.update
  53.     time = Time.now
  54.     tick = (time.sec % 2 == 0) ? " " : ":"
  55.     return if @tick == tick
  56.     @tick = tick
  57.     text = sprintf("%02d%s%02d", time.hour, tick, time.min)
  58.     @bitmap.clear
  59.     @bitmap.draw_text(0,0,50,24,text)
  60.   end
  61.  
  62.   #--------------------------------------------------------------------------
  63.   # *
  64.   #--------------------------------------------------------------------------
  65.   def self.stop
  66.     @clock.visible = false
  67.     @updater.stop
  68.   end
  69.  
  70.   #--------------------------------------------------------------------------
  71.   # *
  72.   #--------------------------------------------------------------------------
  73.   def self.run
  74.     @clock.visible = true
  75.     @updater.run
  76.   end
  77.  
  78.   #--------------------------------------------------------------------------
  79.   # *
  80.   #--------------------------------------------------------------------------
  81.   start
  82.   unless @updater
  83.   @updater = Thread.new {
  84.     loop do
  85.       sleep(0.1)
  86.       Clock.update rescue start
  87.     end
  88.   }
  89.   end
  90. end
  91. #==============================================================================
  92. # *
  93. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement