Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public BoardManager {
  2. LevelData levelData; //defined from editor, don't mutate
  3. BlockObject blockObjectMaster; //defined from editor, don't mutate
  4. List<BlockObject> blockList;
  5. List<EntityObject> entityList;
  6. int strokes = 0;
  7.  
  8.  
  9. void Start() {
  10. blockList = InitBlockList(levelData);
  11.  
  12. }
  13.  
  14. List<BlockObject> InitBlockList(LevelData _levelData) {
  15. //reads LevelData.blockStates and returns a list of BlockObjects
  16. List<BlockObject> blockList = new List<BlockObject>();
  17. for (key in _levelData.blockStates) {
  18. blockList.Add(CreateBlockObject(key, _levelData.blockStates[key]));
  19. }
  20. return blockList;
  21. }
  22.  
  23. BlockObject CreateBlockObject(BlockData _blockData, BlockState _blockState) {
  24. //creates and instantiates a new blockObject
  25. BlockObject blockObject = Instantiate(blockObjectMaster,Util.GridToReal(_blockState.pos));
  26. blockObject.Init(_blockData, _blockState);
  27. return blockObject;
  28. }
  29.  
  30. }
  31.  
  32. //dont mutate this
  33. public LevelData {
  34. int par; //defined from existing data
  35. String name; //defined from existing data
  36. String creator; //defined from existing data
  37. Dict<BlockData, BlockState> blockStates; //defined from existing data
  38. Dict<EntityData, EntityState> entityStates; //defined from existing data
  39. }
  40.  
  41. public BlockObject : MonoBehaviour {
  42. BlockData blockData;
  43. BlockState blockState;
  44.  
  45. Init(BlockData _blockData, BlockState blockState) {
  46. blockData = _blockData;
  47. blockState = _blockState;
  48. //code to change shape based on blockData and blockState
  49. }
  50.  
  51. //functions to actually set and move the block around in here
  52. }
  53.  
  54. public BlockData : ScriptableObject {
  55. int width; //defined from existing data
  56. int height; //defined from existing data
  57. BlockType blockType; //misc data structure to determine the type of block
  58.  
  59. public BlockData(int _width, int _height, BlockType _blockType) {
  60. width = _width;
  61. height = _height;
  62. blockType = _blockType;
  63. }
  64.  
  65. Vector2Int GetSize() {
  66. return new Vector2Int(width,height);
  67. }
  68. }
  69.  
  70.  
  71. public BlockState {
  72. Vector2Int pos;
  73. BlockStateEnum state;
  74.  
  75. public BlockState(int _x, int _y) {
  76. pos = new Vector2Int(_x, _y);
  77. state = BlockStateEnum.DEFAULT;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement