Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Project:
- // Created: 2017-03-06
- // set window properties
- SetWindowTitle( "Project" )
- 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( 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
- Create3DPhysicsWorld()
- Set3DPhysicsGravity(0,0,0)
- SetCameraRange(1,70,3000)
- #include "keys.agc"
- #constant maxobjects=5000
- #constant maxshapes=7
- #constant maxgroups=1
- Type Tobjects
- name$ as string
- x# as float
- y# as float
- z# as float
- sx# as float
- sy# as float
- sz# as float
- scx# as float
- scy# as float
- scz# as float
- friction# as float
- radius# as float
- id as integer
- im as integer
- rotx as integer
- roty as integer
- rotz as integer
- shape as integer
- group as integer
- r as integer
- g as integer
- b as integer
- vis as integer
- tran as integer
- pb as integer
- ps as integer
- selected as integer
- deleted as integer
- master as integer
- slave as integer
- trepeat as integer
- endtype
- type tlights
- lightID as integer
- lightobjectID as integer
- x# as float
- y# as float
- z# as float
- r as integer
- g as integer
- b as integer
- oldr as integer
- oldg as integer
- oldb as integer
- radius# as float
- lightmode as integer
- delay as integer
- olddelay as integer
- lswitch as integer
- lighton as integer
- endtype
- dim object[maxobjects] as Tobjects
- dim light[maxobjects] as tlights
- global r=255
- global g=255
- global b=255
- global cx#=0
- global cy#=0
- global cz#=0
- global sx#=60
- global sy#=60
- global sz#=60
- global scalex#=1
- global scaley#=1
- global scalez#=1
- global xseg#=32
- global yseg#=32
- global rx=0
- global ry=0
- global rz=0
- global radius#=60
- global curs=1
- global collider=12
- global sun=6000
- global CameraDistance#=200
- global ctexture = 6
- global myplane=2
- global shape=2
- global group=0
- global objc=0
- global tran=0
- global group$="Neutral"
- global objectcounter=1
- global groupeditbox=1
- global rxeditbox=2
- global ryeditbox=3
- global rzeditbox=4
- global pbeditbox=5
- global pseditbox=6
- global frictioneditbox=7
- global shapeeditbox=8
- global rededitbox=9
- global blueeditbox=10
- global greeneditbox=11
- global imageeditbox=12
- global sxeditbox=13
- global syeditbox=14
- global szeditbox=15
- global smootheditbox=16
- global scxeditbox=17
- global scyeditbox=18
- global sczeditbox=19
- global trepeateditbox=20
- global delayeditbox=21
- global lightmodeeditbox=22
- global lightoneditbox=23
- global transparencyeditbox=24
- global gametype=0
- global level=1
- global basex#=10
- global basey#=10
- global xgap#=150
- global ygap#=40
- global quit=0
- global smooth#=2.5
- global friction#=0
- global lradius#=180
- global offset=0
- global vis=1
- global pb=1
- global ps=2
- global player=0
- global posi=0
- global walkvel#=200
- global found=0
- global fobjectid=0
- global editmode=0
- global lightcounter=2
- global gun=9
- global div=0
- global trepeat=0
- global delay=5
- global lighton=1
- global lightmode=0
- load_images()
- init()
- repeat
- time$=GetCurrentTime()
- //print(""+str(spritecounter))
- SetTextString(500,time$)
- //print(""+str(objectcounter))
- oldx#=getobjectx(curs)
- oldy#=getobjecty(curs)-sy#/2
- oldz#=getobjectz(curs)
- newx#=getobjectx(curs)
- newy#=getobjecty(curs)+sy#
- newz#=getobjectz(curs)
- objc=caster(oldx#,oldy#,oldz#,newx#,newy#,newz#)
- control()
- //setobjectposition(curs,cx#,cy#,cz#)
- setcameraposition(1,cx#,cy#-CameraDistance#,cz#-CameraDistance#)
- FrameTime#=GetFrameTime()
- //Print( ScreenFPS() )
- if GetPointerPressed()=1
- PointerStartX#=GetPointerX()
- PointerStartY#=GetPointerY()
- endif
- if GetPointerState()=1
- PointerX#=GetPointerX()
- PointerY#=GetPointerY()
- //calculate the distance the pointer traveled while pressing
- PointerDistX#=PointerX#-PointerStartX#
- PointerDistY#=PointerY#-PointerStartY#
- // here we calculate if we swipe vertically or horizontally
- if abs(PointerDistX#)>abs(PointerDistY#)
- // change the camera angle in dependence of the frametime
- CameraAngleY#=CameraAngleY#-PointerDistX#*1.5*FrameTime#
- else
- // change the camera distance in dependence of the frametime
- CameraDistance#=CameraDistance#-PointerDistY#*1.1*FrameTime#
- endif
- endif
- setspriteangle(3,-CameraAngleY#)
- //sin and cos of the camera angle
- Sin#=sin(CameraAngleY#)
- Cos#=cos(CameraAngleY#)
- // calculate the camera position, with curvevalue for the smooth movement
- CameraX#=curvevalue(sin(CameraAngleY#),CameraX#,3)
- CameraZ#=curvevalue(cos(CameraAngleY#),CameraZ#,3)
- setobjectposition(curs,cx#,cy#,cz#)
- setobjectposition(collider,cx#,cy#,cz#)
- setcameraposition(1,cx#+CameraDistance#*0.6*CameraX#,cy#+CameraDistance#-offset*2,cz#+CameraDistance#*0.6*CameraZ#)
- setcameralookat(1,cx#,cy#+offset,cz#,0)
- if GetRawMouseRightPressed()
- endif
- Sync()
- until quit=1
- quit=0
- end
- function control()
- read_boxes()
- if getrawkeypressed(KEY_L)
- inc editmode
- if editmode>1
- editmode=0
- endif
- select editmode
- case 0
- for n=1 to 100
- if geteditboxexists(n)
- seteditboxvisible(n,1)
- endif
- if gettextexists(n)
- settextvisible(n,1)
- endif
- next n
- endcase
- case 1
- for n=1 to 100
- if geteditboxexists(n)
- seteditboxvisible(n,0)
- endif
- if gettextexists(n)
- settextvisible(n,0)
- endif
- next n
- seteditboxvisible(rededitbox,1)
- seteditboxvisible(greeneditbox,1)
- seteditboxvisible(blueeditbox,1)
- seteditboxvisible(lightoneditbox,1)
- seteditboxvisible(lightmodeeditbox,1)
- settextvisible(rededitbox,1)
- settextvisible(greeneditbox,1)
- settextvisible(blueeditbox,1)
- settextvisible(lightoneditbox,1)
- settextvisible(lightmodeeditbox,1)
- scalex#=1.0
- scaley#=1.0
- scalez#=1.0
- seteditboxtext(scxeditbox,"1")
- seteditboxtext(scyeditbox,"1")
- seteditboxtext(sczeditbox,"1")
- endcase
- endselect
- change_cursor(editmode)
- endif
- if getrawkeypressed(KEY_O)
- offset=offset+10
- endif
- if getrawkeypressed(KEY_I)
- offset=offset-10
- endif
- if getrawkeystate(KEY_CONTROL)
- div=4
- else
- div=0
- endif
- if getrawkeypressed(KEY_LEFT)
- if div=0
- cx#=cx#+sx#
- else
- cx#=cx#+smooth#
- endif
- endif
- if getrawkeypressed(KEY_RIGHT)
- if div=0
- cx#=cx#-sx#
- else
- cx#=cx#-smooth#
- endif
- endif
- if getrawkeypressed(KEY_DOWN)
- if div=0
- cz#=cz#+sz#
- else
- cz#=cz#+smooth#
- endif
- endif
- if getrawkeypressed(KEY_UP)
- if div=0
- cz#=cz#-sz#
- else
- cz#=cz#-smooth#
- endif
- endif
- if getrawkeypressed(KEY_LBRACKET)
- inc ctexture
- setspriteimage(1,ctexture)
- seteditboxtext(imageeditbox,str(ctexture))
- endif
- if getrawkeypressed(KEY_RBRACKET) and ctexture>2
- dec ctexture
- setspriteimage(1,ctexture)
- seteditboxtext(imageeditbox,str(ctexture))
- endif
- //************ Place object ********
- if GetRawKeyReleased(KEY_SPACE) and objectcounter<maxobjects and shape<>6
- Select editmode
- case 0
- for n=1 to maxobjects
- if object[n].deleted=1
- found=1
- fobjectid=object[n].ID
- posi=n
- object[n].deleted=0
- exit
- endif
- next n
- select found
- case 0
- select shape
- case 1
- obj=createobjectsphere(radius#,32,32)
- endcase
- case 2
- //obj=loadobject("box.obj")
- obj=createobjectbox(sx#,sy#,sz#)
- endcase
- case 3
- obj=CreateObjectCylinder(sy#,radius#,32)
- endcase
- case 4
- obj=CreateObjectCapsule(radius#/2,sy#,90)
- endcase
- case 5
- obj=createobjectcone(sy#,radius#,32)
- endcase
- case 6
- obj=createobjectplane(sx#,sz#)
- endcase
- endselect
- setobjectposition(obj,cx#,cy#,cz#)
- setobjectscale(obj,scalex#,scaley#,scalez#)
- setobjectrotation(obj,rx,ry,rz)
- setobjectimage(obj,ctexture,0)
- SetObjectTransparency(obj,tran)
- setobjectcolor(obj,r,g,b,255)
- if trepeat=1
- setobjectuvscale(obj,0,1.0*scaley#/2,1.0*scalex#/2)
- elseif trepeat=0
- setobjectuvscale(obj,0,1.0,1.0)
- endif
- set_object_value(obj)
- inc objectcounter
- endcase
- case 1
- select shape
- case 1
- obj=createobjectsphere(radius#,32,32)
- endcase
- case 2
- //obj=loadobject("box.obj")
- obj=createobjectbox(sx#,sy#,sz#)
- endcase
- case 3
- obj=CreateObjectCylinder(sy#,radius#,32)
- endcase
- case 4
- obj=CreateObjectCapsule(radius#/2,sy#,90)
- endcase
- case 5
- obj=createobjectcone(sy#,radius#,32)
- endcase
- case 6
- obj=createobjectplane(sx#,sz#)
- endcase
- endselect
- setobjectposition(obj,cx#,cy#,cz#)
- setobjectscale(obj,scalex#,scaley#,scalez#)
- setobjectrotation(obj,rx,ry,rz)
- setobjectimage(obj,ctexture,0)
- setobjectuvscale(obj,0,0.1/scalez#,0.1/scalex#)
- setobjectcolor(obj,r,g,b,255)
- SetObjectTransparency(obj,tran)
- if trepeat=1
- setobjectuvscale(obj,0,1/scalex#,1.0/scalez#)
- elseif trepeat=0
- setobjectuvscale(obj,0,1.0,1.0)
- endif
- set_object_value2(posi,obj)
- print ("Found deleted!!")
- found=0
- endcase
- endselect
- endcase
- case 1
- createpointlight(lightcounter,cx#,cy#,cz#,lradius#,r,g,b)
- if lighton=0
- setpointlightcolor(lightcounter,0,0,0)
- endif
- lightobject=loadobject("lightbulb.obj")
- setobjectposition(lightobject,cx#,cy#,cz#)
- setobjectcolor(lightobject,r,g,b,255)
- light[lightcounter].x#=cx#
- light[lightcounter].y#=cy#
- light[lightcounter].z#=cz#
- light[lightcounter].r=r
- light[lightcounter].g=g
- light[lightcounter].b=b
- light[lightcounter].oldr=r
- light[lightcounter].oldg=g
- light[lightcounter].oldb=b
- light[lightcounter].radius#=lradius#
- light[lightcounter].delay=delay
- light[lightcounter].olddelay=delay
- light[lightcounter].lightmode=lightmode
- light[lightcounter].lighton=lighton
- light[lightcounter].lightID=lightcounter
- light[lightcounter].lightobjectID=lightobject
- inc lightcounter
- endcase
- endselect
- endif
- if getrawkeypressed(KEY_K)
- for n=2 to 5000
- if light[n].lightobjectID>0
- deleteobject(light[n].lightobjectID)
- deletepointlight(light[n].lightID)
- light[n].lightobjectID=0
- light[n].r=0
- light[n].g=0
- light[n].b=0
- light[n].lighton=0
- light[n].delay=0
- light[n].lswitch=0
- light[n].lightID=0
- light[n].lightmode=0
- light[n].oldr=0
- light[n].oldg=0
- light[n].oldb=0
- light[n].radius#=0
- light[n].x#=0
- light[n].y#=0
- light[n].z#=0
- endif
- next n
- lightcounter=2
- endif
- if getrawkeypressed(KEY_SHIFT)
- if objc>0
- for n=1 to maxobjects
- if object[n].ID=objc and objc<>curs
- print ("hit")
- select object[n].selected
- case 0
- setobjectcolor(objc,255,0,0,100)
- object[n].selected=1
- //inc objectselectedcount
- endcase
- case 1
- setobjectcolor(objc,object[n].r,object[n].g,object[n].b,255)
- object[n].selected=0
- //dec objectselectedcount
- endcase
- endselect
- exit
- endif
- next n
- endif
- endif
- if getrawkeypressed(KEY_DELETE)
- for n=1 to maxobjects
- if object[n].selected=1
- deleteobject(object[n].ID)
- object[n].selected=0
- object[n].deleted=1
- reset_object(n)
- endif
- next n
- endif
- if getrawkeypressed(KEY_A)
- if div=0
- cy#=cy#+sy#
- else
- cy#=cy#+smooth#
- endif
- endif
- if getrawkeypressed(KEY_Z)
- //cy#=cy#-sy#
- if div=0
- cy#=cy#-sy#
- else
- cy#=cy#-smooth#
- endif
- endif
- // change the shape
- if editmode<>1
- if getrawkeypressed(KEY_S)
- inc shape
- if shape>maxshapes
- shape=1
- endif
- change_cursor(0)
- change_edit_boxes()
- endif
- if getrawkeypressed(KEY_G)
- inc group
- if group>maxgroups
- group=0
- endif
- select group
- case 0
- group$="Neutral"
- endcase
- case 1
- group$="Player"
- endcase
- endselect
- settextstring(groupeditbox,group$)
- endif
- endif
- if getrawkeypressed(KEY_Q)
- quit=1
- endif
- if getrawkeypressed(KEY_C)
- clear_level()
- endif
- if getrawkeypressed(KEY_F1)
- load_level(level)
- endif
- if getrawkeypressed(KEY_F4)
- save_level(level)
- endif
- if getrawkeypressed(KEY_T)
- hide_stuff()
- test_level()
- show_stuff()
- endif
- endfunction
- function load_images()
- for n=1 to 200
- f$=str(n) + ".png"
- if getfileexists(f$)
- loadimage (n,f$)
- SetImageWrapU(n,1)
- SetImageWrapV(n,1)
- endif
- next
- endfunction
- function curvevalue(Destination#,Current#,Smooth#)
- Current#=Current#+((Destination#-Current#)/Smooth#)
- endfunction Current#
- function PI()
- endfunction 3.14159265
- function change_cursor(emode)
- if getobjectexists(curs)
- deleteobject(curs)
- endif
- select emode
- case 0
- select shape
- case 1
- createobjectsphere(curs,radius#,32,32)
- endcase
- case 2
- createobjectbox(curs,sx#,sy#,sz#)
- endcase
- case 3
- CreateObjectCylinder(curs,sy#,radius#,32)
- endcase
- case 4
- CreateObjectCapsule(curs,radius#/2,sy#,90)
- endcase
- case 5
- createobjectcone(curs,sy#,radius#,32)
- endcase
- case 6
- createobjectplane(curs,sx#,sz#)
- endcase
- endselect
- endcase
- case 1
- loadobject(curs,"lightbulb.obj")
- endcase
- endselect
- setobjectposition(curs,cx#,cy#,cz#)
- setobjectscale(curs,scalex#,scaley#,scalez#)
- SetObjectTransparency(curs,1)
- setobjectimage(curs,1,0)
- setobjectrotation(curs,rx,ry,rz)
- endfunction
- function create_my_text(number,x#,y#,size,r,g,b,mystring$,depth)
- createtext(number,mystring$)
- settextsize(number,size)
- settextcolor(number,r,g,b,255)
- SetTextPosition(number,x#,y#)
- FixTextToScreen(number,1)
- settextdepth(number,depth)
- //SetTextFontImage ( number, 2 )
- endfunction
- function create_my_editbox(number,x#,y#,bordersize#,r,g,b,backcolor,bsizex#,bsizey#,alpha,box$)
- createeditbox(number)
- SetEditBoxTextSize( number, 20)
- SetEditBoxBorderSize(number,bordersize#)
- SetEditBoxTextColor(number,r,g,b)
- SetEditBoxBorderColor(number,r,g,b,alpha)
- SetEditBoxBackgroundColor( number, 0, 0, 0, alpha )
- seteditboxsize(number,bsizex#,bsizey#)
- SetEditBoxPosition(number,x#,y#)
- FixEditBoxToScreen(number,1)
- seteditboxdepth(number,0)
- SetEditBoxText(number,box$)
- endfunction
- function read_boxes()
- if getrawkeypressed(KEY_ENTER)
- repeat
- focus=GetCurrentEditBox()
- select focus
- //***** Only allow if not in light editing mode (1)
- case groupeditbox
- t$=geteditboxtext(groupeditbox)
- group=val(t$)
- endcase
- case rxeditbox
- t$=geteditboxtext(rxeditbox)
- rx=val(t$)
- setobjectrotation(curs,rx,ry,rz)
- endcase
- case ryeditbox
- t$=geteditboxtext(ryeditbox)
- ry=val(t$)
- setobjectrotation(curs,rx,ry,rz)
- endcase
- case rzeditbox
- t$=geteditboxtext(rzeditbox)
- rz=val(t$)
- setobjectrotation(curs,rx,ry,rz)
- endcase
- case pseditbox
- t$=geteditboxtext(pseditbox)
- ps=val(t$)
- //setobjectrotation(curs,rx,ry,rz)
- endcase
- case pbeditbox
- t$=geteditboxtext(pbeditbox)
- pb=val(t$)
- //setobjectrotation(curs,rx,ry,rz)
- endcase
- case frictioneditbox
- t$=geteditboxtext(frictioneditbox)
- friction#=valfloat(t$)
- //setobjectrotation(curs,rx,ry,rz)
- endcase
- case shapeeditbox
- t$=geteditboxtext(shapeeditbox)
- shape=val(t$)
- change_edit_boxes()
- //setobjectrotation(curs,rx,ry,rz)
- endcase
- case imageeditbox
- t$=geteditboxtext(imageeditbox)
- ctexture=val(t$)
- for n=1 to maxobjects
- if object[n].selected=1
- object[n].selected=0
- setobjectcolor(object[n].id,object[n].r,object[n].g,object[n].b,255)
- object[n].im=ctexture
- setobjectimage(object[n].id,object[n].im,0)
- endif
- next n
- setspriteimage(1,ctexture)
- endcase
- case sxeditbox
- t$=geteditboxtext(sxeditbox)
- sx#=valfloat(t$)
- change_cursor(0)
- endcase
- case syeditbox
- t$=geteditboxtext(syeditbox)
- sy#=valfloat(t$)
- change_cursor(0)
- endcase
- case szeditbox
- t$=geteditboxtext(szeditbox)
- select shape
- case 1
- radius#=valfloat(t$)
- endcase
- case 2
- sz#=valfloat(t$)
- endcase
- case 3
- radius#=valfloat(t$)
- endcase
- case 4
- radius#=valfloat(t$)
- endcase
- endselect
- change_cursor(0)
- endcase
- case scxeditbox
- t$=geteditboxtext(scxeditbox)
- scalex#=valfloat(t$)
- change_cursor(0)
- endcase
- case scyeditbox
- t$=geteditboxtext(scyeditbox)
- scaley#=valfloat(t$)
- change_cursor(0)
- endcase
- case sczeditbox
- t$=geteditboxtext(sczeditbox)
- scalez#=valfloat(t$)
- change_cursor(0)
- endcase
- case smootheditbox
- t$=geteditboxtext(smootheditbox)
- smooth#=valfloat(t$)
- endcase
- case delayeditbox
- t$=geteditboxtext(delayeditbox)
- delay=val(t$)
- endcase
- case transparencyeditbox
- t$=geteditboxtext(transparencyeditbox)
- tran=val(t$)
- endcase
- case trepeateditbox
- t$=geteditboxtext(trepeateditbox)
- trepeat=val(t$)
- endcase
- //******************************************
- //************** Allow this stuff regardless of editmode ***********
- case lightmodeeditbox
- t$=geteditboxtext(lightmodeeditbox)
- lightmode=val(t$)
- endcase
- case lightoneditbox
- t$=geteditboxtext(lightoneditbox)
- lighton=val(t$)
- endcase
- case blueeditbox
- t$=geteditboxtext(blueeditbox)
- b=val(t$)
- setspritecolor(1,r,g,b,255)
- endcase
- case greeneditbox
- t$=geteditboxtext(greeneditbox)
- g=val(t$)
- setspritecolor(1,r,g,b,255)
- endcase
- case rededitbox
- t$=geteditboxtext(rededitbox)
- r=val(t$)
- setspritecolor(1,r,g,b,255)
- endcase
- endselect
- sync()
- until GetRawKeyReleased(KEY_ENTER)
- endif
- endfunction
- function set_object_value(ID)
- object[objectcounter].x#=cx#
- object[objectcounter].y#=cy#
- object[objectcounter].z#=cz#
- object[objectcounter].sx#=sx#
- object[objectcounter].sy#=sy#
- object[objectcounter].sz#=sz#
- object[objectcounter].scx#=scalex#
- object[objectcounter].scy#=scaley#
- object[objectcounter].scz#=scalez#
- object[objectcounter].ID=ID
- object[objectcounter].im=ctexture
- object[objectcounter].rotx=rx
- object[objectcounter].roty=ry
- object[objectcounter].rotz=rz
- object[objectcounter].r=r
- object[objectcounter].g=g
- object[objectcounter].b=b
- object[objectcounter].group=group
- object[objectcounter].shape=shape
- object[objectcounter].radius#=radius#
- object[objectcounter].friction#=friction#
- object[objectcounter].tran=tran
- object[objectcounter].vis=vis
- object[objectcounter].pb=pb
- object[objectcounter].ps=ps
- object[objectcounter].trepeat=trepeat
- endfunction
- function set_object_value2(posi,ID)
- object[posi].x#=cx#
- object[posi].y#=cy#
- object[posi].z#=cz#
- object[posi].sx#=sx#
- object[posi].sy#=sy#
- object[posi].sz#=sz#
- object[posi].scx#=scalex#
- object[posi].scy#=scaley#
- object[posi].scz#=scalez#
- object[posi].ID=ID
- object[posi].im=ctexture
- object[posi].rotx=rx
- object[posi].roty=ry
- object[posi].rotz=rz
- object[posi].r=r
- object[posi].g=g
- object[posi].b=b
- object[posi].group=group
- object[posi].shape=shape
- object[posi].radius#=radius#
- object[posi].friction#=friction#
- object[posi].tran=tran
- object[posi].vis=vis
- object[posi].pb=pb
- object[posi].ps=ps
- object[posi].trepeat=trepeat
- endfunction
- function clear_level()
- for n=1 to maxobjects
- if object[n].ID>0
- deleteobject(object[n].ID)
- object[n].x#=0
- object[n].y#=0
- object[n].z#=0
- object[n].sx#=0
- object[n].sy#=0
- object[n].sz#=0
- object[n].scx#=0
- object[n].scy#=0
- object[n].scz#=0
- object[n].ID=0
- object[n].im=0
- object[n].rotx=0
- object[n].roty=0
- object[n].rotz=0
- object[n].r=0
- object[n].g=0
- object[n].b=0
- object[n].group=0
- object[n].shape=0
- object[n].radius#=0
- object[n].friction#=0
- object[n].tran=0
- object[n].vis=0
- object[n].selected=0
- object[n].deleted=0
- object[n].master=0
- object[n].slave=0
- object[n].trepeat=0
- if light[n].lightobjectID<>0
- deleteobject(light[n].lightobjectID)
- DeletePointLight(light[n].lightID)
- light[n].lightID=0
- light[n].r=0
- light[n].g=0
- light[n].b=0
- light[n].x#=0
- light[n].y#=0
- light[n].z#=0
- light[n].radius#=0
- light[n].delay=0
- light[n].olddelay=0
- light[n].lightmode=0
- light[n].lighton=0
- endif
- endif
- next n
- objectcounter=1
- lightcounter=2
- endfunction
- function caster(oldx#,oldy#,oldz#,newx#,newy#,newz#)
- //pobj = ObjectSpherecast(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,radius#)
- pobj=ObjectRayCast(0,oldx#,oldy#,oldz#,newx#,newy#,newz#)
- if pobj>0
- objc=GetObjectRayCastHitID(0)
- endif
- endfunction objc
- function reset_object(posi)
- object[posi].x#=0
- object[posi].y#=0
- object[posi].z#=0
- object[posi].sx#=0
- object[posi].sy#=0
- object[posi].sz#=0
- object[posi].scx#=0
- object[posi].scy#=0
- object[posi].scz#=0
- object[posi].ID=0
- object[posi].im=0
- object[posi].rotx=0
- object[posi].roty=0
- object[posi].rotz=0
- object[posi].r=0
- object[posi].g=0
- object[posi].b=0
- object[posi].group=0
- object[posi].shape=0
- object[posi].radius#=0
- object[posi].friction#=0
- object[posi].tran=0
- object[posi].vis=0
- object[posi].master=0
- object[posi].slave=0
- object[posi].trepeat=0
- endfunction
- function init()
- setclearcolor(200,200,200)
- clearscreen()
- setsunactive(0)
- SetAmbientColor( 50,50,50 )
- createobjectbox(curs,sx#,sy#,sz#)
- setobjectscale(curs,scalex#,scaley#,scalez#)
- setobjectimage(curs,1,0)
- SetObjectTransparency(curs,1)
- setobjectposition(curs,cx#,cy#,cz#)
- createobjectplane(collider,sx#,sy#)
- setobjectvisible(collider,0)
- SetObjectCollisionMode(collider,0)
- SetObjectCollisionMode(curs,0)
- createobjectplane(myplane,2000,2000)
- setobjectposition(myplane,0,0-sy#,0)
- setobjectrotation(myplane,90,0,0)
- SetObjectCollisionMode(myplane,0)
- setobjectimage(myplane,2,0)
- SetObjectTransparency(myplane,1)
- createsprite(1,ctexture)
- setspritesize(1,128,128)
- setspriteposition(1,870,600)
- //
- create_my_editbox(groupeditbox,basex#+xgap#,basey#,2,255,0,0,0,40,20,255,str(group))
- create_my_editbox(rxeditbox,basex#+xgap#,basey#+ygap#,2,255,0,0,0,40,20,255,"0")
- create_my_editbox(ryeditbox,basex#+xgap#,basey#+ygap#*2,2,255,0,0,0,40,20,255,"0")
- create_my_editbox(rzeditbox,basex#+xgap#,basey#+ygap#*3,2,255,0,0,0,40,20,255,"0")
- create_my_text(groupeditbox,basex#,basey#,25,255,0,0,"Group",0)
- create_my_text(rxeditbox,basex#,basey#+ygap#,25,255,0,0,"Rotate X",0)
- create_my_text(ryeditbox,basex#,basey#+ygap#*2,25,255,0,0,"Rotate Y",0)
- create_my_text(rzeditbox,basex#,basey#+ygap#*3,25,255,0,0,"Rotate Z",0)
- create_my_text(500,-91,basey#+ygap#*18,25,255,0,0,"",0)
- //
- create_my_editbox(pbeditbox,basex#+xgap#*2.5,basey#,2,255,0,0,0,40,20,255,"1")
- create_my_editbox(pseditbox,basex#+xgap#*2.5,basey#+ygap#,2,255,0,0,0,40,20,255,"2")
- create_my_editbox(frictioneditbox,basex#+xgap#*2.5,basey#+ygap#*2,2,255,0,0,0,40,20,255,"0")
- create_my_editbox(shapeeditbox,basex#+xgap#*2.5,basey#+ygap#*3,2,255,0,0,0,40,20,255,"2")
- create_my_text(pbeditbox,basex#+xgap#*1.5,basey#,25,255,0,0,"PhyBody",0)
- create_my_text(pseditbox,basex#+xgap#*1.5,basey#+ygap#,25,255,0,0,"PhyShape",0)
- create_my_text(frictioneditbox,basex#+xgap#*1.5,basey#+ygap#*2,25,255,0,0,"Friction#",0)
- create_my_text(shapeeditbox,basex#+xgap#*1.5,basey#+ygap#*3,25,255,0,0,"Shape",0)
- //
- create_my_editbox(rededitbox,basex#+xgap#*4,basey#,2,255,0,0,0,40,20,255,"255")
- create_my_editbox(greeneditbox,basex#+xgap#*4,basey#+ygap#,2,255,0,0,0,40,20,255,"255")
- create_my_editbox(blueeditbox,basex#+xgap#*4,basey#+ygap#*2,2,255,0,0,0,40,20,255,"255")
- create_my_editbox(imageeditbox,basex#+xgap#*4,basey#+ygap#*3,2,255,0,0,0,40,20,255,str(ctexture))
- create_my_text(rededitbox,basex#+xgap#*3,basey#,25,255,0,0,"RED",0)
- create_my_text(greeneditbox,basex#+xgap#*3,basey#+ygap#,25,255,0,0,"GREEN",0)
- create_my_text(blueeditbox,basex#+xgap#*3,basey#+ygap#*2,25,255,0,0,"BLUE",0)
- create_my_text(imageeditbox,basex#+xgap#*3,basey#+ygap#*3,25,255,0,0,"Texture",0)
- //
- create_my_editbox(sxeditbox,basex#+xgap#*5.5,basey#,2,255,0,0,0,40,20,255,"80")
- create_my_editbox(syeditbox,basex#+xgap#*5.5,basey#+ygap#,2,255,0,0,0,40,20,255,"80")
- create_my_editbox(szeditbox,basex#+xgap#*5.5,basey#+ygap#*2,2,255,0,0,0,40,20,255,"80")
- create_my_editbox(smootheditbox,basex#+xgap#*5.5,basey#+ygap#*3,2,255,0,0,0,40,20,255,"2.5")
- create_my_text(sxeditbox,basex#+xgap#*4.5,basey#,25,255,0,0,"SizeX#",0)
- create_my_text(syeditbox,basex#+xgap#*4.5,basey#+ygap#,25,255,0,0,"SizeY#",0)
- create_my_text(sZeditbox,basex#+xgap#*4.5,basey#+ygap#*2,25,255,0,0,"SizeZ#",0)
- create_my_text(smootheditbox,basex#+xgap#*4.5,basey#+ygap#*3,25,255,0,0,"Smooth#",0)
- create_my_editbox(scxeditbox,basex#+xgap#*6.5,basey#,2,255,0,0,0,40,20,255,"1")
- create_my_editbox(scyeditbox,basex#+xgap#*6.5,basey#+ygap#,2,255,0,0,0,40,20,255,"1")
- create_my_editbox(sczeditbox,basex#+xgap#*6.5,basey#+ygap#*2,2,255,0,0,0,40,20,255,"1")
- create_my_editbox(trepeateditbox,basex#+xgap#*6.5,basey#+ygap#*3,2,255,0,0,0,40,20,255,str(trepeat))
- create_my_text(scxeditbox,basex#+xgap#*5.9,basey#,25,255,0,0,"ScaleX#",0)
- create_my_text(scyeditbox,basex#+xgap#*5.9,basey#+ygap#,25,255,0,0,"ScaleY#",0)
- create_my_text(sczeditbox,basex#+xgap#*5.9,basey#+ygap#*2,25,255,0,0,"ScaleZ#",0)
- create_my_text(trepeateditbox,basex#+xgap#*5.9,basey#+ygap#*3,25,255,0,0,"Trepeat",0)
- create_my_editbox(delayeditbox,basex#+xgap#,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(delay))
- create_my_editbox(lightmodeeditbox,basex#+xgap#*2.5,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(lightmode))
- create_my_editbox(lightoneditbox,basex#+xgap#*4,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(lighton))
- create_my_editbox(transparencyeditbox,basex#+xgap#*5.5,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(tran))
- create_my_text(delayeditbox,basex#,basey#+ygap#*4,25,255,0,0,"Delay",0)
- create_my_text(lightmodeeditbox,basex#+xgap#*1.5,basey#+ygap#*4,25,255,0,0,"LightMode",0)
- create_my_text(lightoneditbox,basex#+xgap#*3,basey#+ygap#*4,25,255,0,0,"LightOn",0)
- create_my_text(transparencyeditbox,basex#+xgap#*4.5,basey#+ygap#*4,25,255,0,0,"Transp",0)
- endfunction
- function load_level(level)
- select gametype
- case 0
- f$="Platformer"
- endcase
- case 1
- f$="Shooter"
- endcase
- endselect
- f$=f$+str(level)
- f$=f$+".lev"
- if getfileexists(f$)=1
- clear_level()
- myfile=opentoread(f$)
- objectcounter=readinteger(myfile)
- lightcounter=readinteger(myfile)
- //cx#=readfloat(myfile)
- //cy#=readfloat(myfile)
- //cz#=readfloat(myfile)
- for n=1 to maxobjects
- object[n].name$=readstring(myfile)
- object[n].x# =readfloat(myfile)
- object[n].y# =readfloat(myfile)
- object[n].z# =readfloat(myfile)
- object[n].sx#=readfloat(myfile)
- object[n].sy#=readfloat(myfile)
- object[n].sz#=readfloat(myfile)
- object[n].scx#=readfloat(myfile)
- object[n].scy#=readfloat(myfile)
- object[n].scz#=readfloat(myfile)
- object[n].friction#=readfloat(myfile)
- object[n].radius#=readfloat(myfile)
- object[n].id=readinteger(myfile)
- object[n].im=readinteger(myfile)
- object[n].rotx=readinteger(myfile)
- object[n].roty=readinteger(myfile)
- object[n].rotz=readinteger(myfile)
- object[n].shape=readinteger(myfile)
- object[n].group=readinteger(myfile)
- object[n].r=readinteger(myfile)
- object[n].g=readinteger(myfile)
- object[n].b=readinteger(myfile)
- object[n].vis=readinteger(myfile)
- object[n].tran=readinteger(myfile)
- object[n].pb=readinteger(myfile)
- object[n].ps=readinteger(myfile)
- object[n].deleted=readinteger(myfile)
- object[n].master=readinteger(myfile)
- object[n].slave=readinteger(myfile)
- object[n].trepeat=readinteger(myfile)
- light[n].lightID=readinteger(myfile)
- light[n].lightobjectID=readinteger(myfile)
- light[n].r=readinteger(myfile)
- light[n].g=readinteger(myfile)
- light[n].b=readinteger(myfile)
- light[n].x#=readfloat(myfile)
- light[n].y#=readfloat(myfile)
- light[n].z#=readfloat(myfile)
- light[n].radius#=readfloat(myfile)
- light[n].delay=readinteger(myfile)
- light[n].olddelay=readinteger(myfile)
- light[n].lightmode=readinteger(myfile)
- light[n].lighton=readinteger(myfile)
- if object[n].id>0
- select object[n].shape
- case 1
- createobjectsphere(object[n].id,object[n].radius#,32,32)
- endcase
- case 2
- createobjectbox(object[n].id,object[n].sx#,object[n].sy#,object[n].sz#)
- endcase
- case 3
- CreateObjectCylinder(object[n].id,object[n].sy#,object[n].radius#,32)
- endcase
- case 4
- obj=CreateObjectCapsule(object[n].radius#,object[n].sy#,90)
- endcase
- case 5
- obj=createobjectcone(object[n].sy#,object[n].radius#,32)
- endcase
- case 6
- obj=createobjectplane(object[n].sx#,object[n].sz#)
- endcase
- endselect
- setobjectimage(object[n].id,object[n].im,0)
- if object[n].trepeat=1
- setobjectuvscale(object[n].id,0,1*object[n].scx#,1.0/object[n].scz#)
- elseif trepeat=0
- setobjectuvscale(object[n].id,0,1.0,1.0)
- endif
- setobjectposition(object[n].id,object[n].x#,object[n].y#,object[n].z#)
- setobjectscale(object[n].id,object[n].scx#,object[n].scy#,object[n].scz#)
- setobjectrotation(object[n].id,object[n].rotx,object[n].roty,object[n].rotz)
- setobjectcolor(object[n].id,object[n].r,object[n].g,object[n].b,255)
- setobjectvisible(object[n].id,1)
- setobjecttransparency(object[n].id,object[n].tran)
- endif
- // place/set the lights
- next n
- closefile(myfile)
- for n=1 to maxobjects
- if light[n].lightobjectID>0
- loadobject(light[n].lightobjectID,"lightbulb.obj")
- setobjectposition(light[n].lightobjectId,light[n].x#,light[n].y#,light[n].z#)
- setobjectcolor(light[n].lightobjectID,light[n].r,light[n].g,light[n].b,255)
- createpointlight(light[n].lightID,light[n].x#,light[n].y#,light[n].z#,light[n].radius#,light[n].r,light[n].g,light[n].b)
- //setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
- endif
- next n
- sys_message(2,500)
- endif
- endfunction
- function save_level(level)
- select gametype
- case 0
- f$="Platformer"
- endcase
- case 1
- f$="Shooter"
- endcase
- endselect
- f$=f$+str(level)
- f$=f$+".lev"
- myfile=opentowrite(f$)
- writeinteger(myfile,objectcounter)
- writeinteger(myfile,lightcounter)
- //writefloat(myfile,cx#)
- //writefloat(myfile,cy#)
- //writefloat(myfile,cz#)
- for n=1 to maxobjects
- writestring(myfile,object[n].name$)
- writefloat(myfile,object[n].x#)
- writefloat(myfile,object[n].y#)
- writefloat(myfile,object[n].z#)
- writefloat(myfile,object[n].sx#)
- writefloat(myfile,object[n].sy#)
- writefloat(myfile,object[n].sz#)
- writefloat(myfile,object[n].scx#)
- writefloat(myfile,object[n].scy#)
- writefloat(myfile,object[n].scz#)
- writefloat(myfile,object[n].friction#)
- writefloat(myfile,object[n].radius#)
- writeinteger(myfile,object[n].id)
- writeinteger(myfile,object[n].im)
- writeinteger(myfile,object[n].rotx)
- writeinteger(myfile,object[n].roty)
- writeinteger(myfile,object[n].rotz)
- writeinteger(myfile,object[n].shape)
- writeinteger(myfile,object[n].group)
- writeinteger(myfile,object[n].r)
- writeinteger(myfile,object[n].g)
- writeinteger(myfile,object[n].b)
- writeinteger(myfile,object[n].vis)
- writeinteger(myfile,object[n].tran)
- writeinteger(myfile,object[n].pb)
- writeinteger(myfile,object[n].ps)
- writeinteger(myfile,object[n].deleted)
- writeinteger(myfile,object[n].master)
- writeinteger(myfile,object[n].slave)
- writeinteger(myfile,object[n].trepeat)
- // write the lights
- writeinteger(myfile,light[n].lightID)
- writeinteger(myfile,light[n].lightobjectID)
- writeinteger(myfile,light[n].r)
- writeinteger(myfile,light[n].g)
- writeinteger(myfile,light[n].b)
- writefloat(myfile,light[n].x#)
- writefloat(myfile,light[n].y#)
- writefloat(myfile,light[n].z#)
- writefloat(myfile,light[n].radius#)
- writeinteger(myfile,light[n].delay)
- writeinteger(myfile,light[n].olddelay)
- writeinteger(myfile,light[n].lightmode)
- writeinteger(myfile,light[n].lighton)
- next n
- closefile(myfile)
- sys_message(1,2000)
- endfunction
- function sys_message(m,del)
- select m
- case 1
- print("Level Saved!!")
- endcase
- case 2
- print("Level Loaded!!")
- endcase
- endselect
- sync()
- sleep(del)
- endfunction
- function createobjectphysics(myobj,myphybody,myphyshape)
- select myphybody
- case 1
- Create3DPhysicsStaticBody(myobj)
- endcase
- case 2
- Create3DPhysicsDynamicBody(myobj)
- endcase
- endselect
- select myphyshape
- case 1
- SetObjectShapesphere(myobj)
- endcase
- case 2
- SetObjectShapebox(myobj)
- endcase
- case 3
- SetObjectShapeCylinder(myobj,90)
- endcase
- endselect
- endfunction
- function test_level()
- //setsunactive(0)
- //SetAmbientColor(0,0,0)
- //setcamerarotation(1,0,180,0)
- //setobjectrotation(player,0,180,0)
- SetAmbientColor( 0,0,0 )
- setcameraposition(1,getobjectx(player),getobjecty(player),getobjectz(player))
- SetCameraRange(1,1,1500)
- addvirtualjoystick(1,100,600,90)
- setobjectposition(curs,-1000000,-1000000,-1000000)
- addvirtualbutton( 1, 94.7,93.1,9.77 )
- addvirtualbutton( 2, 94.7,79.4,9.77 )
- setobjectvisible(myplane,0)
- for n=1 to maxobjects
- if object[n].group=7
- f$="mov1.avi"
- loadvideo(f$)
- playvideotoimage(5000)
- playvideo()
- setobject3dphysicsmass(object[n].id,3)
- exit
- endif
- if object[n].id>0
- createobjectphysics(object[n].id,object[n].pb,object[n].ps)
- //setobject3dphysicsdamping(object[n].id,0.1,0.1)
- //setobject3dphysicsfriction(object[n].id,0.01)
- //setobject3dphysicsrollingfriction(object[n].id,0.01)
- //SetObject3DPhysicsMass(object[n].id,0.5)
- endif
- if object[n].group=1
- player=object[n].id
- px#=object[n].x#
- py#=object[n].y#
- pz#=object[n].z#
- select gametype
- //rem we want an fps controller!
- case 0
- Delete3DPhysicsBody(player)
- Create_character_controller(player)
- endcase
- endselect
- endif
- // if group value is set to 7 then set the texture to that used to render a video onto
- if object[n].group=7
- setobjectimage(object[n].id,5000,0)
- endif
- // hide the light objects used in the editor
- if light[n].lightobjectID>0
- setobjectvisible(light[n].lightobjectID,0)
- endif
- next n
- if gametype=0
- gun = createobjectbox(0.25,0.25,10)
- SetObjectPosition( gun, -15, 0, -50.0 )
- setobjectrotation(gun,0,180,0)
- endif
- repeat
- Step3DPhysicsWorld()
- check_lights()
- rem Old position
- //************ Select based on gametype.. 0 is default and is for fps
- select gametype
- //*******************************************************************
- case 0
- fps_control()
- if ( GetPointerPressed() )
- startx# = GetPointerX()
- starty# = GetPointerY()
- angx# = GetCameraAngleX(1)
- angy# = GetCameraAngleY(1)
- pressed = 1
- endif
- if ( GetPointerState() = 1 )
- fDiffX# = (GetPointerX() - startx#)
- fDiffY# = (GetPointerY() - starty#)
- newX# = angx# + fDiffY#
- if ( newX# > 89 ) then newX# = 89
- if ( newX# < -89 ) then newX# = -89
- SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
- Rotate3DPhysicsCharacterController(player,angy# + fDiffX#)
- endif
- rem Gravity on camera
- SetCameraPosition(1,getobjectx(player),getobjecty(player),getobjectz(player))
- SetObjectRotation(gun,GetCameraAngleX(1),GetCameraAngleY(1),GetCameraAngleZ(1))
- // setobjectposition(gun,getobjectx(player),getobjecty(player),getobjectz(player))
- SetObjectPosition(gun,getcamerax(1),getcameray(1),getcameraz(1))
- SetObjectRotation(gun,GetCameraAngleX(1),GetCameraAngleY(1),GetCameraAngleZ(1))
- MoveObjectLocalZ(gun,6.1)
- MoveObjectLocalx(gun,0.5)
- moveobjectlocaly(gun,-0.4)
- endcase
- //*************************************************************************************
- endselect
- if objc<>0
- //Print("hit object "+str(objc))
- endif
- // posx# = sin(timer()*40) * 250 + 2000
- // SetPointLightPosition( 1, posx#, 565, -3600 )
- //SetObjectPosition( 99, posx#, 565, -3600 )
- rem Framerate prompt
- // print("W A S D or joystick to move, click and drag to rotate")
- fps=ScreenFPS() : Print("FPS: " + str(fps))
- rem Update screen
- if getrawkeypressed(KEY_E)
- quit=1
- endif
- Sync()
- until quit=1
- if getobjectexists(gun)
- deleteobject(gun)
- endif
- quit=0
- Level_cleanup()
- endfunction
- Function Create_character_controller(player)
- characterOffsetVec = CreateVector3( 0.0, 0.0, 0.0 )
- characterOffsetVec2 = CreateVector3( 0.0, 0.0, -12 )
- //This vector indicates the axis your model faces forward.
- //For example if your model faces down the - Z axis use this vector.
- objectOrientationVec = CreateVector3( 0.0, 0.0, -1.0 )
- //The crouchScale parameter is 0.0 to 1.0, for examle 0.75 is 75% of the models standing height.
- `Create3DPhysicsCharacterController(obj, 1, characterOffsetVec, objectOrientationVec, 0.75 )
- Create3DPhysicsCharacterController(player, 1, characterOffsetVec, objectOrientationVec, 0.75 )
- Set3DPhysicsCharacterControllerJumpSpeed(player,9)
- //set3DPhysicsCharacterControllerGravity( player,25 )
- DeleteVector3( characterOffsetVec )
- DeleteVector3( characterOffsetVec2 )
- DeleteVector3( objectOrientationVec )
- endfunction
- function hide_stuff()
- for n=1 to 100
- if gettextexists(n)
- settextvisible(n,0)
- endif
- if geteditboxexists(n)
- seteditboxvisible(n,0)
- endif
- if getspriteexists(n)
- setspritevisible(n,0)
- endif
- next n
- setobjectposition(curs,-100000,-100000,-1000000)
- endfunction
- function show_stuff()
- for n=1 to 100
- if gettextexists(n)
- settextvisible(n,1)
- endif
- if geteditboxexists(n)
- seteditboxvisible(n,1)
- endif
- if getspriteexists(n)
- setspritevisible(n,1)
- endif
- next n
- setobjectvisible(curs,1)
- setobjectposition(curs,cx#,cy#,cz#)
- endfunction
- function Level_cleanup()
- SetAmbientColor( 50,50,50 )
- deletevirtualjoystick(1)
- for n=1 to maxobjects
- if object[n].id>0
- setobjectposition(object[n].id,object[n].x#,object[n].y#,object[n].z#)
- SetObjectRotation(object[n].id,object[n].rotx,object[n].roty,object[n].rotz)
- delete3dphysicsbody(object[n].id)
- endif
- if light[n].lightobjectID>0
- setobjectvisible(light[n].lightobjectID,1)
- endif
- next n
- setobjectvisible(myplane,1)
- setobjectvisible(player,1)
- if Get3DPhysicsCharacterControllerExists(player)
- Delete3DPhysicsCharacterController(player)
- endif
- SetCameraRange(1,100,3000)
- endfunction
- function change_edit_boxes()
- select shape
- case 1
- seteditboxtext(sxeditbox,"32")
- settextstring(sxeditbox,"X Segs")
- seteditboxtext(syeditbox,"32")
- settextstring(syeditbox,"Y Segs")
- seteditboxtext(szeditbox,"80")
- settextstring(szeditbox,"Radius#")
- endcase
- case 2
- seteditboxtext(sxeditbox,"80")
- settextstring(sxeditbox,"SizeX#")
- seteditboxtext(syeditbox,"80")
- settextstring(syeditbox,"SizeY#")
- seteditboxtext(szeditbox,"80")
- settextstring(szeditbox,"SizeZ#")
- endcase
- case 3
- seteditboxtext(sxeditbox,"32")
- settextstring(sxeditbox,"X Segs")
- seteditboxtext(syeditbox,"32")
- settextstring(syeditbox,"Y Segs")
- seteditboxtext(szeditbox,"80")
- settextstring(szeditbox,"Radius#")
- endcase
- endselect
- endfunction
- function check_lights()
- for n=0 to lightcounter-1
- if light[n].lightmode>0 and light[n].lighton=1
- select light[n].lightmode
- // blinking light
- case 1
- dec light[n].delay
- if light[n].delay<=0
- if light[n].lswitch=0
- light[n].lswitch=1
- light[n].delay=light[n].olddelay
- SetPointLightcolor(light[n].lightID,0,0,0)
- elseif light[n].lswitch=1
- light[n].lswitch=0
- light[n].delay=light[n].olddelay
- setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
- endif
- endif
- endcase
- // Flickering Light
- case 2
- dec light[n].delay
- if light[n].delay<=0
- if light[n].lswitch=0
- light[n].lswitch=1
- light[n].delay=random2(2,20)
- SetPointLightcolor(light[n].lightID,0,0,0)
- elseif light[n].lswitch=1
- light[n].lswitch=0
- light[n].delay=random2(2,10)
- setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
- endif
- endif
- endcase
- // Pulsating Light
- case 3
- if light[n].delay>0
- dec light[n].delay
- endif
- if light[n].delay=0
- light[n].delay=light[n].olddelay
- if light[n].lswitch=0
- if light[n].r>0
- light[n].r=light[n].r-10
- endif
- if light[n].g>0
- light[n].g=light[n].g-10
- endif
- if light[n].b>0
- light[n].b=light[n].b-10
- endif
- if light[n].r<=0 and light[n].g<=0 and light[n].b<=0
- light[n].lswitch=1
- endif
- SetPointLightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
- elseif light[n].lswitch=1
- if light[n].r<>light[n].oldr
- light[n].r=light[n].r+10
- endif
- if light[n].g<>light[n].oldg
- light[n].g=light[n].g+10
- endif
- if light[n].b<>light[n].oldb
- light[n].b=light[n].b+10
- endif
- if light[n].r=light[n].oldr and light[n].g=light[n].oldg and light[n].b=light[n].oldb
- light[n].lswitch=0
- endif
- setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
- endif
- endif
- endcase
- endselect
- endif
- next n
- endfunction
- function load_model(currenttexture)
- model$=ChooseRawFile("*.obj")
- if model$>""
- name$=model$
- `myobject[objectnumber].name$=myname$
- pobj=loadobject(model$)
- setobjectposition(pobj,cx#,cy#,cz#)
- setobjectscale(pobj,sx#,sy#,sz#)
- setobjectimage(pobj,currenttexture,0)
- setobjectcolor(pobj,r,g,b,255)
- set_object_value(pobj)
- //inc objpointer
- endif
- endfunction
- function ThrowBall( initialSpeed as float, mass as float, gunPositionVec as integer )
- projectileDirBox as integer
- projectileDirBox = CreateObjectBox( 1.0, 1.0, 1.0 )
- SetObjectPosition( projectileDirBox, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
- //setobjectrotation(projectiledirbox,getobjectanglex(gun),getobjectangley(gun),getobjectanglez(gun))
- MoveObjectLocalZ( projectileDirBox, -1.0 )
- projectileDirVec = CreateVector3( GetobjectX( projectileDirBox )-getobjectx(gun), GetobjectY( projectileDirBox )-getobjecty(gun), GetobjectZ( projectileDirBox )-getobjectz(gun) )
- DeleteObject( projectileDirBox )
- throwBall as integer
- throwBall = CreateObjectSphere( 10, 16, 32 )
- SetObjectImage( throwBall, 12, 0 )
- SetObjectPosition( throwBall, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
- //setobjectrotation(throwball,getobjectanglex(gun),getobjectangley(gun),getobjectanglez(gun))
- //3D Physics code
- Create3DPhysicsDynamicBody( throwBall )
- SetObjectShapeSphere( throwBall )
- SetObject3DPhysicsMass( throwBall, mass )
- SetObject3DPhysicsLinearVelocity( throwBall, projectileDirVec, initialSpeed )
- SetObject3DPhysicsFriction( throwBall, 0.8 )
- SetObject3DPhysicsRollingFriction( throwBall, 0.7 )
- deletevector3(projectileDirVec)
- deletevector3(gunPositionVec)
- endfunction
- function fps_control()
- oldx#=GetCameraX(1)
- oldy#=GetCameraY(1)-45.0
- oldz#=GetCameraZ(1)
- Move3DPhysicsCharacterController( player, 0, walkVel#)
- if ( GetRawKeyState( 87 ) )
- MoveCameraLocalZ( 1, 4 )
- Move3DPhysicsCharacterController(player,1,walkvel#)
- //print("Up")
- endif
- if ( GetRawKeyState( 83 ) )
- MoveCameraLocalZ( 1, -4 )
- Move3DPhysicsCharacterController(player,2,walkvel#)
- // print("Down")
- endif
- if ( GetRawKeyState( 65 ) )
- MoveCameraLocalX( 1, -4 )
- Move3DPhysicsCharacterController(player,3,walkvel#)
- // print("Left")
- endif
- if ( GetRawKeyState( 68 ) )
- MoveCameraLocalX( 1, 4 )
- Move3DPhysicsCharacterController(player,4,walkvel#)
- // print("Right")
- endif
- if ( getvirtualbuttonstate(1) = 1 ) then MoveCameraLocalZ( 1, -4 )
- if ( getvirtualbuttonstate(2) = 1 ) then MoveCameraLocalZ( 1, 4 )
- if ( getrawjoystickexists(1) )
- MoveCameraLocalZ(1,-getrawjoysticky(1)*4)
- MoveCameraLocalX(1,getrawjoystickx(1)*4)
- RotateCameraGlobalY(1,getrawjoystickrx(1)*4)
- RotateCameraLocalX(1,getrawjoystickry(1)*4)
- //RotateobjectGlobalY(player,GetCameraAngleX(1))
- //Rotate3DPhysicsCharacterController(player,getcameraangleY(1))
- endif
- if GetrawkeyPressed(KEY_V)
- //To move dynamic physics bodies we need to apply velocity to the physics body.
- gunPositionVec= CreateVector3(getobjectx(gun),getobjecty(gun), getobjectz(gun) )
- ThrowBall( 190.0, 1.0,gunPositionVec)
- endif
- rem New position
- newx#=GetCameraX(1)
- newy#=GetCameraY(1)-45
- newz#=GetCameraZ(1)`
- rem Adjust Y to match floor
- pobj= ObjectSphereSlide(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,19.0)
- if pobj>0
- newx#=GetObjectRayCastSlideX(0)
- newy#=GetObjectRayCastSlideY(0)
- newz#=GetObjectRayCastSlideZ(0)
- //SetCameraPosition(1,newx#,newy#+45.0,newz#)
- //setobjectposition(player,newx#,newy#,newz#)
- objc=GetObjectRayCastHitID(0)
- endif
- if getrawkeypressed(KEY_SPACE)
- Jump3DPhysicsCharacterController(player)
- endif
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement