We could add a bit of fog - so anything further than the fog field of view - can be invisible blocks - or blocks that are not generated what so ever - they "could be" potentially created as an when they come into view with InstanceObject
And then as the player moves, it procedurally builds new blocks as they come into view in the distance depending on where they are from the map generated
So this would mean that we could have potentially a lot bigger map to, say 1000,1000 (not all generated at same time) just as and when come into view
Just an idea
// Project: craft-a-lite
// Created: 2018-01-20
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "craft-a-lite" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 1200, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
// setup an array of blocks to store the building block structure
type _blocks
id
x#, y#, z#
texture
endtype
global blocks as _blocks[40000] // 200 * 200
type _datablocks
height
texture
endtype
global data as _datablocks[200,200] //200 * 200
// Position a ball player - could be any thing
player = CreateObjectSphere(1,1,50)
SetObjectColor(player,0,255,0,255)
SetObjectPosition(player,0,0,0)
// generate map
generatemap(200,200)
block=CreateObjectBox(2,2,2)
grass=createtexture(64,64,MakeColor(0,255,0),255,255)
sand = createtexture(64,64,MakeColor(194,178,128),200,255)
water = createtexture(64,64,MakeColor(0,0,255),200,255)
blockcount=0
for x=1 to 200
for z=1 to 200
blocks[blockcount].id = InstanceObject(block)
blocks[blockcount].x#=100- GetObjectSizeMaxX(blocks[blockcount].id) * x
blocks[blockcount].y# = 43+GetObjectSizeMaxY(blocks[blockcount].id) * data[x,z].height
blocks[blockcount].z# =100- GetObjectSizeMaxZ(blocks[blockcount].id) * z
textid=data[x,z].texture
if textid=1 then blocks[blockcount].texture = grass
if textid=2 then blocks[blockcount].texture = water
if textid=3 then blocks[blockcount].texture = sand
SetObjectPosition(blocks[blockcount].id,(blocks[blockcount].x#*2),(blocks[blockcount].y#*2)-90,-blocks[blockcount].z#*2-90)
SetObjectVisible(blocks[blockcount].id,1)
SetObjectImage(blocks[blockcount].id,blocks[blockcount].texture,1)
inc blockcount
// if data[blockcount].height=0 then SetObjectPosition(player, blocks[blockcount].x#,140,blocks[blockcount].z#)
next
next
// setup a skybox
SetSunActive(1)
SetSunColor(255,255,0)
SetSkyBoxHorizonSize(4.0,4)
SetSkyBoxHorizonColor(0,0,0)
SetSkyBoxSkyColor(0,0,50)
SetSkyBoxVisible(1)
SetFogColor(0,0,0)
SetFogRange(0,200)
SetFogMode(1)
// setcameras
SetCameraRange(1,1,200)
SetCameraRotation(1,0,90,0)
// initialise player positioning variables
x#=GetObjectx(player):y#=0:z#=getobjectz(player)
cx#=0 : cy#=0 : cz#=0
do
SetObjectPosition(player,x#,y#,z#)
// Aim camera with the player - and position in 3rd person
SetCameraPosition(1,getobjectx(player),getobjecty(player)+2,getobjectz(player)-10)
SetCameraLookAt(1,getobjectx(player),getobjecty(player),getobjectz(player),0)
// press and hold C to move the camera instead of the player
if GetRawKeyState(67) // C
// rotate camera
if GetRawKeyState(37) then dec cy#,.1
if GetRawKeyState(39) then inc cy#,.1
SetCameraRotation(1,0,cy#*5,0)
else
// move player
if GetRawKeyState(37) then dec x#,.1
if GetRawKeyState(39) then inc x#,.1
if GetRawKeyState(38) then inc z#,.1
if GetRawKeyState(40) then dec z#,.1
endif
Print( ScreenFPS() )
Print( "Last Key " + str(GetRawLastKey()))
Print( "Press and keep hold of 'c' to move the camera with cursors")
Sync()
loop
// thats all folks
end
function generatemap(sizex, sizey)
height=5
up=1
// Create Ground first
for x=1 to sizex
for y=1 to sizey
data[x,y].height=0
data[x,y].texture=1
next
next
// Add height on random areas
summit = 5 // Hight peak of any mountain top - this is 3 at moment to do some testing of shifting up blocks the surround the peak
summitlocationx = random(1,sizex) // where on the map do we position the start of that mountain
summitlocationy = random(1,sizey)
for mountains = 1 to 200 // lets have 100 mountains
// OK, now we increase the height one loop at a time, and increase the height of an existing height
// set the centre of the mounting top
summitlocationx = random(1,sizex) // where on the map do we position the start of that mountain
summitlocationy = random(1,sizey)
applyheightandcheckbounderies(summitlocationx, summitlocationy,3)
// repeat so many times, so the each loop increases the mountain height and surround boxes of it - i think 1000 rounds gives a nice effect
for a=1 to 2
// loop round surrounding blocks
// for a=1 to 3
// centre
applyheightandcheckbounderies(summitlocationx, summitlocationy,3)
//for a=b to 1 step -1
// edges
applyheightandcheckbounderies(summitlocationx-a, summitlocationy,2)
applyheightandcheckbounderies(summitlocationx+a, summitlocationy,2)
applyheightandcheckbounderies(summitlocationx, summitlocationy-a,2)
applyheightandcheckbounderies(summitlocationx, summitlocationy+a,2)
//forcorners
applyheightandcheckbounderies(summitlocationx+a, summitlocationy+a,3)
applyheightandcheckbounderies(summitlocationx-a, summitlocationy+a,3)
applyheightandcheckbounderies(summitlocationx+a, summitlocationy-a,3)
applyheightandcheckbounderies(summitlocationx-a, summitlocationy-a,3)
//next
inc summitlocationx,a
inc summitlocationy,a
next
next
endfunction
function applyheightandcheckbounderies(posx, posy, textureid)
if posx>0 and posx<200 and posy>0 and posy<200
//increase height
data[posx, posy].height=data[posx, posy].height+1
data[posx, posy].texture=textureid
endif
endfunction
// Function to create a texture
//
// Inputs - Sizex - size of the texture to create - width
// Sizey - size of the texture to create - height
// Color - is the main color of the image
// Denisity - is a the depth of the texture - the lower the value, the more detail. higher value = no detail
//
// Returns the image for the resulting texture
//
// EG. CreateTexture ( 100, 100, makecolor(0,0,255), 100)
// This could create a DEEP water effect texture?
function createtexture(sizex# as float, sizey# as float, color, density, alpha as integer)
swap()
drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
render()
img = getimage(0,0,sizex#, sizey#)
memblockid = CreateMemblockFromImage (img)
imgwidth = GetMemblockInt(memblockid, 0)
imgheight = GetMemblockInt(memblockid, 4)
size=GetMemblockSize(memblockid)
for offset=12 to size-4 step 4
r=GetMemblockByte(memblockid, offset)
g=GetMemblockByte(memblockid, offset+1)
b=GetMemblockByte(memblockid, offset+2)
a=GetMemblockByte(memblockid, offset+3)
strength=random(1,density)
SetMemblockByte (memblockid, offset, r-strength)
SetMemblockByte (memblockid, offset+1, g-strength)
SetMemblockByte (memblockid, offset+2, b-strength )
SetMemblockByte (memblockid, offset+3, alpha)
next
deleteimage (img)
img = CreateImageFromMemblock(memblockid)
DeleteMemblock(memblockid)
endfunction img