Pixel Art Drawing From Maximal Rectangle Solution

--[[
    -- user: togagames for CoreGames.com and LuaSnippets.com
    

Library selections: 61
1. AnimeGirl
2. BabyGroot
3. Bomb
4. Battlehelm
5. Bitcoin
6. Bow
7. BrickBlue
8. BrickBrown
9. BrickRed
10. BlankBlue
11. BlankBrown
12. BlankRed
13. BlockQuestion
14. Cactus
15. Castle
16. Cheeseburger
17. Cherries
18. Doge
19. Drumstick
20. EmojiGrin
21. EmojiHeartEyes
22. EmojiShades
23. EmojiThumbsUp
24. EyesBlue
25. Fox
26. GameOver
27. Gemstone
28. Grapes
29. GraveHand
30. Ham
31. HamCooked
32. HandPoint
33. Heart
34. HotAirBalloon
35. Hotdog
36. Lightbulb
37. LootBag
38. MapPinBlue
39. MapPinGreen
40. MapPinRed
41. Milk
42. Pikachu
43. PirateFlag
44. Potion
45. Rest
46. Rip
47. RupeeBlue
48. RupeeGreen
49. RupeeRed
50. Shades
51. Skull
52. SpeechBubble
53. Star
54. Sword
55. SwordsBanner
56. TootsieRoll
57. Toucan
58. TreasureChest
59. Trophy
60. Wizard
61. WoodSign


    Make your own pixel art for use in Core!
    
    Download the setup Pyxel Edit starter file that is already configured for this:
    
    https://www.luasnippets.com/wp-content/uploads/2020/09/core-pixel-art-starter-93-53-8.zip
    
    Create your own pixel art inside of Core! Have fun.
    
    * Convert your tilemap (from Pyxel Edit)
    
    Step 1: go to: https://www.w3schools.com/code/tryit.asp?filename=GJ348BT5QHBE
    
    Step 2: put the array data inside: const _pixelArt = [] and hit RUN (above)
    Step 3: press button "Convert Tilemap" and copy the new array
    Step 4: paste that array inside: const mat = [] and hit RUN (above)
    Step 5: press button "Pixel Array" - this is the pixel/mesh reduction code
    Step 6: copy all the output and create a "New Script" inside of Core.

--]]

-- Internal custom properties
local COMPONENT_ROOT = script:GetCustomProperty("ComponentRoot"):WaitForObject()
local _artLibrary       = require( script:GetCustomProperty("ListArt") )
local _color          = require( script:GetCustomProperty("ColorPalette") )
local propPixel      = script:GetCustomProperty("Pixel")
local _stand           = script:GetCustomProperty("stand"):WaitForObject()
local _spot          = script:GetCustomProperty("spot"):WaitForObject()


-- User exposed properties
local ART_CHOICE = COMPONENT_ROOT:GetCustomProperty("ArtChoice")
local HIDE_STAND = COMPONENT_ROOT:GetCustomProperty("HideStand")
local SCALE_SIZE = COMPONENT_ROOT:GetCustomProperty("ScaleSize")
local FACE_NORTH_SOUTH = COMPONENT_ROOT:GetCustomProperty("FaceNorthSouth")

local _artwork    = require( script:GetCustomProperty("Art".._artLibrary[ART_CHOICE][1]) )

if(2 > 1)then -- just a check of the library
    print("Library selections: "..tostring(_artLibrary._count))
    for a=1, _artLibrary._count do
        print (tostring(a)..". ".._artLibrary[a][1])
    
    end
end
--print("Library: "..tostring(_artLibrary._count).." items")

--local _rChoice = math.random(1,_artLibrary._count) -- make a random selection from arts

local _rawPixelCount     = #_artwork

print("("..tostring(_rawPixelCount).." meshes from "..tostring(_artwork._width * _artwork._height).." pixels) Spawn: ".._artLibrary[ART_CHOICE][1])


local _pixelScale = .01 -- overall world scale
--local _stand = COMPONENT_ROOT:FindDescendantsByName("stand")[1] -- cube display block
--local _spot = COMPONENT_ROOT:FindDescendantsByName("spot")[1] -- attach to plane

if(HIDE_STAND)then
    _stand.visibility = Visibility.FORCE_OFF
end
_spot.visibility = Visibility.FORCE_ON


local _shell = {}
for a=1, #_artwork do -- build the pixel art
    local _paColor = Color.New(_color.hex( _color[ _artwork[a][1]+1 ][1] ))
    local _locX = _artwork[a][2] -- origin points
    local _locY = _artwork[a][3]
    local _pWidth = _artwork[a][4] -- how wide (each tile)    
    local _pHeight = _artwork[a][5] -- how tall  ^    ^    ^
    local _pX = nil
    local _pY = nil
    local _pZ = nil
    
    _pX = (_stand:GetWorldPosition().x + _locX + (_pWidth/2)) - (_artwork._width/2) 
    --_pY = _stand:GetWorldPosition().y + _locY + (_pHeight/2) - (_artwork._height*SCALE_SIZE)/(SCALE_SIZE*_artwork._height)
    _pY = _stand:GetWorldPosition().y + _locY + (_pHeight/2) - _artwork._height

    _pZ = _stand:GetWorldPosition().z
    local _paOffset = Vector3.New(_pX,_pY,_pZ)
    
    _shell[a] = World.SpawnAsset(propPixel, {position = _paOffset})
    _shell[a]:SetWorldScale(Vector3.New(_pWidth*_pixelScale,_pHeight*_pixelScale,_pixelScale))
    --_shell[a]:SetRotation(Rotation.New(0, 90, 0))
    _shell[a]:SetColor(_paColor)
    _shell[a].parent = _spot
    _shell[a].visibility = Visibility.FORCE_ON
    --print(_shell[a]:GetWorldTransform())
end

-- Move the pixel art via the "anchor"
local _nx = _stand:GetPosition().x
local _ny = _stand:GetPosition().y
local _nz = _stand:GetPosition().z + 100
_spot:SetPosition(Vector3.New(_nx,_ny,_nz))

if FACE_NORTH_SOUTH then
    _spot:SetRotation(Rotation.New(90, 0, 90))
else
    _spot:SetRotation(Rotation.New(90, 0, 0))
end

_spot:SetScale(Vector3.ONE * SCALE_SIZE)
_spot.visibility = Visibility.FORCE_OFF



Latest Posts

Emulation ProcessEmulation Process

  Record Locs for Emulation in Core Grab data. Here, I am recording x,yz, and name data to emulate. Next Convert to usable array for Core template data. Snippet>> Pattern  Core template replacement pattern: Path:[C:\Users\soandso\Documents\My Games\CORE\Saved\Maps\mycoregame\Data\Tree\Emulator_