--[[ -- user: togagames for CoreGames.com and LuaSnippets.com Proof of concept for making a 2D game in Core 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. * Make a picture frame that resizes with the artwork * Draw pixels from the bottom-up so they natively align to the ground. * Check next pixel to grow (width) the current pixel * Use spacing for "empty" (56) pixels --]] local _color = require( script:GetCustomProperty("ColorPalette") ) local propPixel = script:GetCustomProperty("Pixel") --[[Choices: ArtBattlehelm,ArtBow,ArtGemstone,ArtHam, ArtCheeseburger, ArtHamCooked,ArtLootBag,ArtPikachu, ArtMegaMan, ArtPotion, ArtWizard, ArtCoreLolgo, ArtWoodSign, ArtSword --]] local _artwork = require( script:GetCustomProperty("ArtBattlehelm") ) print(#_artwork) local _library = {} local _groundLevel = 53 local _borderL = -223 --y local _borderR = 190 --y local _borderT = 353 --z local _borderB = 118 --z local _pixelArt = {} -- store all pixel art ids local _pixelArts = 0 local _newY = 0 -- test to move more function _nextY(_awm) _newY = _newY + (_awm*2)+12 end function _makeSprite() UI.PrintToScreen("MAKING A SPRITE") _pixelArts = _pixelArts + 1 _pixelArt[_pixelArts] = _pixelArts -- store this pixel art's (global) ID _G["_pixi".._pixelArts] = {} local _paOffset = nil local _px = -21.9 local _py = _nextY(_artwork._width) -- Tells where to place the pixel art in the world local _pz = _artwork._height * _artwork._pixelSize local _rowZ = _groundLevel local _colY = _borderL local _pc = nil local _pSpot = 1 local _colR = nil local _colG = nil local _colB = nil local _colA = nil local aaa = 0 -- each drawn pixel for r=1, _artwork._height do _py = _newY+_borderL+5 -- start position of y (left/right) local _grow = 0 -- store the pixel data for whole object widths (consecutive pixels) local _cg = 1 local _cy = 0 -- read each element in this row -- if blank (56) go the next -- if NOT blank check next and add up 'sames" -- skip to next after sames for c=1, _artwork._width do -- next row if(_artwork[_pSpot] == 56)then -- empty spot: draw previous stuff if(_cg > 1)then print("DRAW PREVIOUS CG AT BLANK") -- (_grow) block size: (_cg) at loc: (_cy) aaa = aaa + 1 --_py = _py + _artwork._pixelSize local _pws = _cy + (_cg*_artwork._pixelSize)/2 - _artwork._pixelSize+2 local _scaleYZ = _artwork._pixelSize * .01 _paOffset = Vector3.New(_px,_pws,_pz) _G["_pixi".._pixelArts][aaa] = World.SpawnAsset(propPixel, {position = _paOffset}) _G["_pixi".._pixelArts][aaa]:SetWorldScale(Vector3.New(_scaleYZ, _scaleYZ*_cg,_scaleYZ)) _G["_pixi".._pixelArts][aaa]:SetRotation(Rotation.New(0, 90, 0)) _colR = _color[_grow +1 ][1] _colG = _color[_grow +1 ][2] -- get colors RGBA _colB = _color[_grow +1 ][3] _colA = _color[_grow +1 ][4] _G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_color.hex(_color[_grow +1][1]))) --_G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_colR,_colG,_colB,_colA)) end _cg = 1 -- end of the row: is this block part of the "stored"? elseif(c == _artwork._width)then if(_cg > 1)then print("DRAW A LINE at end of row") -- (_grow) block size: (_cg) at loc: (_cy) aaa = aaa + 1 --_py = _py + _artwork._pixelSize local _pws = _cy + (_cg*_artwork._pixelSize)/2 - _artwork._pixelSize+2 local _scaleYZ = _artwork._pixelSize * .01 _paOffset = Vector3.New(_px,_pws,_pz) _G["_pixi".._pixelArts][aaa] = World.SpawnAsset(propPixel, {position = _paOffset}) _G["_pixi".._pixelArts][aaa]:SetWorldScale(Vector3.New(_scaleYZ, _scaleYZ*_cg,_scaleYZ)) _G["_pixi".._pixelArts][aaa]:SetRotation(Rotation.New(0, 90, 0)) _colR = _color[_grow +1 ][1] _colG = _color[_grow +1 ][2] -- get colors RGBA _colB = _color[_grow +1 ][3] _colA = _color[_grow +1 ][4] _G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_color.hex(_color[_grow +1][1]))) --_G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_colR,_colG,_colB,_colA)) else --print("DRAW SINGLE at end of row") -- nothing previous so draw this single spot aaa = aaa + 1 local _scaleYZ = _artwork._pixelSize * .01 _paOffset = Vector3.New(_px,_py,_pz) _G["_pixi".._pixelArts][aaa] = World.SpawnAsset(propPixel, {position = _paOffset}) _G["_pixi".._pixelArts][aaa]:SetWorldScale(Vector3.New(_scaleYZ, _scaleYZ,_scaleYZ)) _G["_pixi".._pixelArts][aaa]:SetRotation(Rotation.New(0, 90, 0)) _colR = _color[_artwork[_pSpot] +1 ][1] _colG = _color[_artwork[_pSpot] +1 ][2] -- get colors RGBA _colB = _color[_artwork[_pSpot] +1 ][3] _colA = _color[_artwork[_pSpot] +1 ][4] _G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_color.hex(_color[_artwork[_pSpot] +1 ][1]))) --_G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_colR,_colG,_colB,_colA)) end _cg = 1 -- consecutive spot: store for later elseif(_artwork[_pSpot] == _artwork[_pSpot+1])then --print("Store spots") if(_cg == 1)then _cy = _py -- store the y pos _grow = _artwork[_pSpot] -- save the tile to "grow" end -- save start y position _cg = _cg + 1 -- count how many wide to "grow" else -- single spot: draw previous stuff if(_cg > 1)then --print("DRAW A LINE (single spot found)") -- (_grow) block size: (_cg) at loc: (_cy) aaa = aaa + 1 --_py = _py + _artwork._pixelSize local _pws = _cy + (_cg*_artwork._pixelSize)/2 - _artwork._pixelSize+2 local _scaleYZ = _artwork._pixelSize * .01 _paOffset = Vector3.New(_px,_pws,_pz) _G["_pixi".._pixelArts][aaa] = World.SpawnAsset(propPixel, {position = _paOffset}) _G["_pixi".._pixelArts][aaa]:SetWorldScale(Vector3.New(_scaleYZ, _scaleYZ*_cg,_scaleYZ)) _G["_pixi".._pixelArts][aaa]:SetRotation(Rotation.New(0, 90, 0)) _colR = _color[_grow +1 ][1] _colG = _color[_grow +1 ][2] -- get colors RGBA _colB = _color[_grow +1 ][3] _colA = _color[_grow +1 ][4] _G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_color.hex(_color[_grow +1][1]))) --_G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_colR,_colG,_colB,_colA)) else --print("Single Spot Drawn") -- nothing previous so draw this single spot aaa = aaa + 1 local _scaleYZ = _artwork._pixelSize * .01 _paOffset = Vector3.New(_px,_py,_pz) _G["_pixi".._pixelArts][aaa] = World.SpawnAsset(propPixel, {position = _paOffset}) _G["_pixi".._pixelArts][aaa]:SetWorldScale(Vector3.New(_scaleYZ, _scaleYZ,_scaleYZ)) _G["_pixi".._pixelArts][aaa]:SetRotation(Rotation.New(0, 90, 0)) _colR = _color[_artwork[_pSpot] +1 ][1] _colG = _color[_artwork[_pSpot] +1 ][2] -- get colors RGBA _colB = _color[_artwork[_pSpot] +1 ][3] _colA = _color[_artwork[_pSpot] +1 ][4] _G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_color.hex(_color[_artwork[_pSpot] +1 ][1]))) --print(_color[_grow +1][5]) --_G["_pixi".._pixelArts][aaa]:SetColor(Color.New(_colR,_colG,_colB,_colA)) end _cg = 1 end _py = _py + _artwork._pixelSize -- move column _pSpot = _pSpot + 1 -- move through our (selected) pixel art array end _pz = _pz - _artwork._pixelSize -- move to next row(z) end _nextY(_artwork._width)-- this is just for spawning multiple next to each other.. --print(#_G["_pixi".._pixelArts]) --print( _G["_pixi".._pixelArts][aaa-1]:GetWorldPosition().z.." z") end local _spriteTask = Task.Spawn(function() _makeSprite() end) _spriteTask.repeatCount = 1-- set to -1 for infinite loops _spriteTask.repeatInterval = .4 -- Mimick the Palette onto the group of blocks local _bfID = "582A82E06CEDF7D2:ClientContextCubes" local _blocksFolder = World.FindObjectById(_bfID) local _nextHex = 1 for _,child in ipairs(_blocksFolder:GetChildren()) do child:SetColor(Color.New(_color.hex(_color[_nextHex][5]))) --child:SetColor(Color.New(_color.hex("007800ff"))) _nextHex = _nextHex + 1 end print ("HEX: ",_color.hex("503000ff",1))