Advertisement
antonsavov

WIP WorldSetup

Jan 10th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.18 KB | None | 0 0
  1. -------------------------------
  2. -- /lib/WorldSetup ------------
  3. -------------------------------
  4. --- This package keeps functions that define the layout of the game world
  5. -- Where the portals are, where the buildzones are, where the spawn area is, etc.
  6. -- no minecraft dependent code should be in here
  7.  
  8. function getPortalLocations(settings)
  9.     local portals_boxes = {}
  10.  
  11.     local x = settings.computer.x + math.floor(settings.spawnzone_size/2) + settings.portal_offset
  12.     local y = settings.computer.y - 2
  13.     local z = settings.computer.z - math.floor(settings.portal_count.z/2) * ( settings.portal_offset + settings.portal_size) - math.floor(settings.portal_size/2)
  14.     for ix = 0, settings.portal_count.x - 1 do
  15.         for iz=0, settings.portal_count.z - 1 do
  16.             local xpos = x + ix * (settings.portal_offset + settings.portal_size)
  17.             local ypos = y
  18.             local zpos = z + iz * (settings.portal_offset + settings.portal_size)              
  19.             table.insert( portals_boxes, box(xpos, ypos, zpos, settings.portal_size, settings.portal_height, settings.portal_size))
  20.         end
  21.     end
  22.     return portals_boxes
  23. end
  24.  
  25. function getSpawnAreaLocation(settings)
  26.     local x = settings.computer.x - math.floor(settings.spawnzone_size/2)
  27.     local y = settings.computer.y
  28.     local z = settings.computer.z - math.floor(settings.spawnzone_size/2)
  29.     local w = settings.spawnzone_size + portal_size*settings.portal_count.x + portal_offset*(settings.portal_count.x+1) --TODO make this static with 3x3 portals in mind
  30.     local l = settings.spawnzone_size
  31.     local h = 3 -- the height of the fence around the spawn zone
  32.    
  33.     local spawn_zone = box(x,y,z,w,h,l) -- TODO maybe have that created by a initSpawnzone() function and stored in the game object as it could be needed to check player locations
  34.     return spawn_zone
  35. end
  36.  
  37. function getBuildzoneLocations(settings)
  38.     BUILDZONE_WIDTH = GRIDCELL_SIZE * GRIDCELL_COUNT --TODO if we want to mimic a Manhattan-like grid, rectangular buildzones must be possible
  39.     PLUG_LENGTH = math.floor(GRIDCELL_SIZE/3) -- the number of minecraft blocks which the crosses around each detector block that are made out of plug blocks will expand to
  40.     NUMBER_OF_BUILDZONES = GAME_FIELD.countX*GAME_FIELD.countZ -- the number of games that can be active simultaneously
  41.  
  42.     --a platfrom encompassing all play areas (number of play areas is defined in GAME_FIELD)
  43.     PLAY_AREAS = {
  44.         x= computer.x + (PLAY_AREA_OFFSET.x - CATALOGUE_SLOT_OFFSET) * GRIDCELL_SIZE + 1 ,
  45.         y=computer.y - 1,
  46.         z = closestGridCoord(computer.z, GRIDCELL_SIZE, computer.z + SPAWNZONE_SIZE/2)  + (PLAY_AREA_OFFSET.z - CATALOGUE_SLOT_OFFSET ) * GRIDCELL_SIZE + 1,
  47.         dx = 2 * CATALOGUE_SLOT_OFFSET * GRIDCELL_SIZE + (GRIDCELL_SIZE-1) +  BUILDZONE_WIDTH * GAME_FIELD.countX + (BUILDZONE_OFFSET * GRIDCELL_SIZE)*(GAME_FIELD.countX-1),
  48.         dz = 2 * CATALOGUE_SLOT_OFFSET * GRIDCELL_SIZE + (GRIDCELL_SIZE-1) +  BUILDZONE_WIDTH * GAME_FIELD.countZ + (BUILDZONE_OFFSET * GRIDCELL_SIZE)*(GAME_FIELD.countZ-1)
  49.     }
  50.  
  51.     FIRST_ZONE = {
  52.         x=computer.x + PLAY_AREA_OFFSET.x * GRIDCELL_SIZE + 1 + math.floor(GRIDCELL_SIZE/2),
  53.         y=computer.y - 1,
  54.         z=closestGridCoord(computer.z, GRIDCELL_SIZE, computer.z + SPAWNZONE_SIZE/2)  + PLAY_AREA_OFFSET.z * GRIDCELL_SIZE + 1 + math.floor(GRIDCELL_SIZE/2),
  55.     }
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement