@Bri_G Here’s the other scroll I had. It’s set for a 3x3 grid terrain. It creates new terrain in front of you and deletes the terrain behind you to keep you in the middle. It can be changed to 5x5 or 7x7, etc. Because I’m scrolling fast, you can see a slight delay as new terrain is created and the old terrain deleted. If you move at a slower speed, it might not be as noticeable. You can also change the size of each grid. I guess this can be considered an infinite terrain.
PS. This eventually crashes, but I don’t know if it me or a problem with Codea not releasing memory.
displayMode(FULLSCREEN)
function setup()
map={"Surfaces:Basic Bricks AO","Surfaces:Basic Bricks Color",
"Surfaces:Basic Bricks Normal","Surfaces:Basic Bricks Roughness",
"Surfaces:Desert Cliff AO","Surfaces:Desert Cliff Color",
"Surfaces:Desert Cliff Height","Surfaces:Desert Cliff Normal",
"Surfaces:Desert Cliff Roughness","Surfaces:Stone Brick Color",
"Surfaces:Stone Brick Height","Surfaces:Stone Brick Metalness",
"Surfaces:Stone Brick Normal","Surfaces:Stone Brick Roughness",}
terrainSize=1 -- 1=3x3 grid 2=5x5 grid 3=7x7 grid
size=30 -- size of each grid
hgx=Gravity.x
speed,ey,ang=0,0,0
cameraX,cameraZ=0,0
scene = craft.scene()
scene.camera.position = vec3(cameraX,0,cameraZ)
scene.camera.eulerAngles=vec3(0,ey,0)
scene.sun.rotation = quat.eulerAngles(45,0,45)
scene.ambientColor = color(90,90,90)
skyMaterial = scene.sky.material
skyMaterial.sky = color(0, 185, 255, 255)
skyMaterial.horizon = color(116, 226, 198, 255)
tab={}
px,py=0,0
newPosition(vec3(0,0,0))
fill(255)
end
function update(dt)
scene:update(dt)
scene.camera.position = vec3(cameraX,1,cameraZ)
scene.camera.eulerAngles=vec3(0,ey,0)
end
function draw()
background(0)
update(DeltaTime)
scene:draw()
ey=ey-ang
local xVel=speed*math.sin(math.rad(ey))
local zVel=speed*math.cos(math.rad(ey))
local xDir=math.sin(math.rad(ey))
local zDir=math.cos(math.rad(ey))
cameraX=cameraX+xVel
cameraZ=cameraZ+zVel
local gx=Gravity.x
ang=ang+(gx-hgx)*4
hgx=gx
pushMatrix()
translate(WIDTH/2,HEIGHT/2-300)
rotate(ang*-30)
sprite("Tyrian Remastered:Boss A",0,0,300)
translate()
popMatrix()
px=cameraX//size
py=cameraZ//size
text(px.." "..py,WIDTH/2,HEIGHT-25)
if speed==0 then
text("tap screen to start",WIDTH/2,HEIGHT-50)
else
text("tap screen to stop",WIDTH/2,HEIGHT-50)
end
newPosition()
end
function newPosition()
r=math.random(1000000)
for x=-terrainSize,terrainSize do
for y=-terrainSize,terrainSize do
a=string.format("%d%d",px+x,py+y)
if tab[a]==nil then
local c=createFloor(vec3(px+x,0,py+y))
tab[a]={x=px+x,y=py+y,r=r,c=c}
else
tab[a].r=r
end
end
end
if hx~=px or hy~=py then
oldPosition(hr)
end
hr=r
hx,hy=px,py
end
function oldPosition(r)
for a,b in pairs(tab) do
if b.r==r then
tab[a].c:destroy()
tab[a]=nil
end
end
end
function createFloor(pos)
local c1=scene:entity()
c1.model = craft.model.cube(vec3(size,.1,size))
c1.position=vec3(pos.x*size,pos.y,pos.z*size)
c1.material = craft.material("Materials:Standard")
c1.material.map = readImage(map[math.random(#map)])
c1.material.offsetRepeat=vec4(0,0,size,size)
return c1
end
function touched(t)
if t.state==BEGAN then
if speed>0 then
speed=0
else
speed=.1
end
end
end