2D Game In Core – Proof of Concept Test

--[[
    -- user: togagames for CoreGames.com and LuaSnippets.com
    Proof of concept for making a 2D game in Core
    
* Find board parameters (each corner x,y)

--]]
local propSnowflake = script:GetCustomProperty("Snowflake")

local _ballId = "EC8ED5115368CADC:ball"
local _ball = World.FindObjectById(_ballId)
local _bx    = _ball:GetWorldPosition().x
local _by    = _ball:GetWorldPosition().y
local _bz    = _ball:GetWorldPosition().z

local _speedY     = 2.432
local _speedZ     = 1.74
local _borderL     = -223     --y
local _borderR     = 190     --y
local _borderT     = 353     --z
local _borderB     = 118     --z
local _width    = 413
local _randY    = 1

local _bdh = _ball:GetWorldPosition().y -- horz pos (y)
local _bdv = _ball:GetWorldPosition().z -- vert pos (z)

local _dirY = 1 -- will change the direction by multiplying neg or pos
local _dirZ = 1


local _snowflake = {}
local _sfOffset = nil
local _ssY = 1.2
local _ssZ = -.3
local _snowHeap = {} -- mark for destruction
local _starterFlake = 1
--print(_ball:GetWorldPosition().z)



function Tick(deltaTime)
    -- track ball L/R
    if(_ball:GetWorldPosition().y + _speedY >= _borderR)then -- ball hits right
        _dirY = -1
    elseif(_ball:GetWorldPosition().y - _speedY <= _borderL)then -- ball hits left
        _dirY = 1
    end
    -- track ball U/D
    if(_ball:GetWorldPosition().z + _speedZ >= _borderT)then -- ball hits top
        _dirZ = -1
    elseif(_ball:GetWorldPosition().z - _speedZ <= _borderB)then -- ball hits bottom
        _dirZ = 1
    end    
    _by = _ball:GetWorldPosition().y +_speedY * _dirY -- go left (y)
    _bz = _ball:GetWorldPosition().z +_speedZ * _dirZ -- go down (z)
    _ball:SetWorldPosition(Vector3.New(_bx,_by,_bz))
    --[[ *********** BALL MOVEMENT ABOVE ***********--]]
    
    
    
    --[[- *********** SNOW CODE BELOW *********** -]]
    
    if(#_snowHeap < 5)then -- wait for trash day
        for b=_starterFlake, #_snowflake do
            local _sx = _snowflake[b]:GetWorldPosition().x    
            local _sy = _snowflake[b]:GetWorldPosition().y
            local _sz = _snowflake[b]:GetWorldPosition().z +_ssZ
            if(_sz + _ssZ < _borderB)then
                _starterFlake = _starterFlake + 1
                --table.insert(_snowHeap,_snowflake[b]) -- add to trash
                --_snowflake[b].visibility = Visibility.FORCE_OFF
                _snowflake[b]:Destroy()
            else
                _snowflake[b]:SetWorldPosition(Vector3.New(_sx,_sy,_sz))
            end        
        end
    end
    
    -- remove trash (not doing this right now as "shifting" the array seems to break it)
    if(#_snowHeap >= 5)then
        for c=1, #_snowHeap do
            _snowflake[c]:Destroy()
            table.remove(_snowflake,1)
        end
        _snowHeap = {}
    end
end

--[[

        _s[1] = a
        _s[2] = b
        _s[3] = c
        _s[4] = d

--]]

function _makeAFlake()
    local _snowflakes = #_snowflake + 1
    --local _sfOffset = Vector3.New(_bx,_borderL,_borderT)
    _randY = math.random(1,_width)
    _sfOffset = Vector3.New(_bx,_borderL+_randY,_borderT-10)
    --print ("[Snowflake] @ ",_sfOffset)
    _snowflake[_snowflakes] = World.SpawnAsset(propSnowflake, {position = _sfOffset})
    _snowflake[_snowflakes]:SetWorldScale(Vector3.ONE * .08)
    _snowflake[_snowflakes]:SetRotation(Rotation.New(0, 0, 90))
end

local _snowTask = Task.Spawn(function() _makeAFlake() end)
_snowTask.repeatCount = -1
_snowTask.repeatInterval = 1





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_