Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- objectdef gameController
- {
- ; timestamps in seconds since the script started
- variable float CurrentFrame
- variable float LastFrame
- variable int Difficulty = 2
- ; amount of time (in seconds) elapsed since the last frame
- variable float FrameTime
- ; constructor
- method Initialize()
- {
- CurrentFrame:Set[${Script.RunningTime}/1000.0]
- LastFrame:Set[${CurrentFrame}]
- LGUI2:LoadPackageFile[day7.json]
- }
- ; destructor
- method Shutdown()
- {
- LGUI2:UnloadPackageFile[day7.json]
- }
- ; to be called by a LGUI2 "onRefresh" event handler, e.g. from the game viewer element
- method OnRefresh()
- {
- CurrentFrame:Set[${Script.RunningTime}/1000.0]
- if ${CurrentFrame.Equal[${LastFrame}]}
- return
- FrameTime:Set[${CurrentFrame}-${LastFrame}]
- This:UpdateGame
- LastFrame:Set[${CurrentFrame}]
- }
- ; called by OnRefresh, add game logic here. use ${This.FrameTime} to calculate any distances moved, etc.
- method UpdateGame()
- {
- }
- method DifficultyView()
- {
- variable jsonvalue joListBoxItem = "{\"type\":\"itemview\"}"
- if ${Context.Args[name](exists)}
- joListBoxItem:Set[content,"${Context.Args[name].AsJSON.Escape}"]
- else
- joListBoxItem:Set[content,"\"\""]
- Context:SetView["${joListBoxItem.AsJSON.Escape}"]
- }
- }
- objectdef gameBoard
- {
- variable gameTile Tiles[10,10]
- variable gameMouse GameMouse
- variable lgui2elementref BoardElement
- method InitTiles()
- {
- variable int X
- variable int Y
- for (Y:Set[1];${Y}<=10;Y:Inc)
- {
- for (X:Set[1];${X}<=10;X:Inc)
- {
- This.Tiles[${Y},${X}]:Init[This, ${X}, ${Y}]
- }
- }
- }
- method InitUI()
- {
- BoardElement:Set[${LGUI2.Element[gameBoard].ID}]
- This:InitTiles
- }
- }
- objectdef gameTile
- {
- variable int X
- variable int Y
- variable weakref Board
- variable lgui2elementref TileElement
- method Init (weakref _Board, int _X, int _Y)
- {
- X:Set[${_X}]
- Y:Set[${_Y}]
- Board:SetReference[_Board]
- variable jsonvalue joTileView = "${LGUI2.Template[tile.Wall].AsJSON.Escape}"
- joTileView:Set["_ref", "\"GameBoard.Tiles[${_Y},${_X}]\""]
- joTileView:Set["_row", ${_Y}]
- joTileView:Set["_column", ${_X}]
- TileElement:Set[${_Board.BoardElement.AddChild["${joTileView.AsJSON.Escape}"].ID}]
- }
- }
- objectdef gameMouse
- {
- variable float X = 5.5
- variable float Y = 5.5
- variable float Speed
- variable float Heading
- variable float SmellRadius
- variable float SightDistance
- variable float LastTurn
- method Refresh()
- {
- }
- }
- variable(global) gameController GameController
- variable(global) gameBoard GameBoard
- function main()
- {
- GameBoard:InitUI
- while 1
- waitframe
- }
- {
- "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json",
- "templates":
- {
- "starSize":
- { "font": { "height": 32 } },
- "tile.View":
- { "type": "panel",
- "jsonTemplate": "panel",
- "verticalAlignment": "stretch",
- "horizontalAlignment": "stretch"
- },
- "tile.Wall":
- {
- "jsonTemplate": "tile.View",
- "backgroundBrush": "wallBrush"
- }
- },
- "brushes":
- {
- "wallBrush": { "color": [ 1.0 , 0.0 , 0.0 ] },
- "mouseBrush":
- { "color": [ 0.25 , 0.25 , 0.25 ],
- "-canvas":
- {
- "width": 64,
- "height": 64
- }
- },
- "cheeseBrush": { "color": [ 1.0 , 0.85 , 0.0 ] }
- },
- "elements":
- [
- { "type": "window",
- "name": "game.window",
- "title": "Game Options",
- "height": 250,
- "width": 400,
- "verticalAlignment": "center",
- "horizontalAlignment": "center",
- "content":
- { "type": "dockpanel",
- "margin": [ 10 , 10 ],
- "children":
- [ { "type": "stackpanel",
- "orientation": "horizontal",
- "horizontalContentAlignment": "left",
- "margin": [ 10 , 5 ],
- "children":
- [ { "type": "combobox",
- "minSize": [ 90, 0 ],
- "selectedItemBinding": "GameController.Difficulty",
- "selectedItemBindingProperty": "level",
- "items":
- [ { "level": 1,
- "name": "Easy",
- "display": "✮✩✩✩"
- },
- { "level": 2,
- "name": "Normal",
- "display": "✮✮✩✩"
- },
- { "level": 3,
- "name": "Hard",
- "display": "✮✮✮✩"
- },
- { "level": 4,
- "name": "Insane",
- "display": "✮✮✮✮"
- }
- ],
- "itemViewGenerators":
- { "default":
- { "type": "method",
- "object": "GameController",
- "method": "DifficultyView"
- }
- }
- }
- ]
- }
- ]
- },
- "eventHandlers":
- { "onRefresh":
- { "type":"method",
- "object": "GameController",
- "method": "OnRefresh"
- }
- }
- },
- {
- "type": "window",
- "name": "gameboard.Window",
- "content":
- {
- "type": "panel",
- "name": "gameSurface",
- "width": 400,
- "height": 400,
- "children":
- [ { "type": "table",
- "verticalAlignment": "stretch",
- "horizontalAlignment": "stretch",
- "name": "gameBoard",
- "strata": 0.1,
- "cellSpacing": [ 1 , 1 ],
- "rows":
- [ { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 },
- { "heightFactor": 0.1 }
- ],
- "columns":
- [ { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 },
- { "widthFactor": 0.1 }
- ]
- },
- {
- "type": "panel",
- "name": "hector",
- "backgroundBrush": "mouseBrush",
- "width": 40,
- "height": 40
- }
- ]
- }
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement