Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. objectdef gameController
  2. {
  3. ; timestamps in seconds since the script started
  4. variable float CurrentFrame
  5. variable float LastFrame
  6. variable int Difficulty = 2
  7.  
  8. ; amount of time (in seconds) elapsed since the last frame
  9. variable float FrameTime
  10.  
  11. ; constructor
  12. method Initialize()
  13. {
  14. CurrentFrame:Set[${Script.RunningTime}/1000.0]
  15. LastFrame:Set[${CurrentFrame}]
  16.  
  17. LGUI2:LoadPackageFile[day7.json]
  18. }
  19.  
  20. ; destructor
  21. method Shutdown()
  22. {
  23. LGUI2:UnloadPackageFile[day7.json]
  24. }
  25.  
  26. ; to be called by a LGUI2 "onRefresh" event handler, e.g. from the game viewer element
  27. method OnRefresh()
  28. {
  29. CurrentFrame:Set[${Script.RunningTime}/1000.0]
  30. if ${CurrentFrame.Equal[${LastFrame}]}
  31. return
  32.  
  33. FrameTime:Set[${CurrentFrame}-${LastFrame}]
  34. This:UpdateGame
  35. LastFrame:Set[${CurrentFrame}]
  36. }
  37.  
  38. ; called by OnRefresh, add game logic here. use ${This.FrameTime} to calculate any distances moved, etc.
  39. method UpdateGame()
  40. {
  41. }
  42.  
  43. method DifficultyView()
  44. {
  45. variable jsonvalue joListBoxItem = "{\"type\":\"itemview\"}"
  46. if ${Context.Args[name](exists)}
  47. joListBoxItem:Set[content,"${Context.Args[name].AsJSON.Escape}"]
  48. else
  49. joListBoxItem:Set[content,"\"\""]
  50. Context:SetView["${joListBoxItem.AsJSON.Escape}"]
  51. }
  52. }
  53.  
  54. objectdef gameBoard
  55. {
  56. variable gameTile Tiles[10,10]
  57. variable gameMouse GameMouse
  58. variable lgui2elementref BoardElement
  59.  
  60. method InitTiles()
  61. {
  62. variable int X
  63. variable int Y
  64. for (Y:Set[1];${Y}<=10;Y:Inc)
  65. {
  66. for (X:Set[1];${X}<=10;X:Inc)
  67. {
  68. This.Tiles[${Y},${X}]:Init[This, ${X}, ${Y}]
  69. }
  70. }
  71. }
  72.  
  73. method InitUI()
  74. {
  75. BoardElement:Set[${LGUI2.Element[gameBoard].ID}]
  76. This:InitTiles
  77. }
  78. }
  79.  
  80. objectdef gameTile
  81. {
  82. variable int X
  83. variable int Y
  84. variable weakref Board
  85. variable lgui2elementref TileElement
  86.  
  87. method Init (weakref _Board, int _X, int _Y)
  88. {
  89. X:Set[${_X}]
  90. Y:Set[${_Y}]
  91. Board:SetReference[_Board]
  92.  
  93. variable jsonvalue joTileView = "${LGUI2.Template[tile.Wall].AsJSON.Escape}"
  94. joTileView:Set["_ref", "\"GameBoard.Tiles[${_Y},${_X}]\""]
  95. joTileView:Set["_row", ${_Y}]
  96. joTileView:Set["_column", ${_X}]
  97. TileElement:Set[${_Board.BoardElement.AddChild["${joTileView.AsJSON.Escape}"].ID}]
  98. }
  99. }
  100.  
  101. objectdef gameMouse
  102. {
  103. variable float X = 5.5
  104. variable float Y = 5.5
  105. variable float Speed
  106. variable float Heading
  107. variable float SmellRadius
  108. variable float SightDistance
  109. variable float LastTurn
  110.  
  111. method Refresh()
  112. {
  113.  
  114. }
  115. }
  116.  
  117.  
  118. variable(global) gameController GameController
  119. variable(global) gameBoard GameBoard
  120.  
  121. function main()
  122. {
  123. GameBoard:InitUI
  124. while 1
  125. waitframe
  126. }
  127.  
  128.  
  129.  
  130.  
  131. {
  132. "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json",
  133. "templates":
  134. {
  135. "starSize":
  136. { "font": { "height": 32 } },
  137. "tile.View":
  138. { "type": "panel",
  139. "jsonTemplate": "panel",
  140. "verticalAlignment": "stretch",
  141. "horizontalAlignment": "stretch"
  142. },
  143. "tile.Wall":
  144. {
  145. "jsonTemplate": "tile.View",
  146. "backgroundBrush": "wallBrush"
  147. }
  148. },
  149. "brushes":
  150. {
  151. "wallBrush": { "color": [ 1.0 , 0.0 , 0.0 ] },
  152. "mouseBrush":
  153. { "color": [ 0.25 , 0.25 , 0.25 ],
  154. "-canvas":
  155. {
  156. "width": 64,
  157. "height": 64
  158. }
  159. },
  160. "cheeseBrush": { "color": [ 1.0 , 0.85 , 0.0 ] }
  161. },
  162. "elements":
  163. [
  164. { "type": "window",
  165. "name": "game.window",
  166. "title": "Game Options",
  167. "height": 250,
  168. "width": 400,
  169. "verticalAlignment": "center",
  170. "horizontalAlignment": "center",
  171. "content":
  172. { "type": "dockpanel",
  173. "margin": [ 10 , 10 ],
  174. "children":
  175. [ { "type": "stackpanel",
  176. "orientation": "horizontal",
  177. "horizontalContentAlignment": "left",
  178. "margin": [ 10 , 5 ],
  179. "children":
  180. [ { "type": "combobox",
  181. "minSize": [ 90, 0 ],
  182. "selectedItemBinding": "GameController.Difficulty",
  183. "selectedItemBindingProperty": "level",
  184. "items":
  185. [ { "level": 1,
  186. "name": "Easy",
  187. "display": "✮✩✩✩"
  188. },
  189. { "level": 2,
  190. "name": "Normal",
  191. "display": "✮✮✩✩"
  192. },
  193. { "level": 3,
  194. "name": "Hard",
  195. "display": "✮✮✮✩"
  196. },
  197. { "level": 4,
  198. "name": "Insane",
  199. "display": "✮✮✮✮"
  200. }
  201. ],
  202. "itemViewGenerators":
  203. { "default":
  204. { "type": "method",
  205. "object": "GameController",
  206. "method": "DifficultyView"
  207. }
  208. }
  209. }
  210. ]
  211. }
  212. ]
  213. },
  214. "eventHandlers":
  215. { "onRefresh":
  216. { "type":"method",
  217. "object": "GameController",
  218. "method": "OnRefresh"
  219. }
  220. }
  221. },
  222. {
  223. "type": "window",
  224. "name": "gameboard.Window",
  225. "content":
  226. {
  227. "type": "panel",
  228. "name": "gameSurface",
  229. "width": 400,
  230. "height": 400,
  231. "children":
  232. [ { "type": "table",
  233. "verticalAlignment": "stretch",
  234. "horizontalAlignment": "stretch",
  235. "name": "gameBoard",
  236. "strata": 0.1,
  237. "cellSpacing": [ 1 , 1 ],
  238. "rows":
  239. [ { "heightFactor": 0.1 },
  240. { "heightFactor": 0.1 },
  241. { "heightFactor": 0.1 },
  242. { "heightFactor": 0.1 },
  243. { "heightFactor": 0.1 },
  244. { "heightFactor": 0.1 },
  245. { "heightFactor": 0.1 },
  246. { "heightFactor": 0.1 },
  247. { "heightFactor": 0.1 },
  248. { "heightFactor": 0.1 }
  249. ],
  250. "columns":
  251. [ { "widthFactor": 0.1 },
  252. { "widthFactor": 0.1 },
  253. { "widthFactor": 0.1 },
  254. { "widthFactor": 0.1 },
  255. { "widthFactor": 0.1 },
  256. { "widthFactor": 0.1 },
  257. { "widthFactor": 0.1 },
  258. { "widthFactor": 0.1 },
  259. { "widthFactor": 0.1 },
  260. { "widthFactor": 0.1 }
  261. ]
  262. },
  263. {
  264. "type": "panel",
  265. "name": "hector",
  266. "backgroundBrush": "mouseBrush",
  267. "width": 40,
  268. "height": 40
  269. }
  270. ]
  271. }
  272. }
  273. ]
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement