Advertisement
ssccsscc

Timer

May 31st, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | None | 0 0
  1. timert=0
  2. xc=5
  3. fp=1
  4. yc=5
  5. pause=0
  6. setup=0
  7. pauseonend=0
  8. togg=100
  9. togr=255
  10. buttoni={}
  11.  
  12.  
  13. function timer()
  14. if timert==1 then
  15. timert=0
  16. else
  17. timert=1
  18. end
  19. end
  20.  
  21. function click(mousex, mousey, button, event)
  22. if timert==0 then
  23. return
  24. end
  25.     for i=1, table.getn(buttoni) do
  26.                    if (mousex>=buttoni[i][1]) and (mousex<=buttoni[i][1]+buttoni[i][3]) and (mousey>=buttoni[i][2]) and (mousey<=buttoni[i][2]+buttoni[i][4]) and (button==1) then
  27.                             if event==3 then
  28.                                   graphics.fillRect(buttoni[i][1], buttoni[i][2], buttoni[i][3], buttoni[i][4], buttoni[i][5], buttoni[i][6], buttoni[i][7])
  29.                                   p=1
  30.                           end
  31.                           if (event==2) and (p==1) then
  32.                                  p=0
  33.                                     buttoni[i][8]()
  34.                             end
  35.                   end
  36. end
  37. end
  38. tpt.register_mouseclick(click)
  39.  
  40. function button(id,x,y,w,h,c,r,g,b,action)
  41.     buttoni[id]={}
  42.     buttoni[id][1]=x
  43.     buttoni[id][2]=y
  44.     buttoni[id][3]=w
  45.     buttoni[id][4]=h
  46.     buttoni[id][5]=r
  47.     buttoni[id][6]=g
  48.     buttoni[id][7]=b
  49.     buttoni[id][8]=action
  50.         graphics.drawRect(x, y, w, h, r, g, b)
  51.         k=string.len(c)*4+string.len(c)-1
  52.         graphics.drawText(x+(w-k)/2, y+(h-7)/2, c,1,1,1)
  53.         if (tpt.mousex>=x) and (tpt.mousex<=x+w) and (tpt.mousey>=y) and (tpt.mousey<=y+h) then
  54.                 graphics.fillRect(x, y, w, h, r, g, b,50)
  55.         end
  56. end
  57.  
  58. function start()
  59. setup=1
  60. if pause==1 then
  61. anot=ti+os.time()
  62. pause=0
  63. else
  64. anot=os.time()+s2+s1*10+m2*60+m1*600
  65. end
  66. end
  67.  
  68. function stopp()
  69. pause=1
  70. ptime=os.time()
  71. end
  72.  
  73. function reset()
  74. setup=0
  75. end
  76.  
  77. function m1p()
  78. if m1<6 then
  79. m1=m1+1
  80. end
  81. if m1==6 then
  82. m2=0
  83. end
  84. end
  85.  
  86. function m1m()
  87. if m1>0 then
  88. m1=m1-1
  89. end
  90. end
  91.  
  92. function m2p()
  93. if m2==9 then
  94. m1p()
  95. m2=0
  96. else
  97. if m1~=6 then
  98. m2=m2+1
  99. end
  100. end
  101. end
  102.  
  103. function m2m()
  104. if m2>0 then
  105. m2=m2-1
  106. else
  107. if m1>0 then
  108. m1m()
  109. m2=9
  110. end
  111. end
  112. end
  113.  
  114. function s1p()
  115. if s1<6 then
  116. s1=s1+1
  117. end
  118. if s1==6 then
  119. s2=0
  120. end
  121. end
  122.  
  123. function s1m()
  124. if s1>0 then
  125. s1=s1-1
  126. end
  127. end
  128.  
  129. function s2p()
  130. if s2==9 then
  131. s1p()
  132. s2=0
  133. else
  134. if s1~=6 then
  135. s2=s2+1
  136. end
  137. end
  138. end
  139.  
  140. function s2m()
  141. if s2>0 then
  142. s2=s2-1
  143. else
  144. if s1>0 then
  145. s1m()
  146. s2=9
  147. end
  148. end
  149. end
  150.  
  151. function endaction()
  152. if pauseonend==1 then
  153. tpt.set_pause(1)
  154. end
  155. end
  156.  
  157. function togpause()
  158. if pauseonend==0 then
  159. pauseonend=1
  160. togg=255
  161. togr=100
  162. else
  163. pauseonend=0
  164. togg=100
  165. togr=255
  166. end
  167. end
  168.  
  169. function press(mousex, mousey, button, event)
  170. if ((button==1) and (event==1)) and (((mousex<xc) or (mousex>100+xc)) or ((mousey<yc) or (mousey>4+yc))) then
  171. fp=0
  172. end
  173. if (button==1) and (event==1) and (mousex>=xc) and (mousex<=100+xc) and (mousey>=yc) and (mousey<=4+yc) then
  174. fp=1
  175. fx=mousex-xc
  176. fy=mousey-yc
  177. end
  178. if (button==1) and (event==3) and (fp==1) then
  179. if (mousex-fx<0) or (mousex-fx>512) then
  180. if mousex-fx<0 then
  181. xc=0
  182. else
  183. xc=512
  184. end
  185. else
  186. xc=mousex-fx
  187. end
  188. if (mousey-fy>353) or (mousey-fy<-1) then
  189. if mousey-fy>353 then
  190. yc=353
  191. else
  192. yc=-1
  193. end
  194. else
  195. yc=mousey-fy
  196. end
  197. end
  198. end
  199. tpt.register_mouseclick(press)
  200. m1=0
  201. m2=0
  202. s1=0
  203. s2=0
  204.  
  205. function image()
  206. if (setup==1) and (pause==0) then
  207. ti=os.difftime(anot,os.time())
  208. if ti==0 then
  209. setup=0
  210. endaction()
  211. end
  212. end
  213. if (setup==0) and (pause==0) then
  214. ti=0
  215. end
  216. if timert==0 then
  217. return
  218. end
  219. graphics.fillRect(xc,yc,100,50)
  220. graphics.fillRect(xc,yc,100,5,150,150,255)
  221. graphics.drawText(xc+12,yc+10,os.date("%M:%S",ti),1,1,1)
  222. button(1,xc+1,yc+35,33,12,'start',100,255,100,start)
  223. button(2,xc+36,yc+35,28,12,'pause',200,200,100,stopp)
  224. button(3,xc+66,yc+35,33,12,'reset',255,100,100,reset)
  225. button(12,xc+1,yc+20,52,12,'auto pause',togr,togg,100,togpause)
  226. graphics.drawText(xc+55,yc+15,m1,1,1,1)
  227. graphics.drawText(xc+65,yc+15,m2,1,1,1)
  228. graphics.drawText(xc+80,yc+15,s1,1,1,1)
  229. graphics.drawText(xc+90,yc+15,s2,1,1,1)
  230. button(4,xc+54,yc+6,8,8,'+',100,100,200,m1p)
  231. button(5,xc+54,yc+23,8,8,'-',100,100,200,m1m)
  232. button(6,xc+64,yc+6,8,8,'+',100,100,200,m2p)
  233. button(7,xc+64,yc+23,8,8,'-',100,100,200,m2m)
  234. button(8,xc+79,yc+6,8,8,'+',100,100,200,s1p)
  235. button(9,xc+79,yc+23,8,8,'-',100,100,200,s1m)
  236. button(10,xc+89,yc+6,8,8,'+',100,100,200,s2p)
  237. button(11,xc+89,yc+23,8,8,'-',100,100,200,s2m)
  238. end
  239. tpt.register_step(image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement