CuppyBoi

Colour Reaction Time Code

Jul 21st, 2020
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. pico-8 cartridge // http://www.pico-8.com
  2. version 29
  3. __lua__
  4. --main functions
  5. poke(0x5f2d,1)
  6.  
  7. --chooses what scene to load
  8. state="menu"
  9. --makes key presses work
  10. press=false
  11. spacebar="false"
  12. warning=false
  13. count=0
  14. --decides when colour appears
  15. timer=0
  16. appear=""
  17. --chooses the colour that appears
  18. scrn_col_val=""
  19. scrn_col_tbl={8,11,12}
  20. col_decide=0
  21. --stores the times for each colour
  22. red={}
  23. blue={}
  24. green={}
  25. red_avrg=0
  26. blu_avrg=0
  27. grn_avrg=0
  28.  
  29. function _update60()
  30.  
  31. if stat(31)==" " then
  32. press=true
  33. else
  34. press=false
  35. end
  36.  
  37. --state transitions
  38. if state=="menu" and press==true then
  39. state="pre-warmup"
  40. end
  41. if state=="pre-warmup" and timer==300 then
  42. state="warmup"
  43. timer=0
  44. appear=flr(rnd(150))+150
  45. end
  46. if state=="warmup" and count==3 then
  47. state="pre-test"
  48. spacebar="false"
  49. timer=0
  50. end
  51. if state=="pre-test" and press==true and timer>140 then
  52. state="countdown"
  53. timer=181
  54. end
  55. if state=="countdown" and timer==300 then
  56. state="test"
  57. timer=0
  58. spacebar="false"
  59. end
  60. if state=="test" and count==18 then
  61. for i=1,5 do
  62. red_avrg+=red[i]
  63. blu_avrg+=blue[i]
  64. grn_avrg+=green[i]
  65. end
  66. state="results"
  67. spacebar="false"
  68. end
  69.  
  70. --timer
  71. if state!="menu" then
  72. timer+=1
  73. end
  74.  
  75. end
  76.  
  77. function _draw()
  78. if spacebar=="false" and state=="test" or spacebar=="false" and state=="warmup" then
  79. cls(7)
  80. else
  81. cls(1)
  82. end
  83. textprint()
  84. if state=="results" then
  85. results()
  86. end
  87.  
  88. --screen colouring
  89. if press==true and spacebar=="false" then
  90. if state=="warmup" or state=="test" then
  91. warning=true
  92. spacebar="start"
  93. appear=flr(rnd(150))+150
  94. press=false
  95. end
  96. end
  97. if timer==appear and spacebar=="false" then
  98. if state=="warmup" then
  99. scrn_col_val=0
  100. end
  101. if state=="test" then
  102. if #scrn_col_tbl==0 then
  103. for x in all({8,11,12}) do
  104. add(scrn_col_tbl,x)
  105. end
  106. end
  107. col_decide=flr(rnd(#scrn_col_tbl))+1
  108. scrn_col_val=scrn_col_tbl[col_decide]
  109. end
  110. if state!="pre-test" then
  111. spacebar="stop"
  112. end
  113. end
  114. if press==true and spacebar=="stop" then
  115. if state=="test" then
  116. if scrn_col_tbl[col_decide]==8 then
  117. add(red,timer-appear)
  118. elseif scrn_col_tbl[col_decide]==11 then
  119. add(green,timer-appear)
  120. elseif scrn_col_tbl[col_decide]==12 then
  121. add(blue,timer-appear)
  122. end
  123. del(scrn_col_tbl,scrn_col_tbl[col_decide])
  124. end
  125. scrn_col_val=""
  126. spacebar="start"
  127. appear=flr(rnd(150))+150
  128. count+=1
  129. press=false
  130. end
  131.  
  132. if scrn_col_val!="" then
  133. rectfill(0,0,127,127,scrn_col_val)
  134. end
  135.  
  136. if spacebar=="start" then
  137. if press==true then
  138. timer=0
  139. spacebar="false"
  140. warning=false
  141. end
  142. if count<18 then
  143. if warning==false then
  144. print("good job!",47,48,6)
  145. print("for the next one!",29,76,6)
  146. elseif warning==true then
  147. print("try not to press space before\nthe colour appears",5,48,6)
  148. end
  149. print("press space when you're ready",5,70,6)
  150. end
  151. end
  152. --[[debug
  153. for i=1,#green do
  154. print(green[i],1,1+i*6,10)
  155. end
  156. for i=1,#red do
  157. print(red[i],11,1+i*6,10)
  158. end
  159. for i=1,#blue do
  160. print(blue[i],21,1+i*6,10)
  161. end
  162. print(state,5,110,8)
  163. print(count,5,116,8)
  164. print(timer,5,122,8)
  165. print(appear,18,122,8)]]
  166. end
  167. -->8
  168. --text printers
  169. function textprint()
  170. if state=="menu" then
  171. print("for this test, you must press\nthe the spacebar as soon as\nthe screen changes\ncolour.",5,25,6)
  172. print("this test will take around 2-3\nminutes",5,65,6)
  173. print("press spacebar to begin!",13,92,6)
  174. elseif state=="pre-warmup" or state=="countdown" then
  175. if timer<181 then
  176. print("first, let's warm you up",17,54,6)
  177. print("get ready",47,66,6)
  178. end
  179. if timer>180 then
  180. print("three",53,51,6)
  181. end
  182. if timer>210 then
  183. print("two",57,57,6)
  184. end
  185. if timer>240 then
  186. print("one",57,63,6)
  187. end
  188. if timer>270 then
  189. print("go!",57,69,6)
  190. end
  191. elseif state=="pre-test" then
  192. print("now for the real test, make\nsure to press as quick as\npossible for accuracy.",5,33,6)
  193. if timer>139 then
  194. print("press spacebar to begin!",13,82,6)
  195. end
  196. end
  197. end
  198. -->8
  199. --results screen
  200. function results()
  201. print("thank you for participating in\nthis experiment! your results\nmean a hell of a lot to me.\nnow let me have a looksie at\nthese results.",5,25,6)
  202. for i=1,7 do
  203. line(i*18-2,70,i*18-2,102,13)
  204. end
  205. for i=1,5 do
  206. line(2,i*8+62,124,i*8+62,13)
  207. print("try"..i,i*18,72,6)
  208. print(round2dp(red[i]/60),i*18,80,7)
  209. print(round2dp(blue[i]/60),i*18,88,7)
  210. print(round2dp(green[i]/60),i*18,96,7)
  211. end
  212. line(2,70,2,102,13)
  213. rect(2,70,15,77,1)
  214. print("red",4,80,6)
  215. print("blu",4,88,6)
  216. print("grn",4,96,6)
  217. print("avrg",108,72,6)
  218. print(round2dp(red_avrg/300),108,80,7)
  219. print(round2dp(blu_avrg/300),108,88,7)
  220. print(round2dp(grn_avrg/300),108,96,7)
  221. end
  222. -->8
  223. --calculator functions
  224. function round2dp(x)
  225. return flr(x*100+0.5)/100
  226. end
  227. __gfx__
  228. 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  229. 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  230. 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  231. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  232. 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  233. 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Advertisement
Add Comment
Please, Sign In to add comment