right on rich

, anyways since theres no code box ill add it on my message,
if you compile this with the latest newton and dbp then it should work the same as the release, hope someone finds it usefull.
Rem Project: Pipe
Rem Created: 26/05/05 17:47:11
Rem ***** Main Source File *****
sync on
sync rate 0
autocam off
hide mouse
set camera range 0.001,1000
`set ambient light 100
color backdrop rgb(0,0,0)
`backdrop off
NDB_NewtonCreate
NDB_SetVector 0.0, -50.0, 0.0
NDB_SetStandardGravity
global obk2
global arrows=800
global foundz
global mapsize
global nobj
global lvlz
global go
global gh
global released
global game_mode
global moves
global mapname$
global movacr
`============================================
`set shadow position -1,200,200,-200
main_menu:
wipe()
color backdrop rgb(0,0,0)
load image "data/2d/background.png",1 : s(1)
load image "data/2d/newgame-dim.png",2 : s(2)
load image "data/2d/newgame-bright.png",3 : s(3)
load image "data/2d/entercode-dim.png",4 : s(4)
load image "data/2d/entercode-bright.png",5 : s(5)
load image "data/2d/leveleditor-dim.png",6 : s(6)
load image "data/2d/leveleditor-bright.png",7 : s(7)
load image "data/2d/quit-dim.png",8 : s(8)
load image "data/2d/quit-bright.png",9 : s(9)
load image "data/2d/puzzlemode-dim.png",10 : s(10)
load image "data/2d/puzzlemode-bright.png",11 : s(11)
load image "data/2d/classicgame-dim.png",12 : s(12)
load image "data/2d/classicgame-bright.png",13 : s(13)
load image "data/2d/precisiongame-dim.png",14 : s(14)
load image "data/2d/precisiongame-bright.png",15 : s(15)
load image "data/2d/back-dim.png",16 : s(16)
load image "data/2d/back-bright.png",17 : s(17)
load image "data/2d/entermapcode.png",19 : s(19)
load image "data/2d/ok-dim.png",20 : s(20)
load image "data/2d/ok-bright.png",21 : s(21)
load image "data/2d/back.png",18,1 : s(18)
load object "data/3d/pipe.x",1 : set object light 1,0
load object "data/3d/light.x",2 : set object light 2,0 : ghost object on 2
load object "data/3d/water.x",3 : set object light 3,0 : ghost object on 3
`fog on
`fog color rgb(0,0,0)
`fog distance 30
if xxd=1
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
load image "data/2d/black.png",997
sprite 997,0,0,997
fade#=255
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
endif
xxd=1
menu=0
lvlz=0
mapname$=""
start_time#=timer()
do
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
omd=md
md=0
md=mouseclick()
mc=0
if md=1 and omd=0 then mc=1
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
`=====
diff#=abs(timer()-start_time#)
start_time#=timer()
diff#=diff#/1000
scfps=screen fps()
`=====
paste sprite 1,0,0
if menu=0
if clicked(2,3,800,500,mc)=1 then menu=1 : mc=0
if clicked(4,5,780,560,mc)=1 then menu=9 : clear entry buffer
if clicked(6,7,760,620,mc)=1 then go=2 : mapeditormap$="0"
if clicked(8,9,740,680,mc)=1 then wipe() : end
msgf$=""
endif
if menu=1
if clicked(10,11,700,500,mc)=1 then go=1 : lvlz=1 : game_mode=0
if clicked(12,13,730,560,mc)=1 then go=0
if clicked(14,15,760,620,mc)=1 then go=1 : lvlz=1 : game_mode=1
if clicked(16,17,790,680,mc)=1 then menu=0 : mc=0
endif
if menu=9
paste sprite 18,0,338
paste sprite 19,210,340
if clicked(16,17,520,390,mc)=1 then menu=0
`================
omd2=md2
md2=0
md2=keystate(14)
mc2=0
if md2=1 and omd2=0 then mc2=1
if mc2=1
if len(msgf$)>0
temp$=""
for i=1 to len(msgf$)-1
temp$=temp$+mid$(msgf$,i)
next i
msgf$=temp$
endif
endif
msgf$=msgf$+entry$()
clear entry buffer
msgf$=convert(msgf$,450,350)
if clicked(20,21,430,390,mc)=1
mapname$=""
if check_input(msgf$)=-1
game_mode=0 : go=1
else
if check_input(msgf$)>0
lvlz=check_input(msgf$) : game_mode=0 : go=1
else
failed2()
endif
endif
endif
`================
endif
sprite 911,mousex(),mousey(),911
if go>0 then goto wadhwd
if gh=1 and sprite exist(997)
fade#=fade#-diff#*500
if fade#<0 then fade#=0
set sprite alpha 997,fade#
if fade#=0 then gh=0 : delete sprite 997
endif
sync
loop
wadhwd:
if go=1 then fade_out() : goto main_game
if go=2 then fade_out() : goto map_editor
`###################################################################################################
`################################ MAP EDITOR ##########################################
`###################################################################################################
map_editor:
wipe()
`add_map("data/3d/net.x",0,0,0,0,0)
`MakeSphere(0,1.2,0,0.45,5)
`load object "data/3d/cage.x",1
`load object "data/3d/walls.x",2 : set object ambience 2, 10 : ghost object on 2 : set object cull 2,0
`set shadow shading on 1,1,10000,1
dim mapp(50)
for i=0 to 50
mapp(i)=0
next i
`add_map("data/3d/pipe-tr.x",-1,0,1,1,0)
load_map(mapeditormap$)
make_cam_light()
add_arrows()
time# = NDB_GetElapsedTimeInSec() : time# = NDB_GetElapsedTimeInSec()
start_time#=timer()
zoom#=150
center=-5
obj2=999
load image "data/2d/addstraight-dim.png",2 : s(2)
load image "data/2d/addstraight-bright.png",3 : s(3)
load image "data/2d/addcurve-dim.png",4 : s(4)
load image "data/2d/addcurve-bright.png",5 : s(5)
load image "data/2d/save-dim.png",6 : s(6)
load image "data/2d/save-bright.png",7 : s(7)
load image "data/2d/rotateaxis-dim.png",8 : s(8)
load image "data/2d/x-dim.png",14 : s(14)
load image "data/2d/x-bright.png",15 : s(15)
load image "data/2d/y-dim.png",16 : s(16)
load image "data/2d/y-bright.png",17 : s(17)
load image "data/2d/z-dim.png",18 : s(18)
load image "data/2d/z-bright.png",19 : s(19)
load image "data/2d/addblock-dim.png",20 : s(20)
load image "data/2d/addblock-bright.png",21 : s(21)
load image "data/2d/clear-dim.png",22 : s(22)
load image "data/2d/clear-bright.png",23 : s(23)
load image "data/2d/entercode-dim.png",24 : s(24)
load image "data/2d/entercode-bright.png",25 : s(25)
load image "data/2d/back-dim.png",26 : s(26)
load image "data/2d/back-bright.png",27 : s(27)
load image "data/2d/ok-dim.png",28 : s(28)
load image "data/2d/ok-bright.png",29 : s(29)
load image "data/2d/entermapcode.png",89 : s(89)
load image "data/2d/quit-dim.png",12 : s(12)
load image "data/2d/quit-bright.png",13 : s(13)
load image "data/2d/bar.png",1,1 : s(1)
load image "data/2d/back.png",88 : s(88)
load object "data/3d/sky.x",993 : set object light 993,0
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
load image "data/2d/black.png",997
sprite 997,0,0,997
fade#=255
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
start_time#=timer()
LOAD_MA=0
do
for i=1 to 1000
if object exist(i)=1 then text object screen x(i),object screen y(i),str$(i)
next i
zomd=zmd
zmd=0
zmd=mouseclick()
zmc=0
if zmd=1 and zomd=0 then zmc=1
IF LOAD_MA=0
paste sprite 1,0,0
if clicked(20,21,200,-4,zmc)=1 then add_map("data/3d/block.x",0,0,0,mapsize,2,mapsize,1,0,0) : load object "data/3d/block.x",nobj+100 : position object nobj+100,mapsize,2,mapsize : mapp(nobj)=3
if clicked(2,3,5,-4,zmc)=1 then add_map("data/3d/pipe-straight.x",0,0,0,mapsize,2,mapsize,1,0,0) : load object "data/3d/pipe-straight-rim.x",nobj+100 : position object nobj+100,mapsize,2,mapsize : mapp(nobj)=1
if clicked(4,5,8,50,zmc)=1 then add_map("data/3d/pipe-bend.x",0,0,0,mapsize,2,mapsize,1,0,0) : load object "data/3d/pipe-bend-rim.x",nobj+100 : position object nobj+100,mapsize,2,mapsize : mapp(nobj)=2
if clicked(6,7,1024-sprite width(6),-4,zmc)=1 then save_map()
paste sprite 8,400,-4
if clicked(22,23,750,0,zmc)=1 then go=3 : mapeditormap$="0"
if clicked(14,15,450,52,zmc)=1 and foundz>4 then rotate object foundz,wrapvalue(oa("x",foundz)+90),oa("y",foundz),oa("z",foundz) : rotate object foundz+100,wrapvalue(oa("x",foundz+100)+90),oa("y",foundz+100),oa("z",foundz+100)
if clicked(16,17,480,52,zmc)=1 and foundz>4 then rotate object foundz,oa("x",foundz),wrapvalue(oa("y",foundz)+90),oa("z",foundz) : rotate object foundz+100,oa("x",foundz+100),wrapvalue(oa("y",foundz+100)+90),oa("z",foundz+100)
if clicked(18,19,510,52,zmc)=1 and foundz>4 then rotate object foundz,oa("x",foundz),oa("y",foundz),wrapvalue(oa("z",foundz)+90) : rotate object foundz+100,oa("x",foundz+100),oa("y",foundz+100),wrapvalue(oa("z",foundz+100)+90)
if clicked(12,13,1014-sprite width(6),50,zmc)=1 then go=2
if clicked(24,25,750,52,zmc)=1 then LOAD_MA=1
`=====
diff#=abs(timer()-start_time#)
start_time#=timer()
diff#=diff#/1000
scfps=screen fps()
`=====
if mouseclick()=2
cax#=cax#+mmy#
cay#=cay#+mmx#
endif
if mouseclick()=3
vmovz#=vmovz#+mmy#/20
endif
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬ CAMERA
mmy#=mousemovey()
mmx#=mousemovex()
if cax#>50 then cax#=50
if cax#<-30 then cax#=-30
if vmovz#>2.5 then vmovz#=2.5
if vmovz#<0 then vmovz#=0
ocax#=camera angle x() : ocay#=camera angle y()
rcax#=curvevalue(cax#,rcax#,scfps/5)
rcay#=curvevalue(cay#,rcay#,scfps/5)
vmov#=curvevalue(vmovz#,vmov#,scfps/5)
position camera mapsize,0-mapsize,mapsize
rotate camera rcax#,wrapvalue(rcay#),0
move camera (center*(2.5+vmov#))
point camera mapsize,0-mapsize,mapsize
scroll_tex((ocax#-camera angle x()),(ocay#-camera angle y()))
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬ RELEASE BALL
selec2(zmc)
pointers(1)
position light 1,camera position x(),camera position y(),camera position z()
sprite 911,mousex(),mousey(),911
if go>0 then exit
if gh=1
fade#=fade#-diff#*500
if fade#<0 then fade#=0
set sprite alpha 997,fade#
if fade#=0 then gh=0 : delete sprite 997
endif
position object 993,camera position x(),camera position y(),camera position z()
msgf$=""
clear entry buffer
ELSE
paste sprite 88,0,338
paste sprite 89,210,340
if clicked(26,27,520,390,zmc)=1 then LOAD_MA=0
`================
omd2=md2
md2=0
md2=keystate(14)
mc2=0
if md2=1 and omd2=0 then mc2=1
if mc2=1
if len(msgf$)>0
temp$=""
for i=1 to len(msgf$)-1
temp$=temp$+mid$(msgf$,i)
next i
msgf$=temp$
endif
endif
msgf$=msgf$+entry$()
clear entry buffer
msgf$=convert(msgf$,450,350)
if clicked(28,29,430,390,zmc)=1
mapname$=""
if check_input2(msgf$)=-1
LOAD_MA=0
go=3 : mapeditormap$=msgf$
else
if check_input2(msgf$)>0
go=3 : mapeditormap$=msgf$ : LOAD_MA=0
else
if failed2()=1 then LOAD_MA=0
endif
endif
endif
`================
sprite 911,mousex(),mousey(),911
ENDIF
sync
loop
if go=2 then fade_out() : goto main_menu
if go=3 then fade_out() : goto map_editor
`###################################################################################################
`###################################################################################################
`###################################################################################################
`###################################################################################################
`################################ MAIN LOOP ###########################################
`###################################################################################################
main_game:
wipe()
`add_map("data/3d/net.x",0,0,0,0,0)
`MakeSphere(0,1.2,0,0.45,5)
`load object "data/3d/cage.x",1
`load object "data/3d/walls.x",2 : set object ambience 2, 10 : ghost object on 2 : set object cull 2,0
`set shadow shading on 1,1,10000,1
`add_map("data/3d/pipe-tr.x",-1,0,1,1,0)
if mapname$=""
load_map(str$(lvlz))
else
load_map(mapname$)
endif
make_cam_light()
add_arrows()
time# = NDB_GetElapsedTimeInSec() : time# = NDB_GetElapsedTimeInSec()
zoom#=150
center=-5
obj2=999
counter#=0
finished#=0
moves=1000
if game_mode=1
if lvlz=1 then moves=1
if lvlz=2 then moves=4
if lvlz=3 then moves=7
if lvlz=4 then moves=6
if lvlz=5 then moves=7
if lvlz=6 then moves=9
if lvlz=7 then moves=2
if lvlz=8 then moves=13
endif
load object "data/3d/sky.x",993 : set object light 993,0
load image "data/2d/ok-dim.png",86 : s(86)
load image "data/2d/ok-bright.png",87 : s(87)
load image "data/2d/back.png",88 : s(88)
load image "data/2d/bar.png",1,1 : s(1)
load image "data/2d/dropball-dim.png",30 : s(30)
load image "data/2d/dropball-bright.png",31 : s(31)
load image "data/2d/forfeit-dim.png",32 : s(32)
load image "data/2d/forfeit-bright.png",33 : s(33)
load image "data/2d/retry-dim.png",34 : s(34)
load image "data/2d/retry-bright.png",35 : s(35)
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
load image "data/2d/black.png",997
sprite 997,0,0,997
fade#=255
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
start_time#=timer()
started=0
pass$=""
pass$=map(lvlz)
if pass$="" then started=1
do
paste sprite 1,0,-50
if game_mode=1
convert("moves left "+str$(moves),380,4)
endif
zomd=zmd
zmd=0
zmd=mouseclick()
zmc=0
if zmd=1 and zomd=0 then zmc=1
if started=0
if lvlz>0
paste sprite 88,0,338
mmg$="level "+str$(lvlz)+" code is "+pass$
convert(mmg$,512-(len(mmg$)*20)/2,350)
if clicked(86,87,512-(sprite width(86)/2),390,zmc)=1 then started=1
else
endif
endif
`=====
diff#=abs(timer()-start_time#)
start_time#=timer()
diff#=diff#/1000
scfps=screen fps()
`=====
if started=1
if mouseclick()=2
cax#=cax#+mmy#
cay#=cay#+mmx#
endif
if mouseclick()=3
vmovz#=vmovz#+mmy#/20
endif
endif
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬ CAMERA
mmy#=mousemovey()
mmx#=mousemovex()
if cax#>50 then cax#=50
if cax#<-30 then cax#=-30
if vmovz#>2.5 then vmovz#=2.5
if vmovz#<0 then vmovz#=0
ocax#=camera angle x() : ocay#=camera angle y()
rcax#=curvevalue(cax#,rcax#,scfps/5)
rcay#=curvevalue(cay#,rcay#,scfps/5)
vmov#=curvevalue(vmovz#,vmov#,scfps/5)
position camera mapsize,0-mapsize,mapsize
rotate camera rcax#,wrapvalue(rcay#),0
move camera (center*(2.5+vmov#))
point camera mapsize,0-mapsize,mapsize
scroll_tex((ocax#-camera angle x()),(ocay#-camera angle y()))
`¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬ RELEASE BALL
if started=1
if released=0
selec(zmc)
pointers(0)
else
foundz=0
for i=arrows to arrow+5
position object i,0,-999999,0
next i
endif
oreleased=released
if clicked(30,31,0,0,zmc)=1 or moves=0 then released=1
if oreleased=0 and released=1 then coli()
if released=1 then counter#=counter#+diff#
endif
time# = NDB_GetElapsedTimeInSec()
if released=1 then NDB_NewtonUpdate time#
`============================================ DEBUG
if dist(5,3)<0.4 then finished#=finished#+diff#
if started=1
if finished#>0.5
if complete()=1
if mapname$=""
go=3 : lvlz=lvlz+1
else
go=1
endif
endif
endif
if counter#>8 or object position y(5)<-40
if failed()=1
go=3
endif
endif
if clicked(32,33,1024-sprite width(32),0,zmc)=1
if failed3()=1
go=1
endif
endif
endif
`============================================
position light 1,camera position x(),camera position y(),camera position z()
sprite 911,mousex(),mousey(),911
if go>0 then exit
if gh=1
fade#=fade#-diff#*500
if fade#<0 then fade#=0
set sprite alpha 997,fade#
if fade#=0 then gh=0 : delete sprite 997
endif
if released=1
for i=arrows to arrow+5
position object i,0,-999999,0
next i
endif
position object 993,camera position x(),camera position y(),camera position z()
sync
loop
if go=3 then fade_out() : goto main_game
if go=1 then fade_out() : goto main_menu
`###################################################################################################
`###################################################################################################
`###################################################################################################
function check_input(in$)
for i=1 to 200
in2$=map(i)
if in$=""
else
if in$=in2$ then maptoload=i : i=201
if file exist("data/maps/"+in$+".dat")=1 then maptoload=-1 : mapname$=in$
endif
next i
if len(in$)<3 then mapname$="" : maptoload=0
endfunction maptoload
`###################################################################################################
function check_input2(in$)
for i=1 to 200
in2$=map(i)
if in$=""
else
if in$=in2$ then maptoload=i : i=201
if file exist("data/maps/"+in$+".dat")=1 then maptoload=-1 : mapname$=in$
endif
next i
endfunction maptoload
`###################################################################################################
function map(No)
if No=1 then nam$="pancake"
if No=2 then nam$="noodle"
if No=3 then nam$="speaker"
if No=4 then nam$="tape"
if No=5 then nam$="monitor"
if No=6 then nam$="cloth"
if No=7 then nam$="table"
if No=8 then nam$="game"
if No=9 then nam$="paper"
if No=10 then nam$="computer"
if No=11 then nam$="screw"
if No=12 then nam$="anvil"
if No=13 then nam$="picture"
if No=14 then nam$="wallet"
if No=15 then nam$="car"
if No=16 then nam$="battery"
if No=17 then nam$="torch"
if No=18 then nam$="pencil"
if No=19 then nam$="tile"
if No=20 then nam$="fence"
endfunction nam$
`###################################################################################################
function load_chars()
for i=0 to 9
load image "data/2d/"+str$(i)+".png",148+i : s(148+i)
next i
for i=0 to 23
load image "data/2d/"+chr$(i+97)+".png",197+i : s(197+i)
next i
load image "data/2d/space.png",132 : s(132)
endfunction
`###################################################################################################
function scroll_tex(my#,mx#)
for i=6 to 50
if object exist(i)=1 then scroll object texture i,mx#/50,my#/50
next i
endfunction
`##########################################################################################
function convert(msg2$,x,y)
`msg$=lower$(msg$)
if len(msg2$)>0
for i=1 to len(msg2$)
filnum=asc(mid$(msg2$,i))
filnum=filnum+100
if sprite exist(filnum)=1 then paste sprite filnum,x+(20*movxh),y : inc movxh : msg$=msg$+mid$(msg2$,i)
next i
endif
endfunction msg$
`##########################################################################################
function dist(Obj1,Obj2)
d1#=abs(abs(object position x(Obj1))-abs(object position x(Obj2)))
d2#=abs(abs(object position y(Obj1))-abs(object position y(Obj2)))
d3#=abs(abs(object position z(Obj1))-abs(object position z(Obj2)))
dist#=(d1#+d2#+d3#)/3
endfunction dist#
`##########################################################################################
function fade_out()
get image 998,0,0,1024,768,1
load image "data/2d/black.png",997
sprite 997,0,0,997
start_time#=timer()
fade#=0
for i=1 to 5
i=1
paste image 998,0,0
diff#=abs(timer()-start_time#)
start_time#=timer()
diff#=diff#/1000
fade#=fade#+diff#*500
if fade#>255 then fade#=255 : i=6
set sprite alpha 997,fade#
sync
next i
endfunction
`##########################################################################################
function complete()
get image 993,0,0,1024,768,1
load image "data/2d/levelcomplete.png",85 : s(85)
load image "data/2d/ok-dim.png",86 : s(86)
load image "data/2d/ok-bright.png",87 : s(87)
load image "data/2d/back.png",88 : s(88)
for i=1 to 5
i=1
zomd=zmd
zmd=0
zmd=mouseclick()
zmc=0
if zmd=1 and zomd=0 then zmc=1
paste image 993,0,0
paste sprite 88,0,298
paste sprite 85,512-(sprite width(85)/2),300
if clicked(86,87,512-(sprite width(86)/2),350,zmc)=1 then i=6 : done=1
sprite 911,mousex(),mousey(),911
sync
next i
endfunction done
`##########################################################################################
function failed()
get image 993,0,0,1024,768,1
load image "data/2d/failed.png",85 : s(85)
load image "data/2d/retry-dim.png",86 : s(86)
load image "data/2d/retry-bright.png",87 : s(87)
load image "data/2d/back.png",88 : s(88)
for i=1 to 5
i=1
zomd=zmd
zmd=0
zmd=mouseclick()
zmc=0
if zmd=1 and zomd=0 then zmc=1
paste image 993,0,0
paste sprite 88,0,298
paste sprite 85,512-(sprite width(85)/2),300
if clicked(86,87,512-(sprite width(86)/2),350,zmc)=1 then i=6 : done=1
sprite 911,mousex(),mousey(),911
sync
next i
endfunction done
`##########################################################################################
function failed3()
get image 993,0,0,1024,768,1
load image "data/2d/failed.png",85 : s(85)
load image "data/2d/ok-dim.png",86 : s(86)
load image "data/2d/ok-bright.png",87 : s(87)
load image "data/2d/back.png",88 : s(88)
for i=1 to 5
i=1
zomd=zmd
zmd=0
zmd=mouseclick()
zmc=0
if zmd=1 and zomd=0 then zmc=1
paste image 993,0,0
paste sprite 88,0,298
paste sprite 85,512-(sprite width(85)/2),300
if clicked(86,87,512-(sprite width(86)/2),350,zmc)=1 then i=6 : done=1
sprite 911,mousex(),mousey(),911
sync
next i
endfunction done
`##########################################################################################
function failed2()
get image 993,0,0,1024,768,1
load image "data/2d/failed.png",85 : s(85)
load image "data/2d/ok-dim.png",86 : s(86)
load image "data/2d/ok-bright.png",87 : s(87)
load image "data/2d/back.png",88 : s(88)
for i=1 to 5
i=1
zomd=zmd
zmd=0
zmd=mouseclick()
zmc=0
if zmd=1 and zomd=0 then zmc=1
paste image 993,0,0
paste sprite 88,0,198
paste sprite 85,512-(sprite width(85)/2),200
if clicked(86,87,512-(sprite width(86)/2),250,zmc)=1 then i=6 : done=1
sprite 911,mousex(),mousey(),911
sync
next i
delete image 85
delete image 86
delete image 87
delete image 993
endfunction done
`##########################################################################################
function save_map()
load image "data/2d/ok-dim.png",86 : s(86)
load image "data/2d/ok-bright.png",87 : s(87)
load image "data/2d/entermapcode.png",88 : s(88)
load image "data/2d/back.png",89 : s(89)
clear entry buffer
for j=1 to 5
j=1
paste sprite 89,0,338
omd=md
md=0
md=keystate(14)
mc=0
if md=1 and omd=0 then mc=1
omd2=md2
md2=0
md2=mouseclick()
mc2=0
if md2=1 and omd2=0 then mc2=1
if mc=1
if len(msgf$)>0
temp$=""
for i=1 to len(msgf$)-1
temp$=temp$+mid$(msgf$,i)
next i
msgf$=temp$
endif
endif
msgf$=msgf$+entry$()
clear entry buffer
paste sprite 88,400-sprite width(88),340
msgf$=convert(msgf$,400,350)
if clicked(86,87,512-(sprite width(86)/2),390,mc2)=1 then j=6
sprite 911,mousex(),mousey(),911
sync
name$=msgf$
next j
`----------------------
set dir "data"
set dir "maps"
fil$=name$+".dat"
if file exist(fil$)=1 then delete file fil$
open to write 3,fil$
write string 3,"Map "+name$
write string 3," "
write string 3,"ADD map"
write string 3,"("
write string 3," 4"
write string 3,")"
write string 3," "
write string 3,"ADD basket"
write string 3,"("
write string 3," "+str$(object position x(3))
write string 3," "+str$(object position y(3))
write string 3," "+str$(object position z(3))
write string 3,")"
write string 3," "
write string 3,"ADD dropper"
write string 3,"("
write string 3," "+str$(object position x(4))
write string 3," "+str$(object position y(4))
write string 3," "+str$(object position z(4))
write string 3,")"
write string 3," "
for i=5 to 50
if mapp(i)>0 and object exist(i)=1
if mapp(i)=1 then write string 3,"ADD straight"
if mapp(i)=2 then write string 3,"ADD bend"
if mapp(i)=3 then write string 3,"ADD block"
write string 3,"("
write string 3," "+str$(object angle x(i))
write string 3," "+str$(object angle y(i))
write string 3," "+str$(object angle z(i))
write string 3," "+str$(object position x(i))
write string 3," "+str$(object position y(i))
write string 3," "+str$(object position z(i))
write string 3,")"
write string 3," "
endif
next i
close file 3
set dir ".."
set dir ".."
endfunction
`##########################################################################################
function coli()
for i=6 to 50
if object exist(i)=1 then update_object(i,1)
next i
endfunction
`##########################################################################################
function selec(mouse)
if mouse=1
ofoundz=foundz
foundz=pick object(mousex(),mousey(),6,50)
foundz2=0
foundz2=pick object(mousex(),mousey(),arrows,arrows+5)
if foundz2>0 then foundz=ofoundz
if foundz=0 then foundz=ofoundz
if foundz2=arrows and op("y",arrows)>-999 then shift_obj(foundz,0,-2,0) : shift_obj(foundz+100,0,-2,0) : moves=moves-1
if foundz2=arrows+1 and op("y",arrows+1)>-999 then shift_obj(foundz,0,2,0) : shift_obj(foundz+100,0,2,0) : moves=moves-1
if foundz2=arrows+2 and op("y",arrows+2)>-999 then shift_obj(foundz,0,0,-2) : shift_obj(foundz+100,0,0,-2) : moves=moves-1
if foundz2=arrows+3 and op("y",arrows+3)>-999 then shift_obj(foundz,2,0,0) : shift_obj(foundz+100,2,0,0) : moves=moves-1
if foundz2=arrows+4 and op("y",arrows+4)>-999 then shift_obj(foundz,0,0,2) : shift_obj(foundz+100,0,0,2) : moves=moves-1
if foundz2=arrows+5 and op("y",arrows+5)>-999 then shift_obj(foundz,-2,0,0) : shift_obj(foundz+100,-2,0,0) : moves=moves-1
endif
if foundz=0
for i=arrows to arrow+5
position object i,0,-999999,0
next i
endif
endfunction foundz
`##########################################################################################
function selec2(mouse)
if mouse=1
if mousey()>110
ofoundz=foundz
foundz=pick object(mousex(),mousey(),3,50)
foundz2=0
foundz2=pick object(mousex(),mousey(),arrows,arrows+5)
if foundz2>0 then foundz=ofoundz
endif
if foundz=0 then foundz=ofoundz
if foundz2=arrows and op("y",arrows)>-999 then shift_obj(foundz,0,-2,0) : shift_obj(foundz+100,0,-2,0)
if foundz2=arrows+1 and op("y",arrows+1)>-999 then shift_obj(foundz,0,2,0) : shift_obj(foundz+100,0,2,0)
if foundz2=arrows+2 and op("y",arrows+2)>-999 then shift_obj(foundz,0,0,-2) : shift_obj(foundz+100,0,0,-2)
if foundz2=arrows+3 and op("y",arrows+3)>-999 then shift_obj(foundz,2,0,0) : shift_obj(foundz+100,2,0,0)
if foundz2=arrows+4 and op("y",arrows+4)>-999 then shift_obj(foundz,0,0,2) : shift_obj(foundz+100,0,0,2)
if foundz2=arrows+5 and op("y",arrows+5)>-999 then shift_obj(foundz,-2,0,0) : shift_obj(foundz+100,-2,0,0)
endif
if foundz=0
for i=arrows to arrow+5
position object i,0,-999999,0
next i
endif
endfunction foundz
`##########################################################################################
function shift_obj(object,x#,y#,z#)
if object exist(object)=1 then position object object,object position x(object)+x#,object position y(object)+y#,object position z(object)+z#
endfunction
`##########################################################################################
function pointers(modz)
if foundz>0
if object exist(foundz)=1
for i=arrows to arrows+5
offzz=0
if foundz=4 then offzz=2
position object i,object position x(foundz),object position y(foundz)+offzz,object position z(foundz)
next i
if modz=0
if object position x(foundz)=0 then position object arrows+5,0,-999999,0
if object position x(foundz)=(mapsize*2)-2 then position object arrows+3,0,-999999,0
if object position y(foundz)=0 then position object arrows+1,0,-999999,0
if object position y(foundz)=(-mapsize*2)+2 then position object arrows,0,-999999,0
if object position z(foundz)=0 then position object arrows+2,0,-999999,0
if object position z(foundz)=(mapsize*2)-2 then position object arrows+4,0,-999999,0
endif
for i=6 to 50
if object exist(i)=1
if op("x",foundz)+2 = op("x",i) and op("y",foundz)=op("y",i) and op("z",foundz)=op("z",i) then position object arrows+3,0,-999999,0
if op("x",foundz)-2 = op("x",i) and op("y",foundz)=op("y",i) and op("z",foundz)=op("z",i) then position object arrows+5,0,-999999,0
if op("y",foundz)+2 = op("y",i) and op("x",foundz)=op("x",i) and op("z",foundz)=op("z",i) then position object arrows+1,0,-999999,0
if op("y",foundz)-2 = op("y",i) and op("x",foundz)=op("x",i) and op("z",foundz)=op("z",i) then position object arrows,0,-999999,0
if op("z",foundz)+2 = op("z",i) and op("x",foundz)=op("x",i) and op("y",foundz)=op("y",i) then position object arrows+4,0,-999999,0
if op("z",foundz)-2 = op("z",i) and op("x",foundz)=op("x",i) and op("y",foundz)=op("y",i) then position object arrows+2,0,-999999,0
endif
next i
endif
endif
endfunction
`##########################################################################################
function op(dir$,object)
if dir$="x" then pos#=object position x(object)
if dir$="y" then pos#=object position y(object)
if dir$="z" then pos#=object position z(object)
endfunction pos#
function oa(dir$,object)
if dir$="x" then pos#=object angle x(object)
if dir$="y" then pos#=object angle y(object)
if dir$="z" then pos#=object angle z(object)
endfunction pos#
`##########################################################################################
function add_arrows()
load object "data/3d/arrow1.x",arrows
load object "data/3d/arrow2.x",arrows+1
load object "data/3d/arrow3.x",arrows+2
load object "data/3d/arrow4.x",arrows+3
load object "data/3d/arrow5.x",arrows+4
load object "data/3d/arrow6.x",arrows+5
for i=arrows to arrows+5
position object i,0,-9999999,0
next i
endfunction
`##########################################################################################
function update_object(obj,flag)
x#=op("x",obj)
y#=op("y",obj)
z#=op("z",obj)
rx#=oa("x",obj)
ry#=oa("y",obj)
rz#=oa("z",obj)
`if flag=1 then ghost object on obj
`if flag=2 then set object transparency obj,1
Col = NDB_NewtonCreateTreeCollision( obj )
`if obj>4 then map(x#/2,y#/2,z#/2,0)=1 : map(x#/2,y#/2,z#/2,1)=obj
Room = NDB_NewtonCreateBody( Col )
NDB_BuildMatrix rx#,ry#,rz#,x#,y#,z#
NDB_NewtonBodySetMatrix room
nobj=obj
NDB_BodySetDBProData Room, obj
NDB_NewtonBodySetDestructorCallback Room
NDB_NewtonReleaseCollision Col
endfunction
function add_map(name$,rx#,ry#,rz#,x#,y#,z#,flag,shadow,collision)
obj = FreeObject()
if shadow=1 then obj=freeobject2()
load object name$, obj
position object obj,x#,y#,z#
rotate object obj,rx#,ry#,rz#
`if flag=1 then ghost object on obj
if flag=1 then set alpha mapping on obj,60
if flag=2 then set object transparency obj,1
if collision=1
Col = NDB_NewtonCreateTreeCollision( obj )
`if obj>4 then map(x#/2,y#/2,z#/2,0)=1 : map(x#/2,y#/2,z#/2,1)=obj
Room = NDB_NewtonCreateBody( Col )
NDB_BuildMatrix rx#,ry#,rz#,x#,y#,z#
NDB_NewtonBodySetMatrix room
NDB_BodySetDBProData Room, obj
NDB_NewtonBodySetDestructorCallback Room
NDB_NewtonReleaseCollision Col
endif
nobj=obj
endfunction
`##########################################################################################
function FreeObject()
repeat
inc i
if object exist(i)=0 then found=1
until found
endfunction i
`##########################################################################################
function FreeObject2()
i=55
repeat
inc i
if object exist(i)=0 then found=1
until found
endfunction i
`##########################################################################################
function NeverCalled()
if memblock exist(1) then delete memblock 1
endfunction
`##########################################################################################
function MakeSphere(x#,y#,z#,s#,mass#)
`NOTE- Newton now allows for elipsoid objects, which are spheres with different radius' for each axis. In this
`demo I am using a single radius (normals sphere), but you can acutally pass 3 radius' into the function to create
`a elipsoid shape.
Col = NDB_NewtonCreateSphere( s# )
Body = NDB_NewtonCreateBody(Col)
`Set initial position and rotation
NDB_BuildMatrix 0.0, 0.0, 0.0, x#, y#, z#
NDB_NewtonBodySetMatrix Body
`notice that I calculate the MI (moment of inertia) for a sphere shape this time.
NDB_CalculateMISphereSolid mass#, s#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "data/3d/ball.x", obj
`set object ambience obj, 50
scale object obj, s#*100.0, s#*100.0, s#*100.0
position object obj, x#, y#, z#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
`##########################################################################################
function s(No)
sprite No,0,0,No
hide sprite No
endfunction
`##########################################################################################
function wipe()
set current bitmap 0
NDB_NewtonDestroy
NDB_NewtonCreate
NDB_SetVector 0.0, -50.0, 0.0
NDB_SetStandardGravity
for I = 1 to 31
if memblock exist(I)
delete memblock I
endif
if bitmap exist(I)
delete bitmap I
endif
if music exist(I)
delete music I
endif
if animation exist(I)
delete animation I
endif
next I
for I = 1 to 65535
if image exist(I)
delete image I
endif
if sprite exist(I)
delete sprite I
endif
if object exist(I)
delete object I
endif
next I
for I = 1 to 1024
if sound exist(I)
delete sound I
endif
next I
for I = 1 to 5
if light exist(I)
delete light I
endif
next I
fog off
rotate camera 0,0,0
position camera 0,0,0
load image "data/2d/mouse.png",911
load_chars()
obk2=0
foundz=0
released=0
go=0
gh=1
endfunction
`##########################################################################################
function make_cam_light()
make light 1
set point light 1, 0,0,0
set light range 1, 500
color light 1,100,100,100
endfunction
`##########################################################################################
function load_map(No$)
dim mapp(50)
for i=1 to 50
mapp(i)=0
next i
movacr=5
dir$="data/maps/"
open to read 1,dir$+No$+".dat"
repeat
if file end(1)=1
found=1
else
read string 1,var1$
if left$(var1$,7)="ADD map"
read string 1,void$
read string 1,var3$ : var3$=remove_spaces(var3$) : var3=val(var3$)
read string 1,void$
obj=FreeObject()
dim map(var3,var3,var3,1)
mapsize=var3
if var3=4 then load object "data/3d/glass.x",obj : load object "data/3d/cage.x",obj+1
ghost object on obj
endif
if left$(var1$,10)="ADD basket"
read string 1,void$
read string 1,var3$ : var3$=remove_spaces(var3$) : var3=val(var3$)
read string 1,var4$ : var4$=remove_spaces(var4$) : var4=val(var4$)
read string 1,var5$ : var5$=remove_spaces(var5$) : var5=val(var5$)
read string 1,void$
add_map("data/3d/net.x",0,0,0,var3,var4,var5,0,0,1)
endif
if left$(var1$,11)="ADD dropper"
read string 1,void$
read string 1,var3$ : var3$=remove_spaces(var3$) : var3=val(var3$)
read string 1,var4$ : var4$=remove_spaces(var4$) : var4=val(var4$)
read string 1,var5$ : var5$=remove_spaces(var5$) : var5=val(var5$)
read string 1,void$ : obj=FreeObject()
load object "data/3d/dropper.x",obj : position object obj,var3,var4,var5
if void$<>")." then MakeSphere(var3,var4+2.2,var5,0.6,1)
endif
if left$(var1$,8)="ADD bend"
read string 1,void$
read string 1,var0$ : var0$=remove_spaces(var0$) : var0=val(var0$)
read string 1,var1$ : var1$=remove_spaces(var1$) : var1=val(var1$)
read string 1,var2$ : var2$=remove_spaces(var2$) : var2=val(var2$)
read string 1,var3$ : var3$=remove_spaces(var3$) : var3=val(var3$)
read string 1,var4$ : var4$=remove_spaces(var4$) : var4=val(var4$)
read string 1,var5$ : var5$=remove_spaces(var5$) : var5=val(var5$)
read string 1,void$
add_map("data/3d/pipe-bend.x",var0,var1,var2,var3,var4,var5,1,0,0)
load object "data/3d/pipe-bend-rim.x",nobj+100 : position object nobj+100,var3,var4,var5 : rotate object nobj+100,var0,var1,var2
mapp(movacr)=2 : movacr=movacr+1
endif
if left$(var1$,12)="ADD straight"
read string 1,void$
read string 1,var0$ : var0$=remove_spaces(var0$) : var0=val(var0$)
read string 1,var1$ : var1$=remove_spaces(var1$) : var1=val(var1$)
read string 1,var2$ : var2$=remove_spaces(var2$) : var2=val(var2$)
read string 1,var3$ : var3$=remove_spaces(var3$) : var3=val(var3$)
read string 1,var4$ : var4$=remove_spaces(var4$) : var4=val(var4$)
read string 1,var5$ : var5$=remove_spaces(var5$) : var5=val(var5$)
read string 1,void$
add_map("data/3d/pipe-straight.x",var0,var1,var2,var3,var4,var5,1,0,0)
load object "data/3d/pipe-straight-rim.x",nobj+100 : position object nobj+100,var3,var4,var5 : rotate object nobj+100,var0,var1,var2
mapp(movacr)=1 : movacr=movacr+1
endif
if left$(var1$,9)="ADD block"
read string 1,void$
read string 1,var0$ : var0$=remove_spaces(var0$) : var0=val(var0$)
read string 1,var1$ : var1$=remove_spaces(var1$) : var1=val(var1$)
read string 1,var2$ : var2$=remove_spaces(var2$) : var2=val(var2$)
read string 1,var3$ : var3$=remove_spaces(var3$) : var3=val(var3$)
read string 1,var4$ : var4$=remove_spaces(var4$) : var4=val(var4$)
read string 1,var5$ : var5$=remove_spaces(var5$) : var5=val(var5$)
read string 1,void$
add_map("data/3d/block.x",var0,var1,var2,var3,var4,var5,0,1,1)
set object smoothing nobj,100
mapp(movacr)=3 : movacr=movacr+1
endif
endif
until found
close file 1
endfunction
`##########################################################################################
function remove_spaces(ent_$)
if left$(ent_$,1)=" "
for i=1 to len(ent_$)
if mid$(ent_$,i)=" "
inc spaces
else
i=999
endif
next i
for i=spaces+1 to len(ent_$)
ret_$=ret_$+mid$(ent_$,i)
next i
endif
endfunction ret_$
`##########################################################################################
function clicked(No1,No2,x,y,mouse)
xlen=sprite width(No1)
ylen=sprite height(No2)
if mousex()>x and mousex()<(x+xlen) and mousey()>y and mousey()<(y+ylen)
paste sprite No2,x,y
if mouse=1 then clicked=1
endif
paste sprite No1,x,y
endfunction clicked