UPDATE 13/03/2020
NO SHADER PACK
https://drive.google.com/open?id=1MquXmdh18WaG95xJkvxOyQqnpGBD-1O2
SHADER PACK
https://drive.google.com/open?id=1n0r2M2H3WS5Kp915dGxlMow5wnP0A_Qc
// Project: height maps
// Created: 2020-02-26
// show all errors
#include ".\..\Templates\ShaderPack\Includes\ShaderPack.agc"
SetErrorMode(2)
// set window properties
SetWindowTitle( "height maps" )
SetWindowSize( 1024, 1024, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 1024 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 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
// enable the sky box
SetSkyBoxVisible( 1 )
// load terrain detail texture with mipmapping enabled
SetGenerateMipmaps(1)
LoadImage( 1, "detail.png" )
SetImageWrapU( 1, 1 )
SetImageWrapV( 1, 1 )
WaterNormalImageID=LoadImage("waterNormal.png")
SetImageWrapU(WaterNormalImageID,1)
SetImageWrapV(WaterNormalImageID,1)
SP_Init() //
type models
model as integer []
model_texture as integer []
model_string as string []
model_texture_string as string []
x as float []
y as float []
z as float []
ax as float []
ay as float []
az as float []
sx as float []
sy as float []
sz as float []
texture as integer []
amount as integer
endtype
global import as models
dim walls[100,1000] as integer
dim walls_type[100,1000] as integer
dim walls_teture[100,1000] as integer
dim walls_teture_string [100,1000] as string
dim walls_x[100,1000] as float
dim walls_y[100,1000] as float
dim walls_z[100,1000] as float
dim walls_ax[100,1000] as float
dim walls_ay[100,1000] as float
dim walls_az[100,1000] as float
DIM WALLS_VECTOR_X[100,1000,30] AS FLOAT
DIM WALLS_VECTOR_Y[100,1000,30] AS FLOAT
DIM WALLS_VECTOR_Z[100,1000,30] AS FLOAT
dim Wgrid[50,50]
dim bar[20]
dim bx[10] as float
dim ROAD[1000] as integer
dim ROAD_TEXTURE[1000] as integer
dim ROAD_TEXTURE_STRING[1000] AS STRING
dim holdx[1000] as float
dim holdz[1000] as float
dim holdy[1000] as float
DIM DOTS[100]
dim grid[10]
dim Wall_papers[200]
dim wall_papers_string[200] as string
dim buttons[2000]
dim sp_tiles[1000]
dim trees[100] as integer
dim trees_X[100] as float
dim trees_Y[100] as float
dim trees_Z[100] as float
dim trees_AX[100] as float
dim trees_AY[100] as float
dim trees_AZ[100] as float
global texon=0
global tile_image
global make_build
global Count
global rod
global up
global grab
global Object
global pointer_x
global pointer_y
GLOBAL MAP
global sp
global ste#
global box
global tex
global memblock
GLOBAL DELETEIT
global temp_sprite
global level
GLOBAL LAND
global r#
global g#
global b#
global w=0
ste#=0.01
make_build=0
up=1
draw=1
rod=1
count=0
grab=0
box=CreateObjectBox(10,30,10)
SetObjectCollisionMode(box,0)
WaterObjectID=CreateObjectPlane(1024,1024)
RotateObjectLocalX(WaterObjectID,90)
FixObjectPivot(WaterObjectID)
SetObjectPosition(WaterObjectID,0,-10,40)
SetObjectUVScale(WaterObjectID,0,8,8)
SP_Water_AddObject(WaterObjectID,WaterNormalImageID)
SP_Water_SetSunColor(WaterObjectID,190,100,0)
SP_Water_SetDepthScale(WaterObjectID,0.4)
SP_Water_SetDepthColorScale(WaterObjectID,0.2)
SP_Water_SetWaveStrength(WaterObjectID,0.1)
SP_Water_SetRefractionHeightScale(1000.3)
// Setup the water object before any other object so they generate the clipping plane code for the water
// load the terrain shader to give the terrain color based on height
LoadShader( 1, "Terrain.vs", "Terrain.ps" )
// create the terrain object from a height map
LAND=CreateObjectFromHeightMap( "\media\height maps\2\05.png", 1024, 50, 1024, 4, 16 )
SetObjectImage( LAND, 1, 0 )
SetObjectUVScale( LAND, 0, 128, 128 ) // scale the detail texture so it repeats
SetObjectShader( LAND, 1 )
SetObjectCollisionMode(LAND,1)
SetAmbientColor( 128,128,128 )
LoadImage( 2, "tarmac.jpg" )
SetImageWrapU( 2, 1 )
SetImageWrapV( 2, 1 )
global roads_map
global roads
global sp1
roads=CreateObjectFromHeightMap( "\media\road.png", 1024, 50, 1024, 4, 16 )
SetObjectImage( roads, 2, 0 )
SetObjectUVScale( roads, 0, 64, 64 ) // scale the detail texture so it repeats
SetObjectCollisionMode(roads,0)
i1=loadimage("\media\road.png")
sp1=CreateSprite(i1)
roads_map=CreateRenderImage(1024,1024,0,0)
setRenderToImage(roads_map,0)
DrawSprite(sp1)
SetRenderToScreen()
SetSpriteImage(sp1,roads_map)
SetSpriteSize(sp1,1024,1024)
deleteimage(i1)
SetSpriteDepth(SP1,900)
LoadImage( 3, "path.png" )
SetImageWrapU( 3, 1 )
SetImageWrapV( 3, 1 )
global path_map
global paths
global sp2
paths=CreateObjectFromHeightMap( "\media\road.png", 1024, 50, 1024, 4, 16 )
SetObjectImage( paths, 3, 0 )
SetObjectUVScale( paths, 0, 32, 32 ) // scale the detail texture so it repeats
SetObjectCollisionMode(paths,0)
i2=loadimage("\media\road.png")
sp2=CreateSprite(i2)
path_map=CreateRenderImage(1024,1024,0,0)
setRenderToImage(path_map,0)
DrawSprite(sp2)
SetRenderToScreen()
SetSpriteImage(sp2,path_map)
SetSpriteSize(sp2,1024,1024)
deleteimage(i2)
SetSpriteDepth(SP2,850)
SetSpriteTransparency(sp2,2)
SetSpriteVisible(sp2,0)
SetCameraPosition(1,150,50,150)
SetCameraRotation(1,0,0,0)
x#=getcamerax(1)
y#=GetObjectHeightMapHeight(LAND,getcamerax(1),getcameraz(1))
z#=getcameraz(1)
SetCameraPosition(1,x#,y#+1,z#)
SetObjectPosition(WaterObjectID,500,y#-1,500)
tree=loadobject("\media\foliage\tree01.x")
SetObjectScale(tree,0.1,0.1,0.1)
tree_image=LoadImage("\media\foliage\tree01_d_result.png")
SetObjectImage(tree,tree_image,0)
SetObjectAlphaMask(tree,1)
for t=1 to 100
trees[t]=InstanceObject(tree)
_labal:
x#=random(1,1024)
z#=random(1,1024)
y#=GetObjectHeightMapHeight(LAND,x#,z#)
hit=ObjectRAYCast(0,x#,y#,z#,x#,y#+200,z#)
if hit=WaterObjectID then goto _labal:
SetObjectPosition(trees[t],x#,y#,z#)
//SP_AddObject(trees[t])
next
#insert "buttons.scene"
buttons_setup()
SetSpriteDepth( buttons_done1,1)
SetSpriteDepth( buttons_set_camera[0],1)
SetSpriteDepth(buttons_build[0],1)
SetSpriteDepth(buttons_show_map[0],1)
SetSpriteDepth(buttons_show_map[1],1)
SetSpriteDepth(buttons_show_map[2],1)
SetSpriteDepth(buttons_show_map[3],1)
CreateEditBox(1)
CreateEditBox(2)
CreateEditBox(3)
CreateEditBox(4)
CreateEditBox(5)
CreateEditBox(6)
SetEditBoxSize(1,120,30)
SetEditBoxPosition(1,getspritex(buttons_show_map[0]),1)
SetEditBoxText(1,"main map")
SetEditBoxSize(2,120,30)
SetEditBoxPosition(2,getspritex(buttons_show_map[1]),1)
SetEditBoxText(2,"road map")
SetEditBoxSize(3,120,30)
SetEditBoxPosition(3,getspritex(buttons_show_map[2]),1)
SetEditBoxText(3,"path map")
SetEditBoxSize(4,120,30)
SetEditBoxPosition(4,getspritex(buttons_show_map[3]),1)
SetEditBoxText(4,"make tiles")
SetEditBoxTextSize(1,40)
SetEditBoxTextSize(2,40)
SetEditBoxTextSize(3,40)
SetEditBoxTextSize(4,40)
SetEditBoxSize(5,120,30)
SetEditBoxPosition(5,getspritex(buttons_import),1)
SetEditBoxText(5,"load model")
SetSpriteDepth(buttons_import,1)
SetEditBoxSize(6,120,30)
SetEditBoxPosition(6,getspritex(buttons_done1),1)
SetEditBoxText(6,"Done")
SetEditBoxTextSize(5,30)
SetEditBoxTextSize(6,40)
i=loadimage("\media\height maps\2\99.png")
sp=CreateSprite(i)
map=CreateRenderImage(1024,1024,0,0)
setRenderToImage(map,0)
DrawSprite(sp)
SetRenderToScreen()
SetSpriteImage(sp,map)
SetSpriteSize(sp,1024,1024)
grid[1]=CreateRenderImage(1024,1024,0,0)
SetRenderToImage(grid[1],0)
for q=1 to 1024 step 1024 /50
for t=1 to 1024 step 1024 /50
DrawLine(T,Q,T+1024,Q,MakeColor(0,255,0),MakeColor(0,255,0))
next
next
for q=1 to 1024 step 1024 /50
for t=1 to 1024 step 1024 /50
DrawLine(T,Q,T,Q+1024,MakeColor(0,255,0),MakeColor(0,255,0))
next
next
SetRenderToScreen()
sp_grid=CreateSprite(grid[1])
SetSpriteTransparency(sp_grid,1)
SetPrintColor(0,0,200,255)
C#=MakeColor(200,200,55)
DrawEllipse(5,5,20,20,C#,C#,1)
DOT1=GetImage(0,0,10,10)
FOR T=1 TO 100
DOTS[T]=CreateSprite(DOT1)
NEXT
C#=MakeColor(0,80,80)
Drawbox(1,1,1+1024/50,1+1024/50,C#,C#,c#,c#,1)
tile_image=GetImage(1,1,1+1024/50,1+1024/50)
red=MakeColor(255,0,0)
DrawEllipse(3,3,6,6,red,red,1)
im2=getimage(0,0,10,10)
CreateSprite(100,im2)
SetSpriteDepth(100,0)
SetObjectCollisionMode(WaterObjectID,0)
SetFolder("")
SetFolder("media")
SetFolder("building_textures")
global images
images=0
a$=GetfirstFile()
repeat
a$=GetNextFile()
if FindString(a$,".png") or FindString(a$,".jpg")
images=images+1
Wall_papers[images]=loadimage(a$)
wall_papers_string[images]=a$
endif
until a$=""
SetFolder("")
SetFolder("media")
x=50
y=350
for t=1 to images
buttons[t]=CreateSprite(Wall_papers[t])
SetSpriteSize(buttons[t],50,50)
SetSpritePosition(buttons[t],x+25,y)
SetSpriteVisible(buttons[t],0)
x=x+50
if x>700
y=y+50
x=50
endif
next
tex=1
updata()
do
tpx=GetPointerX()
tpy=GetPointery()
butx=getspritex(buttons_set_camera[0])
butxs=GetSpriteWidth(buttons_set_camera[0])
buty=getspritey(buttons_set_camera[0])
butys=GetSpriteHeight(buttons_set_camera[0])
if tpx>butx and tpx<butx+butxs
if tpy>buty and tpy<buty+butys
if draw=1 and GetPointerReleased()=1
position_camera()
endif
endif
endif
butx=getspritex(buttons_build[0])
butxs=GetSpriteWidth(buttons_build[0])
buty=getspritey(buttons_build[0])
butys=GetSpriteHeight(buttons_build[0])
if tpx>butx and tpx<butx+butxs
if tpy>buty and tpy<buty+butys
if GetPointerPressed()=1
build_it()
endif
endif
endif
butx=getspritex(buttons_import)
butxs=GetSpriteWidth(buttons_import)
buty=getspritey(buttons_import)
butys=GetSpriteHeight(buttons_import)
if tpx>butx and tpx<butx+butxs
if tpy>buty and tpy<buty+butys
if GetPointerPressed()
import_model()
endif
endif
endif
SetSpritePosition(100,GetCameraX(1),1024-getcameraZ(1))
butx=getspritex(buttons_show_map[0])
butxs=GetSpriteWidth(buttons_show_map[0])
buty=getspritey(buttons_show_map[0])
butys=GetSpriteHeight(buttons_show_map[0])
if tpx>butx and tpx<butx+butxs
if tpy>buty and tpy<buty+butys
if GetPointerPressed() then drawmap()
endif
endif
butx=getspritex(buttons_show_map[1])
butxs=GetSpriteWidth(buttons_show_map[1])
buty=getspritey(buttons_show_map[1])
butys=GetSpriteHeight(buttons_show_map[1])
if tpx>butx and tpx<butx+butxs
if tpy>buty and tpy<buty+butys
if GetPointerPressed() then drawroads()
endif
endif
butx=getspritex(buttons_show_map[2])
butxs=GetSpriteWidth(buttons_show_map[2])
buty=getspritey(buttons_show_map[2])
butys=GetSpriteHeight(buttons_show_map[2])
if tpx>butx and tpx<butx+butxs
if tpy>buty and tpy<buty+butys
if GetPointerPressed() then drawpaths()
endif
endif
butx=getspritex(buttons_show_map[3])
butxs=GetSpriteWidth(buttons_show_map[3])
buty=getspritey(buttons_show_map[3])
butys=GetSpriteHeight(buttons_show_map[3])
if tpx>butx and tpx<butx+butxs
if tpy>buty and tpy<buty+butys
if GetPointerPressed() then make_tiles()
endif
endif
if object=2 then edit_models()
picker()
if count>0 and rod=1
for t=1 to Count
tx#=GetObjectWorldX(road[t])
tz#=GetObjectWorldZ(road[t])
SetSpritePosition( sp_tiles[t],TX#,1024-TZ#)
next
endif
for t=1 to 100
tx#=GetObjectWorldX(trees[t])
tz#=GetObjectWorldZ(trees[t])
SetSpritePosition(DOTS[T],TX#,1024-TZ#)
NEXT
sp_sync()
//sync()
nx=GetPointerX()
if GetRawMouseMiddleState() =1 and nx<tpx then RotateCameraLocalY(1,-3)
if GetRawMouseMiddleState() =1 and nx>tpx then RotateCameraLocalY(1,3)
if GetRawMouseRightState() =1 then MoveCameraLocalZ(1,0.3)
if grab>0 and object=1 then move_trees()
if import.amount>0
print( import.x[0])
print( import.y[0])
print( import.z[0])
endif
loop
function move_trees()
pointer_x1 = GetPointerX()
pointer_y1 = GetPointerY()
if pointer_x1<pointer_x then MoveObjectLocalX( trees[grab],-1)
if pointer_x1>pointer_x then MoveObjectLocalX( trees[grab],1)
if pointer_y1<pointer_y then MoveObjectLocalz( trees[grab],1)
if pointer_y1>pointer_y then MoveObjectLocalz( trees[grab],-1)
x#=GetObjectWorldX(trees[grab])
z#=GetObjectWorldz(trees[grab])
y#=GetObjectHeightMapHeight(LAND,x#,z#)
SetobjectPosition(trees[grab],x#,y#+1,z#)
trees_X[GRAB]= GetObjectWorldX(trees[grab])
trees_Y[GRAB]= GetObjectWorldY(trees[grab])
trees_Z[GRAB]= GetObjectWorldZ(trees[grab])
trees_AX[GRAB]= GetObjectWorldAngleX(trees[grab])
trees_AY[GRAB]= GetObjectWorldAngleY(trees[grab])
trees_AZ[GRAB]= GetObjectWorldAngleZ(trees[grab])
if GetPointerState()=0
grab=0
object=0
endif
endfunction
function edit_models()
exi=50
repeat
dec exi
sync()
until exi=0
exi=0
repeat
nx=GetPointerX()
ny=GetPointery()
for t=1 to 9
if GetSpriteExists(bar[t])
print(grab)
spx=getspritex(bar[t])
spy=getspritey(bar[t])
sw=GetSpriteWidth(bar[t])
sh=GetSpriteHeight(bar[t])
if nx>spx and nx<spx+sw
if ny>spy and ny<spy+sh
if GetRawMouseLeftState() and nx<700
select t
case 1:import.x[grab]=import.x[grab]-0.1:endcase
case 2:import.y[grab]=import.y[grab]-0.1:endcase
case 3:import.z[grab]=import.z[grab]-0.1:endcase
case 4:import.sx[grab]=import.sx[grab]-0.001:endcase
case 5:import.sy[grab]=import.sy[grab]-0.001:endcase
case 6:import.sz[grab]=import.sz[grab]-0.001:endcase
case 7:import.ax[grab]=import.ax[grab]-1:endcase
case 8:import.ay[grab]=import.ay[grab]-1:endcase
case 9:import.az[grab]=import.az[grab]-1:endcase
endselect
endif
if GetRawMouseLeftState() and nx>700
select t
case 1:import.x[grab]=import.x[grab]+0.1:endcase
case 2:import.y[grab]=import.y[grab]+0.1:endcase
case 3:import.z[grab]=import.z[grab]+0.1:endcase
case 4:import.sx[grab]=import.sx[grab]+0.001:endcase
case 5:import.sy[grab]=import.sy[grab]+0.001:endcase
case 6:import.sz[grab]=import.sz[grab]+0.001:endcase
case 7:import.ax[grab]=import.ax[grab]+1:endcase
case 8:import.ay[grab]=import.ay[grab]+1:endcase
case 9:import.az[grab]=import.az[grab]+1:endcase
endselect
endif
endif
endif
endif
next
if import.amount>0
SetObjectPosition(import.model[grab],import.x[grab],import.y[grab],import.z[grab])
SetObjectRotation(import.model[grab],import.ax[grab],import.ay[grab],import.az[grab])
SetObjectScale(import.model[grab],import.sx[grab],import.sy[grab],import.sz[grab])
endif
px=GetPointerX()
py=GetPointery()
butx=getspritex(buttons_done1)
butxs=GetSpriteWidth(buttons_done1)
buty=getspritey(buttons_done1)
butys=GetSpriteHeight(buttons_done1)
if px>butx and px<butx+butxs
if py>buty and py<buty+butys
if GetRawMouseLeftPressed()=1
exi=1
endif
endif
endif
sync()
until exi=1
grab=0
object=0
for t=1 to 9
deletesprite(bar[t])
next
endfunction
function picker()
SetSpriteVisible(sp,0)
SetSpriteVisible(sp1,0)
SetSpriteVisible(sp2,0)
if GetRawKeyState(38)=1 then MoveCameraLocalZ(1,0.3)
if GetRawKeyState(40)=1 then MoveCameraLocalZ(1,-0.3)
if GetRawKeyState(37)=1 then RotateCameraLocalY(1,-2)
if GetRawKeyState(39)=1 then RotateCameraLocalY(1,2)
MoveCameraLocalY(1,-1)
x#=getcamerax(1)
y#=getcameray(1)
z#=getcameraz(1)
//
hit=ObjectRAYCast(0,x#,y#,z#,x#,y#-2,z#)
if hit<>0
newy#=GetObjectRayCastY(0)
SetCameraPosition(1,x#,newy#+2,z#)
else
x#=getcamerax(1)
z#=getcameraz(1)
y#=GetObjectHeightMapHeight(LAND,x#,z#)
SetCameraPosition(1,x#,y#+2,z#)
ENDIF
pointer_x = GetPointerX()
pointer_y = GetPointerY()
if grab=0 and object=0
// get the x, y and z unit vectors based on the pointer position
unit_x# = Get3DVectorXFromScreen(pointer_x,pointer_y)
unit_y# = Get3DVectorYFromScreen(pointer_x,pointer_y)
unit_z# = Get3DVectorZFromScreen(pointer_x,pointer_y)
// calculate the start of the ray cast, which is the unit vector + the camera position
start_x# = unit_x# + GetCameraX(1)
start_y# = unit_y# + GetCameraY(1)
start_z# = unit_z# + GetCameraZ(1)
// calculate the end of the vector, which is the unit vector multiplied by the length of the ray cast and then add the camera position to it
end_x# = 800*unit_x# + GetCameraX(1)
end_y# = 800*unit_y# + GetCameraY(1)
end_z# = 800*unit_z# + GetCameraZ(1)
// determine which object has been hit
object_hit = ObjectrayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
if object_hit <> 0
for t=1 to 100
if object_hit=trees[t]
x#=GetObjectWorldX(trees[t])
y#=GetObjectWorldy(trees[t])
z#=GetObjectWorldz(trees[t])
SetObjectPosition(box,x#,y#+10,z#)
if GetPointerState()=1
grab=t
object=1
SetObjectRotation(trees[grab],GetCameraAngleX(1),GetCameraAngley(1),GetCameraAnglez(1))
endif
endif
next
if import.amount>0
for t=0 to import.amount-1
if object_hit=import.model[t]
x#=GetObjectWorldX(import.model[t])
y#=GetObjectWorldy(import.model[t])
z#=GetObjectWorldz(import.model[t])
SetObjectPosition(box,x#,y#+10,z#)
if GetPointerState()=1
grab=t
object=2
y=330
for t=1 to 9
bar[t]=loadsprite("bar.png")
SetSpritePosition(bar[t],500,y)
y=y+40
SetSpriteSize(bar[t],400,15)
next
endif
endif
next
endif
endif
endif
endfunction
function make_tiles()
exi=50
repeat
dec exi
sync()
until exi=0
exi=0
repeat
if GetRawKeypressed(asc("T")) then texon=1-texon
for t=1 to images
SetSpriteVisible(buttons[t],texon)
next
for k=1 to images
px=GetPointerX()
py=GetPointery()
tx=getspritex(buttons[k])
ty=getspritey(buttons[k])
if px>tx and px<tx+50
if py>ty and py<ty+50
if GetPointerPressed() and texon=1
tex=k
endif
endif
endif
next
print(tex)
px=GetPointerX()
py=GetPointery()
butx=getspritex(buttons_done1)
butxs=GetSpriteWidth(buttons_done1)
buty=getspritey(buttons_done1)
butys=GetSpriteHeight(buttons_done1)
if px>butx and px<butx+butxs
if py>buty and py<buty+butys
if GetRawMouseLeftPressed()=1
exi=1
endif
endif
endif
if exi=0
a=1024/50
for q=1 to 1024 step 1024 /50
for t=1 to 1024 step 1024 /50
px = GetPointerX()
py = 1024- GetPointerY()+a
if GetPointerState() and texon=0
if px>t and px<t+a
if py>q and py<q+a
if GetObjectExists(road[count+1])=0
inc count
road[count]=CreateObjectBox(1024 /50,0.2,1024 /50)
holdx[count]=t
holdz[count]=q
holdy[count]=GetObjectHeightMapHeight(LAND,t,q)+0.1
SetObjectPosition(road[count],holdx[count],holdy[count],holdz[count])
sp_tiles[count]=CreateSprite(tile_image)
SetSpriteDepth(sp_tiles[count],600)
setobjectimage(road[count],Wall_papers[tex],0)
ROAD_TEXTURE[COUNT]=TEX
ROAD_TEXTURE_STRING[count] =wall_papers_string[tex]
sync()
endif
endif
endif
endif
next
next
endif
if count>0
for t=1 to Count
tx#=GetObjectWorldX(road[t])
tz#=GetObjectWorldZ(road[t])
SetSpritePosition( sp_tiles[t],TX#,1024-TZ#)
next
endif
RotateCameraLocalX(1,GetRawMouseWheelDelta())
if GetRawKeyState(37) then RotateCameraLocalY(1,-3)
if GetRawKeyState(39) then RotateCameraLocalY(1,3)
if GetRawKeyState(38) then moveCameraLocalz(1,2)
if GetRawKeyState(40) then moveCameraLocalz(1,-2)
sync()
until exi=1
AY#=GetCameraAngleY(1)
SetCameraRotation(1,0,AY#,0)
endfunction
function drawmap()
if GetMemblockExists(memblock1)=0
memblock1 = CreateMemblockFromImage(roads_map)
else
DeleteMemblock(memblock1)
memblock1 = CreateMemblockFromImage(roads_map)
endif
if GetMemblockExists(memblock2)=0
memblock2 = CreateMemblockFromImage(path_map)
else
DeleteMemblock(memblock2)
memblock2 = CreateMemblockFromImage(path_map)
endif
ex=50
exi=50
repeat
dec exi
sync()
until exi=0
exi=0
repeat
for q=1 to 5
print("")
next
print("mouse left_button raise")
print("mouse right_button lower")
print("mouse middle_button flatern_level")
px = GetPointerX()
py = GetPointerY()
SetSpriteVisible(sp,1)
SetSpriteVisible(sp1,1)
SetSpriteVisible(sp2,1)
SetSpriteDepth(SP,900)
SetSpriteDepth(SP1,800)
SetSpriteDepth(SP2,850)
SetSpriteTransparency(SP1,2)
SetSpriteTransparency(SP2,2)
if GetMemblockExists(memblock)=0
memblock = CreateMemblockFromImage(map)
endif
if GetRawMouseLEFTState()=1
for tx=px-12 to px+12
for ty=py-12 to py+12
r#=GetMemblockByte( memblock, 12+px*4+py*1024*4)
g#=GetMemblockByte( memblock, 13+px*4+py*1024*4)
b#=GetMemblockByte( memblock, 14+px*4+py*1024*4)
SetMemblockByte(memblock, 12+tx*4+ty*1024*4,R#+1)
SetMemblockByte(memblock, 13+tx*4+ty*1024*4,G#+1)
SetMemblockByte(memblock, 14+tx*4+ty*1024*4,B#+1)
byte1=getMemblockByte(memblock1,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock1,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock1,14+tx*4+ty*1024*4)
if byte1>0 or byte2>0 or byte3
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock1, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock1, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock1, 14+tx*4+ty*1024*4,byte3+1)
endif
byte1=getMemblockByte(memblock2,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock2,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock2,14+tx*4+ty*1024*4)
if byte1>0 or byte2>0 or byte3
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock2, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock2, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock2, 14+tx*4+ty*1024*4,byte3+1)
endif
next
next
deleteimage(path_map)
path_map = CreateImageFromMemblock(memblock2)
SetSpriteImage(sp2,path_map)
deleteimage(roads_map)
roads_map = CreateImageFromMemblock(memblock1)
SetSpriteImage(sp1,roads_map)
deleteimage(map)
map = CreateImageFromMemblock(memblock)
SetSpriteImage(sp,map)
endif
if GetRawMouseRightState()=1
for tx=px-12 to px+12
for ty=py-12 to py+12
r#=GetMemblockByte( memblock, 12+px*4+py*1024*4)
g#=GetMemblockByte( memblock, 13+px*4+py*1024*4)
b#=GetMemblockByte( memblock, 14+px*4+py*1024*4)
SetMemblockByte(memblock, 12+tx*4+ty*1024*4,R#-1)
SetMemblockByte(memblock, 13+tx*4+ty*1024*4,G#-1)
SetMemblockByte(memblock, 14+tx*4+ty*1024*4,B#-1)
byte1=getMemblockByte(memblock1,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock1,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock1,14+tx*4+ty*1024*4)
if byte1>0 or byte2>0 or byte3
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock1, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock1, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock1, 14+tx*4+ty*1024*4,byte3+1)
endif
byte1=getMemblockByte(memblock2,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock2,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock2,14+tx*4+ty*1024*4)
if byte1>0 or byte2>0 or byte3
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock2, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock2, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock2, 14+tx*4+ty*1024*4,byte3+1)
endif
next
next
deleteimage(path_map)
path_map = CreateImageFromMemblock(memblock2)
SetSpriteImage(sp2,path_map)
deleteimage(roads_map)
roads_map = CreateImageFromMemblock(memblock1)
SetSpriteImage(sp1,roads_map)
deleteimage(map)
map = CreateImageFromMemblock(memblock)
SetSpriteImage(sp,map)
endif
if GetRawMouseMiddleState()=1
if level=0
level=1
r#=GetMemblockByte( memblock, 12+px*4+py*1024*4)
g#=GetMemblockByte( memblock, 13+px*4+py*1024*4)
b#=GetMemblockByte( memblock, 14+px*4+py*1024*4)
endif
for tx=px-12 to px+12
for ty=py-12 to py+12
SetMemblockByte(memblock, 12+tx*4+ty*1024*4,r#)
SetMemblockByte(memblock, 13+tx*4+ty*1024*4,g#)
SetMemblockByte(memblock, 14+tx*4+ty*1024*4,b#)
byte1=getMemblockByte(memblock1,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock1,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock1,14+tx*4+ty*1024*4)
if byte1>0 or byte2>0 or byte3
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock1, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock1, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock1, 14+tx*4+ty*1024*4,byte3+1)
endif
byte1=getMemblockByte(memblock2,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock2,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock2,14+tx*4+ty*1024*4)
if byte1>0 or byte2>0 or byte3
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock2, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock2, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock2, 14+tx*4+ty*1024*4,byte3+1)
endif
next
next
deleteimage(path_map)
path_map = CreateImageFromMemblock(memblock2)
SetSpriteImage(sp2,path_map)
deleteimage(roads_map)
roads_map = CreateImageFromMemblock(memblock1)
SetSpriteImage(sp1,roads_map)
deleteimage(map)
map = CreateImageFromMemblock(memblock)
SetSpriteImage(sp,map)
endif
if GetRawMouseMiddleState()=0 and level=1 then level=0
butx=getspritex(buttons_done1)
butxs=GetSpriteWidth(buttons_done1)
buty=getspritey(buttons_done1)
butys=GetSpriteHeight(buttons_done1)
if px>butx and px<butx+butxs
if py>buty and py<buty+butys
if GetRawMouseLeftPressed()=1
exi=1
endif
endif
endif
sync()
until exi=1
MoveCameraLocalY(1,10)
updata()
DeleteMemblock( memblock)
ENDFUNCTION
function drawroads()
if GetMemblockExists(memblock)=0
memblock= CreateMemblockFromImage(map)
else
DeleteMemblock(memblock)
memblock= CreateMemblockFromImage(map)
endif
if GetMemblockExists(memblock1)=0
memblock1 = CreateMemblockFromImage(roads_map)
else
DeleteMemblock(memblock1)
memblock1 = CreateMemblockFromImage(roads_map)
endif
ex=50
repeat
dec ex
sync()
until ex=0
ex=0
repeat
for q=1 to 5
print("")
next
print("mouse left_button draw road")
print("mouse right_button delete_road")
px = GetPointerX()
py = GetPointerY()
SetSpriteVisible(sp,1)
SetSpriteVisible(sp1,1)
SetSpriteVisible(sp2,1)
SetSpriteDepth(SP,900)
SetSpriteDepth(SP1,800)
SetSpriteDepth(SP2,850)
SetSpriteTransparency(SP1,2)
SetSpriteTransparency(SP2,2)
if GetRawMouseLeftState()=1
for tx=px-10 to px+10
for ty=py-10 to py+10
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock1, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock1, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock1, 14+tx*4+ty*1024*4,byte3+1)
next
next
deleteimage(roads_map)
roads_map = CreateImageFromMemblock(memblock1)
SetSpriteImage(sp1,roads_map)
endif
if GetRawMouseRIGHTState()=1
for tx=px-12 to px+12
for ty=py-12 to py+12
SetMemblockByte(memblock1, 12+tx*4+ty*1024*4,0)
SetMemblockByte(memblock1, 13+tx*4+ty*1024*4,0)
SetMemblockByte(memblock1, 14+tx*4+ty*1024*4,0)
next
next
deleteimage(roads_map)
roads_map = CreateImageFromMemblock(memblock1)
SetSpriteImage(sp1,roads_map)
endif
butx=getspritex(buttons_done1)
butxs=GetSpriteWidth(buttons_done1)
buty=getspritey(buttons_done1)
butys=GetSpriteHeight(buttons_done1)
if px>butx and px<butx+butxs
if py>buty and py<buty+butys
if GetRawMouseLeftPressed()=1
ex=1
endif
endif
endif
sync()
until ex=1
updata()
DeleteMemblock(memblock)
DeleteMemblock(memblock1)
SetSpriteVisible(sp1,0)
endfunction
function drawpaths()
if GetMemblockExists(memblock)=0
memblock= CreateMemblockFromImage(map)
else
DeleteMemblock(memblock)
memblock= CreateMemblockFromImage(map)
endif
if GetMemblockExists(memblock1)=0
memblock1 = CreateMemblockFromImage(path_map)
else
DeleteMemblock(memblock1)
memblock1 = CreateMemblockFromImage(path_map)
endif
exi=50
repeat
dec exi
sync()
until exi=0
ex=0
repeat
for q=1 to 5
print("")
next
print("mouse left_button draw path")
print("mouse right_button delete_path")
px = GetPointerX()
py = GetPointerY()
SetSpriteVisible(sp,1)
SetSpriteVisible(sp1,1)
SetSpriteVisible(sp2,1)
SetSpriteDepth(SP,900)
SetSpriteDepth(SP1,800)
SetSpriteDepth(SP1,850)
SetSpriteTransparency(SP1,2)
if GetRawMouseLeftState()=1
for tx=px-8 to px+8
for ty=py-8 to py+8
byte1=getMemblockByte(memblock,12+tx*4+ty*1024*4)
byte2=getMemblockByte(memblock,13+tx*4+ty*1024*4)
byte3=getMemblockByte(memblock,14+tx*4+ty*1024*4)
SetMemblockByte(memblock1, 12+tx*4+ty*1024*4,byte1+1)
SetMemblockByte(memblock1, 13+tx*4+ty*1024*4,byte2+1)
SetMemblockByte(memblock1, 14+tx*4+ty*1024*4,byte3+1)
next
next
deleteimage(path_map)
path_map = CreateImageFromMemblock(memblock1)
SetSpriteImage(sp2,path_map)
endif
if GetRawMouseRIGHTState()=1
for tx=px-12 to px+12
for ty=py-12 to py+12
SetMemblockByte(memblock1, 12+tx*4+ty*1024*4,0)
SetMemblockByte(memblock1, 13+tx*4+ty*1024*4,0)
SetMemblockByte(memblock1, 14+tx*4+ty*1024*4,0)
next
next
deleteimage(path_map)
path_map = CreateImageFromMemblock(memblock1)
SetSpriteImage(sp2,path_map)
endif
butx=getspritex(buttons_done1)
butxs=GetSpriteWidth(buttons_done1)
buty=getspritey(buttons_done1)
butys=GetSpriteHeight(buttons_done1)
if px>butx and px<butx+butxs
if py>buty and py<buty+butys
if GetRawMouseLeftPressed()=1
ex=1
endif
endif
endif
sync()
until ex=1
updata()
DeleteMemblock(memblock)
DeleteMemblock(memblock1)
SetSpriteVisible(sp2,0)
endfunction
function updata()
setfolder("")
setfolder("media")
SaveImage(map,"my_height_map.png")
DeleteObject(LAND)
LAND=CreateObjectFromHeightMap( "my_height_map.png", 1024, 50, 1024, 4, 16 )
SetObjectImage( LAND, 1, 0 )
SetObjectUVScale( LAND, 0, 128, 128 ) // scale the detail texture so it repeats
SetObjectShader( LAND, 1 )
SetObjectCollisionMode(LAND,1)
saveimage(path_map,"path_map.png")
deleteobject(roads)
paths=CreateObjectFromHeightMap( "path_map.png", 1024, 50, 1024, 4, 16 )
SetObjectImage( paths, 3, 0 )
SetObjectUVScale( paths, 0, 256, 256 ) // scale the detail texture so it repeats
SetObjectCollisionMode(paths,0)
saveimage(roads_map,"roads_map.png")
deleteobject(roads)
roads=CreateObjectFromHeightMap( "roads_map.png", 1024, 50, 1024, 4, 16 )
SetObjectImage( roads, 2, 0 )
SetObjectUVScale( roads, 0, 64, 64 ) // scale the detail texture so it repeats
SetObjectCollisionMode(roads,0)
endfunction
function import_model()
load=0
local spr
ret$=ChooseRawFile("*.x;*.obj;*.fbx")
if ret$=""
no=0
else
load=1
ret1$=ChooseRawFile("*.png;*.jpg")
if ret1$=""
no=0
else
endif
endif
if load=1
delay=120
repeat
dec delay,1
a=1024/50
for q=1 to 1024 step 1024 /50
for t=1 to 1024 step 1024 /50
px# = GetPointerX()
py# = 1024- GetPointerY()+a
if GetPointerPressed() and delay<0
if px#>t and px#<t+a
if py#>q and py#<q+a
y#=GetObjectHeightMapHeight(LAND,px#,py#-30)
import.x.insert(px#)
import.y.insert(y#)
import.z.insert(py#)
import.ax.insert(0.0)
import.ay.insert(0.0)
import.az.insert(0.0)
import.sx.insert(0.1)
import.sy.insert(0.1)
import.sz.insert(0.1)
import.model.insert(loadobject(ret$))
import.model_string.insert(ret$)
import.texture.insert(LoadImage(ret1$))
import.model_texture_string.insert(ret1$)
SetObjectPosition(import.model[import.amount],import.x[import.amount],import.y[import.amount],import.z[import.amount])
SetObjectScale(import.model[import.amount],import.sx[import.amount],import.sy[import.amount],import.sz[import.amount])
SetObjectImage(import.model[import.amount],import.texture[import.amount],0)
SetObjectAlphaMask(import.model[import.amount],1)
load=0
inc import.amount,1
endif
endif
endif
next
next
sync()
until load=0
endif
endfunction
function build_it()
exi1=50
repeat
dec exi1
sync()
until exi1=0
exi1=0
PIC=0
REPEAT
a=1024/50
for q=1 to 1024 step 1024 /50
for t=1 to 1024 step 1024 /50
px = GetPointerX()
py = 1024- GetPointerY()+a
if GetRawMouseleftPressed()=1
if px>t and px<t+a
if py>q and py<q+a
NX#=T
NZ#=Q
NY#=GetObjectHeightMapHeight(LAND,t,q)
PICK=1
endif
endif
endif
NEXT
NEXT
sync()
UNTIL PICK=1
GPIVIT=CreateObjectSphere(1,32,32)
for x=1 to 50 step 5
for z=1 to 50 step 5
Wgrid[x,z]=CreateObjectBox(5,0.4,0.3)
Wgrid[x+1,z+1]=CreateObjectBox(0.3,0.4,5)
Wgrid[x+3,z+3]=CreateObjectBox(4,0.1,4)
FixObjectToObject(Wgrid[x,z],GPIVIT)
FixObjectToObject(Wgrid[x+1,z+1],GPIVIT)
FixObjectToObject(Wgrid[x+3,z+3],GPIVIT)
MoveObjectLocalX(Wgrid[x,z],x+2.5)
MoveObjectLocalz(Wgrid[x,z],z)
MoveObjectLocalX(Wgrid[x+1,z+1],x)
MoveObjectLocalz(Wgrid[x+1,z+1],z+2.5)
MoveObjectLocalX(Wgrid[x+3,z+3],x+2.5)
MoveObjectLocalz(Wgrid[x+3,z+3],z+2.5)
SetObjectColor(Wgrid[x+3,z+3],25,25,0,255)
SetObjectTransparency(Wgrid[x+3,z+3],2)
SetObjectColor(Wgrid[x+1,z+1],255,255,0,255)
SetObjectTransparency(Wgrid[x+1,z+1],2)
SetObjectColor(Wgrid[x,z],255,255,0,255)
SetObjectTransparency(Wgrid[x,z],2)
next
next
SetObjectPosition(GPIVIT,NX#,NY#+0.2,NZ#)
MOVE=0
exi1=0
repeat
RotateCameraLocalX(1,GetRawMouseWheelDelta())
pointer_x=getpointerx()
pointer_y=getpointery()
// get the x, y and z unit vectors based on the pointer position
unit_x# = Get3DVectorXFromScreen(pointer_x,pointer_y)
unit_y# = Get3DVectorYFromScreen(pointer_x,pointer_y)
unit_z# = Get3DVectorZFromScreen(pointer_x,pointer_y)
// calculate the start of the ray cast, which is the unit vector + the camera position
start_x# = unit_x# + GetCameraX(1)
start_y# = unit_y# + GetCameraY(1)
start_z# = unit_z# + GetCameraZ(1)
// calculate the end of the vector, which is the unit vector multiplied by the length of the ray cast and then add the camera position to it
end_x# = 800*unit_x# + GetCameraX(1)
end_y# = 800*unit_y# + GetCameraY(1)
end_z# = 800*unit_z# + GetCameraZ(1)
// determine which object has been hit
object_hit = ObjectrayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
if object_hit<>0 and object_hit>w
for x=1 to 50 step 5
for z=1 to 50 step 5
if GetPointerPressed() and GetRawKeyState(32)=0 and texon=0 AND DELETEIT=0
if object_hit=Wgrid[x,z]
inc w
walls[1,w]=CreateObjectBox(5,5,0.1)
x#=GetObjectWorldX(Wgrid[x,z])
z#=GetObjectWorldz(Wgrid[x,z])
y#=GetObjectWorldy(Wgrid[x,z])
SetObjectPosition(walls[1,w],x#,y#,z#)
MoveObjectLocalY(walls[1,w],2.5)
SetObjectCollisionMode(walls[1,w],0)
SetObjectColor(walls[1,w],0,0,200,100)
walls_type[1,w] =1
walls_x[1,W] =GetObjectWorldX(walls[1,w])
walls_y[1,W] =GetObjectWorldY(walls[1,w])
walls_z[1,W] =GetObjectWorldZ(walls[1,w])
walls_ax[1,W] =GetObjectWorldAngleX (walls[1,w])
walls_ay[1,W] =GetObjectWorldAngleY (walls[1,w])
walls_az[1,W] =GetObjectWorldAngleZ (walls[1,w])
meshmemblock = CreateMemblockFromObjectMesh(walls[1,W],1)
FOR T=0 TO 23
WALLS_VECTOR_X[1,W,T]=GetMeshMemblockVertexX(meshmemblock,T)
WALLS_VECTOR_Y[1,W,T]=GetMeshMemblockVertexY(meshmemblock,T)
WALLS_VECTOR_Z[1,W,T]=GetMeshMemblockVertexZ(meshmemblock,T)
NEXT
DeleteMemblock(meshmemblock)
endif
if object_hit=Wgrid[x+1,z+1]
inc w
walls[1,w]=CreateObjectBox(0.1,5,5)
walls_type[1,w] =2
x#=GetObjectWorldX(Wgrid[x+1,z+1])
z#=GetObjectWorldz(Wgrid[x+1,z+1])
y#=GetObjectWorldy(Wgrid[x+1,z+1])
SetObjectPosition(walls[1,w],x#,y#,z#)
MoveObjectLocalY(walls[1,w],2.5)
SetObjectCollisionMode(walls[1,w],0)
SetObjectColor(walls[1,w],0,0,200,255)
meshmemblock = CreateMemblockFromObjectMesh(walls[1,W],1)
FOR T=0 TO 23
WALLS_VECTOR_X[1,W,T]=GetMeshMemblockVertexX(meshmemblock,T)
WALLS_VECTOR_Y[1,W,T]=GetMeshMemblockVertexY(meshmemblock,T)
WALLS_VECTOR_Z[1,W,T]=GetMeshMemblockVertexZ(meshmemblock,T)
NEXT
DeleteMemblock(meshmemblock)
endif
if object_hit=Wgrid[x+3,z+3]
inc w
walls_type[1,w] =3
walls[1,w]=CreateObjectBox(5,0.1,5)
x#=GetObjectWorldX(Wgrid[x+3,z+3])
z#=GetObjectWorldz(Wgrid[x+3,z+3])
y#=GetObjectWorldy(Wgrid[x+3,z+3])
SetObjectPosition(walls[1,w],x#,y#,z#)
MoveObjectLocalY(walls[1,w],0.1)
SetObjectCollisionMode(walls[1,w],0)
SetObjectColor(walls[1,w],255,0,0,255)
if GetRawKeyState(asc("R"))
roof(w)
endif
endif
endif
next
next
old=object_hit
endif
if GetRawKeyState(37) then RotateCameraLocalY(1,-3)
if GetRawKeyState(39) then RotateCameraLocalY(1,3)
if GetRawKeyState(38) then moveCameraLocalz(1,2)
if GetRawKeyState(40) then moveCameraLocalz(1,-2)
if GetRawKeyPressed(asc("P"))
for x=1 to 50 step 5
for z=1 to 50 step 5
MoveObjectLocaly(Wgrid[x,z],5)
MoveObjectLocaly(Wgrid[x+1,z+1],5)
MoveObjectLocaly(Wgrid[x+3,z+3],5)
next
next
endif
if GetRawKeyPressed(asc("L"))
for x=1 to 50 step 5
for z=1 to 50 step 5
MoveObjectLocaly(Wgrid[x,z],-5)
MoveObjectLocaly(Wgrid[x+1,z+1],-5)
MoveObjectLocaly(Wgrid[x+3,z+3],-5)
next
next
endif
if GetRawKeyPressed(asc("D"))
for x=1 to 50 step 5
for z=1 to 50 step 5
MoveObjectLocalX(Wgrid[x,z],5)
MoveObjectLocalX(Wgrid[x+1,z+1],5)
MoveObjectLocalX(Wgrid[x+3,z+3],5)
next
next
endif
if GetRawKeyPressed(asc("A"))
for x=1 to 50 step 5
for z=1 to 50 step 5
MoveObjectLocalX(Wgrid[x,z],-5)
MoveObjectLocalX(Wgrid[x+1,z+1],-5)
MoveObjectLocalX(Wgrid[x+3,z+3],-5)
next
next
endif
if GetRawKeyPressed(asc("W"))
for x=1 to 50 step 5
for z=1 to 50 step 5
MoveObjectLocalZ(Wgrid[x,z],5)
MoveObjectLocalZ(Wgrid[x+1,z+1],5)
MoveObjectLocalZ(Wgrid[x+3,z+3],5)
next
next
endif
if GetRawKeyPressed(asc("S"))
for x=1 to 50 step 5
for z=1 to 50 step 5
MoveObjectLocalZ(Wgrid[x,z],-5)
MoveObjectLocalZ(Wgrid[x+1,z+1],-5)
MoveObjectLocalZ(Wgrid[x+3,z+3],-5)
next
next
endif
for t=1 to 255
if GetRawKeyState(t)
Print( t )
endif
next
print ("priess T TO CHOUSE TEXTURE")
print ("HOLD SPACE AND CLICK TO SET TILE TEXTURE")
print ("hold r to make roof")
butx=getspritex(buttons_done1)
butxs=GetSpriteWidth(buttons_done1)
buty=getspritey(buttons_done1)
butys=GetSpriteHeight(buttons_done1)
if pointer_x>butx and pointer_x<butx+butxs
if pointer_y>buty and pointer_y<buty+butys
if GetPointerPressed()
exi1=1
endif
endif
endif
if GetRawKeypressed(asc("T"))
texon=1-texon
endif
for t=1 to images
SetSpriteVisible(buttons[t],texon)
next
for k=1 to images
px=GetPointerX()
py=GetPointery()
tx=getspritex(buttons[k])
ty=getspritey(buttons[k])
if px>tx and px<tx+50
if py>ty and py<ty+50
if GetPointerPressed() and texon=1
tex=k
endif
endif
endif
next
print(tex)
if GetRawKeyState(32)=1
city_block()
endif
DELETEIT=0
if GetRawKeyState(asc("D"))=1
DELETEIT=1
city_block()
endif
Sync()
until exi1=1
for x=1 to 50 step 5
for z=1 to 50 step 5
DeleteObject( Wgrid[x,z])
DeleteObject( Wgrid[x+1,z+1])
DeleteObject( Wgrid[x+3,z+3])
next
next
DELETEOBJECT(GPIVIT)
AY#=GetCameraAngleY(1)
SetCameraRotation(1,0,AY#,0)
endfunction
function roof(box)
y=330
for t=1 to 10
bar[t]=loadsprite("bar.png")
SetSpritePosition(bar[t],500,y)
y=y+40
SetSpriteSize(bar[t],400,15)
next
meshmemblock = CreateMemblockFromObjectMesh(walls[1,box],1)
SetPrintSize(25)
testx#=0
sx#=1:sy#=1:sz#=1
RX#=0
RY#=0
RZ#=0
dis#=-2.5
dis1#=2.5
dis2#=2.5
dis3#=2.5
dis4#=-2.5
bx[1]=700-dis1#
bx[2]=700+dis2#
bx[3]=700+dis3#
bx[4]=700+dis4#
bx[5]=700-dis#
bx[6]=700
bx[7]=700
bx[8]=700
bx[9]=700
bx[10]=700
SetObjectTransparency(walls[1,box],0)
exi=0
repeat
print ("press escape when done")
px#=GetPointerX()
py#=GetPointery()
for t=1 to 10
SetSpriteDepth(bar[t],0)
DrawEllipse(bx[t],getspritey(bar[t])+7,5,5,MakeColor(255,0,0),MakeColor(255,0,0),1)
next
print(px#)
if GetPointerstate()=1
if GetSpriteHit(px#,py#)=bar[1]
if px#>bx[1]
bx[1]=bx[1]+0.1
endif
if px#<bx[1]
bx[1]=bx[1]-0.1
endif
test#=bx[1]-700
dis#=test#
endif
if GetSpriteHit(px#,py#)=bar[2]
if px#>bx[2]
bx[2]=bx[2]+0.1
endif
if px#<bx[2]
bx[2]=bx[2]-0.1
endif
test#=bx[2]-700
dis2#=test#
endif
if GetSpriteHit(px#,py#)=bar[3]
if px#>bx[3]
bx[3]=bx[3]+0.1
endif
if px#<bx[3]
bx[3]=bx[3]-0.1
endif
test#=bx[3]-700
dis3#=test#
endif
if GetSpriteHit(px#,py#)=bar[4]
if px#>bx[4]
bx[4]=bx[4]+0.1
endif
if px#<bx[4]
bx[4]=bx[4]-0.1
endif
test#=bx[4]-700
dis4#=test#
endif
if GetSpriteHit(px#,py#)=bar[5]
if px#>bx[5]
bx[5]=bx[5]+0.1
endif
if px#<bx[5]
bx[5]=bx[5]-0.1
endif
test#=bx[5]-700
dis1#=test#
endif
if GetSpriteHit(px#,py#)=bar[6]
if px#>bx[6]
sx#=sx#+0.3
endif
if px#<bx[6]
sx#=sx#-0.3
endif
bx[6]=px#
endif
if GetSpriteHit(px#,py#)=bar[7]
if px#>bx[7]
sz#=sz#+0.3
endif
if px#<bx[7]
sz#=sz#-0.3
endif
bx[7]=px#
endif
if GetSpriteHit(px#,py#)=bar[8]
bx[8]=px#
ry#=bx[8]-700
SetObjectRotation(walls[1,box],rx#,ry#,rz#)
endif
if GetSpriteHit(px#,py#)=bar[9]
bx[9]=px#
rx#=bx[9]-700
SetObjectRotation(walls[1,box],rx#,ry#,rz#)
endif
if GetSpriteHit(px#,py#)=bar[10]
bx[10]=px#
rz#=bx[10]-700
SetObjectRotation(walls[1,box],rx#,ry#,rz#)
endif
endif
SetObjectScale(walls[1,box],sx#,sy#,sz#)
SetMeshMemblockVertexPosition(meshmemblock, 0,GetMeshMemblockVertexx(meshmemblock,0),dis1#,dis#)
SetMeshMemblockVertexPosition(meshmemblock, 2,GetMeshMemblockVertexx(meshmemblock,2),dis1#,dis#)
SetMeshMemblockVertexPosition(meshmemblock, 9,GetMeshMemblockVertexx(meshmemblock,9),dis1#,dis#)
SetMeshMemblockVertexPosition(meshmemblock, 11,GetMeshMemblockVertexx(meshmemblock,11),dis1#,dis#)
SetMeshMemblockVertexPosition(meshmemblock, 18,GetMeshMemblockVertexx(meshmemblock,18),dis1#,dis#)
SetMeshMemblockVertexPosition(meshmemblock, 4,GetMeshMemblockVertexx(meshmemblock,4),dis1#,dis#)
SetMeshMemblockVertexPosition(meshmemblock, 6,GetMeshMemblockVertexx(meshmemblock,6),dis1#,GetMeshMemblockVertexz(meshmemblock,6))
SetMeshMemblockVertexPosition(meshmemblock, 8,GetMeshMemblockVertexx(meshmemblock,8),dis1#,GetMeshMemblockVertexz(meshmemblock,8))
SetMeshMemblockVertexPosition(meshmemblock, 10,GetMeshMemblockVertexx(meshmemblock,10),dis1#,GetMeshMemblockVertexz(meshmemblock,10))
SetMeshMemblockVertexPosition(meshmemblock, 12,GetMeshMemblockVertexx(meshmemblock,12),dis1#,GetMeshMemblockVertexz(meshmemblock,12))
SetMeshMemblockVertexPosition(meshmemblock, 14,GetMeshMemblockVertexx(meshmemblock,14),dis1#,GetMeshMemblockVertexz(meshmemblock,14))
SetMeshMemblockVertexPosition(meshmemblock, 16,GetMeshMemblockVertexx(meshmemblock,15),dis1#,GetMeshMemblockVertexz(meshmemblock,16))
SetMeshMemblockVertexPosition(meshmemblock, 6,GetMeshMemblockVertexx(meshmemblock,6),dis1#,dis2#)
SetMeshMemblockVertexPosition(meshmemblock, 8,GetMeshMemblockVertexx(meshmemblock,8),dis1#,dis2#)
SetMeshMemblockVertexPosition(meshmemblock, 10,GetMeshMemblockVertexx(meshmemblock,10),dis1#,dis2#)
SetMeshMemblockVertexPosition(meshmemblock, 12,GetMeshMemblockVertexx(meshmemblock,12),dis1#,dis2#)
SetMeshMemblockVertexPosition(meshmemblock,14,GetMeshMemblockVertexx(meshmemblock,14),dis1#,dis2#)
SetMeshMemblockVertexPosition(meshmemblock, 16,GetMeshMemblockVertexx(meshmemblock,16),dis1#,dis2#)
SetMeshMemblockVertexPosition(meshmemblock, 2,dis3#,GetMeshMemblockVertexy(meshmemblock,2),GetMeshMemblockVertexz(meshmemblock,2))
SetMeshMemblockVertexPosition(meshmemblock, 4,dis3#,GetMeshMemblockVertexy(meshmemblock,4),GetMeshMemblockVertexz(meshmemblock,4))
SetMeshMemblockVertexPosition(meshmemblock, 6,dis3#,GetMeshMemblockVertexy(meshmemblock,6),GetMeshMemblockVertexz(meshmemblock,6))
SetMeshMemblockVertexPosition(meshmemblock, 10,dis3#,GetMeshMemblockVertexy(meshmemblock,10),GetMeshMemblockVertexz(meshmemblock,10))
SetMeshMemblockVertexPosition(meshmemblock, 11,dis3#,GetMeshMemblockVertexy(meshmemblock,11),GetMeshMemblockVertexz(meshmemblock,11))
SetMeshMemblockVertexPosition(meshmemblock, 12,dis3#,GetMeshMemblockVertexy(meshmemblock,12),GetMeshMemblockVertexz(meshmemblock,12))
SetMeshMemblockVertexPosition(meshmemblock, 0,dis4#,GetMeshMemblockVertexy(meshmemblock,0),GetMeshMemblockVertexz(meshmemblock,0))
SetMeshMemblockVertexPosition(meshmemblock, 8,dis4#,GetMeshMemblockVertexy(meshmemblock,8),GetMeshMemblockVertexz(meshmemblock,8))
SetMeshMemblockVertexPosition(meshmemblock, 9,dis4#,GetMeshMemblockVertexy(meshmemblock,9),GetMeshMemblockVertexz(meshmemblock,9))
SetMeshMemblockVertexPosition(meshmemblock, 14,dis4#,GetMeshMemblockVertexy(meshmemblock,14),GetMeshMemblockVertexz(meshmemblock,14))
SetMeshMemblockVertexPosition(meshmemblock, 16,dis4#,GetMeshMemblockVertexy(meshmemblock,16),GetMeshMemblockVertexz(meshmemblock,16))
SetMeshMemblockVertexPosition(meshmemblock, 18,dis4#,GetMeshMemblockVertexy(meshmemblock,18),GetMeshMemblockVertexz(meshmemblock,18))
SetObjectMeshFromMemblock(walls[1,box],1,meshmemblock)
sync()
opx#=GetPointerX()
opy#=GetPointery()
RotateCameraLocalX(1,GetRawMouseWheelDelta())
if GetRawKeyState(37) then RotateCameraLocalY(1,-3)
if GetRawKeyState(39) then RotateCameraLocalY(1,3)
if GetRawKeyState(38) then moveCameraLocalz(1,2)
if GetRawKeyState(40) then moveCameraLocalz(1,-2)
if GetRawKeyState(27) then exi=1
until exi=1
FOR T=0 TO 23
WALLS_VECTOR_X[1,BOX,T]=GetMeshMemblockVertexX(meshmemblock,T)
WALLS_VECTOR_Y[1,BOX,T]=GetMeshMemblockVertexY(meshmemblock,T)
WALLS_VECTOR_Z[1,BOX,T]=GetMeshMemblockVertexZ(meshmemblock,T)
NEXT
for t=1 to 10
DeleteSprite(bar[t])
next
endfunction
function position_camera()
click=0
repeat
if GetPointerPressed()
px#=getpointerx()
pz#=1024-getpointery()
y#=GetObjectHeightMapHeight(LAND,px#,pz#)
SetCameraPosition(1,pX#,Y#+50,pZ#)
click=1
endif
sync()
until click=1
endfunction
function city_block()
for c=1 to w
IF GetObjectExists(walls[1,c])=1
SetObjectCollisionMode(walls[1,c],1)
ENDIF
next
SetObjectCollisionMode(land,0)
pointer_x = GetPointerX()
pointer_y = GetPointerY()
// get the x, y and z unit vectors based on the pointer position
unit_x# = Get3DVectorXFromScreen(pointer_x,pointer_y)
unit_y# = Get3DVectorYFromScreen(pointer_x,pointer_y)
unit_z# = Get3DVectorZFromScreen(pointer_x,pointer_y)
// calculate the start of the ray cast, which is the unit vector + the camera position
start_x# = unit_x# + GetCameraX(1)
start_y# = unit_y# + GetCameraY(1)
start_z# = unit_z# + GetCameraZ(1)
// calculate the end of the vector, which is the unit vector multiplied by the length of the ray cast and then add the camera position to it
end_x# = 800*unit_x# + GetCameraX(1)
end_y# = 800*unit_y# + GetCameraY(1)
end_z# = 800*unit_z# + GetCameraZ(1)
// determine which object has been hit
object_hit = ObjectrayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
for q=1 to w
if GetObjectExists(walls[1,q])=1
if object_hit=walls[1,q]
if GetPointerPressed()=1 AND texon=0 AND DELETEIT=0
SetObjectImage(walls[1,q],Wall_papers[tex],0)
walls_teture[1,q]=tex
walls_teture_string [1,q]=wall_papers_string[tex]
SetObjectColor(walls[1,q],255,255,255,255)
endif
if GetPointerPressed()=1 AND texon=0 AND DELETEIT=1
DeleteObject(walls[1,q])
walls_type[1,q] =0
walls[1,q]=0
walls_teture[1,q]=0
walls_teture_string [1,q]=""
endif
endif
endif
next
for c=1 to w
IF GetObjectExists(walls[1,c])=1
SetObjectCollisionMode(walls[1,c],0)
ENDIF
next
SetObjectCollisionMode(land,1)
endfunction
function save_it()
setfolder("")
setfolder("media")
file=opentowrite("imports.dat",0)
WriteInteger(file,import.amount-1)
for t=0 to import.amount-1
WriteString(file,import.model_string[t])
WriteString(file,import.model_texture_string [t])
WriteFloat(file,import.x [t])
WriteFloat(file,import.y [t])
WriteFloat(file,import.z [t])
WriteFloat(file,import.ax [t])
WriteFloat(file,import.ay [t])
WriteFloat(file,import.az [t])
WriteFloat(file,import.sx [t] )
WriteFloat(file,import.sy [t])
WriteFloat(file,import.sz [t])
next
closefile(file)
file=opentowrite("builds.dat",0)
WriteInteger(file,w)
for t=1 to w
if GetObjectExists(walls[1,t])
WriteInteger(file, walls_type[1,t] )
WriteString(file,walls_teture_string [1,t])
WriteFloat(file,walls_x[1,t] )
WriteFloat(file,walls_y[1,t] )
WriteFloat(file,walls_z[1,t] )
WriteFloat(file,walls_ax[1,t] )
WriteFloat(file,walls_ay[1,t] )
WriteFloat(file,walls_az[1,t] )
endif
for q=0 to 23
WriteFloat(file, WALLS_VECTOR_X[1,t,q] )
WriteFloat(file, WALLS_VECTOR_Y[1,t,q] )
WriteFloat(file, WALLS_VECTOR_Z[1,t,q] )
next
next
closefile(file)
file=opentowrite("tiles.dat",0)
WriteInteger(file,count)
for t=1 to count
WriteString(file,ROAD_TEXTURE_STRING[t])
WriteFloat(file,holdx[t])
WriteFloat(file,holdz[t] )
WriteFloat(file,holdy[t] )
next
closefile(file)
file=opentowrite("trees.dat",0)
for t=1 to 100
WriteFloat(file,trees_X[t])
WriteFloat(file,trees_Y[t])
WriteFloat(file,trees_Z[t])
WriteFloat(file,trees_AX[t])
WriteFloat(file,trees_AY[t])
WriteFloat(file,trees_AZ[t])
next
closefile(file)
SaveImage(map,"my_height_map.png")
endfunction
function load_it()
/*
type models
model as integer []
model_texture as integer []
model_string as string []
model_texture_string as string []
x as float []
y as float []
z as float []
ax as float []
ay as float []
az as float []
sx as float []
sy as float []
sz as float []
texture as integer []
amount as integer
endtype
global import as models
dim walls[100,1000] as integer
dim walls_type[100,1000] as integer
dim walls_teture[100,1000] as integer
dim walls_teture_string [100,1000] as string
dim walls_x[100,1000] as float
dim walls_y[100,1000] as float
dim walls_z[100,1000] as float
dim walls_ax[100,1000] as float
dim walls_ay[100,1000] as float
dim walls_az[100,1000] as float
DIM WALLS_VECTOR_X[100,1000,23] AS FLOAT
DIM WALLS_VECTOR_Y[100,1000,23] AS FLOAT
DIM WALLS_VECTOR_Z[100,1000,23] AS FLOAT
dim ROAD[1000] as integer
dim ROAD_TEXTURE[1000] as integer
dim ROAD_TEXTURE_STRING[1000] AS STRING
dim holdx[1000] as float
dim holdz[1000] as float
dim holdy[1000] as float
dim trees[100] as integer
dim trees_X[100] as float
dim trees_Y[100] as float
dim trees_Z[100] as float
dim trees_AX[100] as float
dim trees_AY[100] as float
dim trees_AZ[100] as float
global Count
global memblock
GLOBAL LAND
global w
*/
setfolder("")
setfolder("media")
file=opentoread("imports.dat")
import.amount=readInteger(file)
for t=0 to import.amount-1
import.model_string.insert(ReadString(file))
import.model_texture_string.insert(ReadString(file))
import.x.insert(ReadFloat(file))
import.y.insert(ReadFloat(file))
import.z.insert(ReadFloat(file))
import.ax.insert(ReadFloat(file))
import.ay.insert(ReadFloat(file))
import.az.insert(ReadFloat(file))
import.sx.insert(ReadFloat(file))
import.sy.insert(ReadFloat(file))
import.sz.insert(ReadFloat(file))
import.model.insert(LoadObject(import.model_string[t]))
import.model_texture.insert(loadimage(import.model_texture_string[t]))
SetObjectImage(import.model[t],import.model_texture[t],0)
SetObjectScale(import.model[t],import.sx[t],import.sy[t],import.sz[t])
SetObjectRotation(import.model[t],import.ax[t],import.ay[t],import.az[t])
SetObjectPosition(import.model[t],import.x[t],import.y[t],import.z[t])
SetObjectAlphaMask(import.model[t],1)
next
import.amount=import.amount-1
closefile(file)
file=opentoREAD("builds.dat")
BLANK=ReadInteger(FILE)
W=0
repeat
w=w+1
walls_type[1,W]=ReadINTEGER(FILE)
select walls_type[1,W]
case 1:walls[1,w]=CreateObjectBox(5,5,0.1):endcase
case 2: walls[1,w]=CreateObjectBox(0.1,5,5):endcase
case 3: walls[1,w]=CreateObjectBox(5,0.1,5):endcase
endselect
walls_teture_string [1,w]=readString(file)
walls_teture[1,t]=loadimage(walls_teture_string [1,w])
walls_x[1,t] =ReadFloat(file)
walls_y[1,t] =ReadFloat(file)
walls_z[1,t] =ReadFloat(file)
walls_ax[1,t] =ReadFloat(file)
walls_ay[1,t] =ReadFloat(file)
walls_az[1,t] =ReadFloat(file)
for q=0 to 23
WALLS_VECTOR_X[1,t,q] =ReadFloat(file)
WALLS_VECTOR_Y[1,t,q] =ReadFloat(file)
WALLS_VECTOR_Z[1,t,q] =ReadFloat(file)
next
meshmemblock = CreateMemblockFromObjectMesh(walls[1,t],1)
for q=0 to 23
SetMeshMemblockVertexPosition(meshmemblock,q,
WALLS_VECTOR_X[1,t,q],
WALLS_VECTOR_y[1,t,q],
WALLS_VECTOR_z[1,t,q] )
next
SetObjectMeshFromMemblock(walls[1,t],1,meshmemblock)
DeleteMemblock(meshmemblock)
setobjectimage(walls[1,t],walls_teture[1,t],0)
SetObjectPosition(walls[1,t],walls_x[1,t],walls_y[1,t],walls_z[1,t])
SetObjectRotation(walls[1,t],walls_ax[1,t],walls_ay[1,t],walls_az[1,t])
until FileEOF(file)
closefile(file)
file=opentoread("tiles.dat")
count=ReadInteger(file)
for t=1 to count
road[t]=CreateObjectBox(1024 /50,0.2,1024 /50)
ROAD_TEXTURE[t] =loadimage(ReadString(file))
holdx[t] =ReadFloat(file)
holdz[t] =ReadFloat(file)
holdy[t] =ReadFloat(file)
SetObjectPosition(road[t],holdx[t],holdy[t],holdz[t])
SetObjectImage(road[t],ROAD_TEXTURE[t] ,0)
next
closefile(file)
tree=loadobject("\media\foliage\tree01.x")
SetObjectScale(tree,0.1,0.1,0.1)
tree_image=LoadImage("\media\foliage\tree01_d_result.png")
SetObjectImage(tree,tree_image,0)
SetObjectAlphaMask(tree,1)
SetObjectCollisionMode(tree,0)
SetObjectVisible(tree,0)
file=opentoread("trees.dat")
for t=1 to 100
trees[t]=InstanceObject(tree)
trees_X[t]=ReadFloat(file)
trees_y[t]=ReadFloat(file)
trees_z[t]=ReadFloat(file)
trees_aX[t]=ReadFloat(file)
trees_ay[t]=ReadFloat(file)
trees_az[t]=ReadFloat(file)
SetObjectPosition(trees[t],trees_X[t],trees_Y[t],trees_Z[t])
SetObjectRotation(trees[t],trees_aX[t],trees_aY[t],trees_aZ[t])
next
closefile(file)
LoadImage( 1, "detail.png" )
SetImageWrapU( 1, 1 )
SetImageWrapV( 1, 1 )
// load the terrain shader to give the terrain color based on height
LoadShader( 1, "Terrain.vs", "Terrain.ps" )
// create the terrain object from a height map
LAND=CreateObjectFromHeightMap( "my_height_map.png", 1024, 50, 1024, 4, 16 )
SetObjectImage( LAND, 1, 0 )
SetObjectUVScale( LAND, 0, 128, 128 ) // scale the detail texture so it repeats
SetObjectShader( LAND, 1 )
SetObjectCollisionMode(LAND,1)
SetAmbientColor( 128,128,128 )
WaterNormalImageID=LoadImage("waterNormal.png")
SetImageWrapU(WaterNormalImageID,1)
SetImageWrapV(WaterNormalImageID,1)
WaterObjectID=CreateObjectPlane(1024,1024)
RotateObjectLocalX(WaterObjectID,90)
FixObjectPivot(WaterObjectID)
SetObjectPosition(WaterObjectID,0,-10,40)
SetObjectUVScale(WaterObjectID,0,8,8)
//SP_Water_AddObject(WaterObjectID,WaterNormalImageID)
// SP_Water_SetSunColor(WaterObjectID,190,100,0)
//SP_Water_SetDepthScale(WaterObjectID,0.4)
//SP_Water_SetDepthColorScale(WaterObjectID,0.2)
// SP_Water_SetWaveStrength(WaterObjectID,0)
//SP_Water_SetRefractionHeightScale(1000.3)
endfunction