Advertisement
raverdave

Untitled

Mar 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.75 KB | None | 0 0
  1.  
  2. // Project:
  3. // Created: 2017-03-06
  4. // set window properties
  5. SetWindowTitle( "Project" )
  6. SetWindowSize( 1024, 768,0 )
  7. SetWindowAllowResize( 1 ) // allow the user to resize the window
  8. // set display properties
  9. SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
  10. SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
  11. SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
  12. SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
  13. UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
  14. Create3DPhysicsWorld()
  15. Set3DPhysicsGravity(0,0,0)
  16. SetCameraRange(1,70,3000)
  17. #include "keys.agc"
  18. #constant maxobjects=5000
  19. #constant maxshapes=7
  20. #constant maxgroups=1
  21. Type Tobjects
  22. name$ as string
  23. x# as float
  24. y# as float
  25. z# as float
  26. sx# as float
  27. sy# as float
  28. sz# as float
  29. scx# as float
  30. scy# as float
  31. scz# as float
  32. friction# as float
  33. radius# as float
  34. id as integer
  35. im as integer
  36. rotx as integer
  37. roty as integer
  38. rotz as integer
  39. shape as integer
  40. group as integer
  41. r as integer
  42. g as integer
  43. b as integer
  44. vis as integer
  45. tran as integer
  46. pb as integer
  47. ps as integer
  48. selected as integer
  49. deleted as integer
  50. master as integer
  51. slave as integer
  52. trepeat as integer
  53. endtype
  54. type tlights
  55. lightID as integer
  56. lightobjectID as integer
  57. x# as float
  58. y# as float
  59. z# as float
  60. r as integer
  61. g as integer
  62. b as integer
  63. oldr as integer
  64. oldg as integer
  65. oldb as integer
  66. radius# as float
  67. lightmode as integer
  68. delay as integer
  69. olddelay as integer
  70. lswitch as integer
  71. lighton as integer
  72. endtype
  73. dim object[maxobjects] as Tobjects
  74. dim light[maxobjects] as tlights
  75. global r=255
  76. global g=255
  77. global b=255
  78. global cx#=0
  79. global cy#=0
  80. global cz#=0
  81. global sx#=60
  82. global sy#=60
  83. global sz#=60
  84. global scalex#=1
  85. global scaley#=1
  86. global scalez#=1
  87. global xseg#=32
  88. global yseg#=32
  89. global rx=0
  90. global ry=0
  91. global rz=0
  92. global radius#=60
  93. global curs=1
  94. global collider=12
  95. global sun=6000
  96. global CameraDistance#=200
  97. global ctexture = 6
  98. global myplane=2
  99. global shape=2
  100. global group=0
  101. global objc=0
  102. global tran=0
  103. global group$="Neutral"
  104. global objectcounter=1
  105. global groupeditbox=1
  106. global rxeditbox=2
  107. global ryeditbox=3
  108. global rzeditbox=4
  109. global pbeditbox=5
  110. global pseditbox=6
  111. global frictioneditbox=7
  112. global shapeeditbox=8
  113. global rededitbox=9
  114. global blueeditbox=10
  115. global greeneditbox=11
  116. global imageeditbox=12
  117. global sxeditbox=13
  118. global syeditbox=14
  119. global szeditbox=15
  120. global smootheditbox=16
  121. global scxeditbox=17
  122. global scyeditbox=18
  123. global sczeditbox=19
  124. global trepeateditbox=20
  125. global delayeditbox=21
  126. global lightmodeeditbox=22
  127. global lightoneditbox=23
  128. global transparencyeditbox=24
  129. global gametype=0
  130. global level=1
  131. global basex#=10
  132. global basey#=10
  133. global xgap#=150
  134. global ygap#=40
  135. global quit=0
  136. global smooth#=2.5
  137. global friction#=0
  138. global lradius#=180
  139. global offset=0
  140. global vis=1
  141. global pb=1
  142. global ps=2
  143. global player=0
  144. global posi=0
  145. global walkvel#=200
  146. global found=0
  147. global fobjectid=0
  148. global editmode=0
  149. global lightcounter=2
  150. global gun=9
  151. global div=0
  152. global trepeat=0
  153. global delay=5
  154. global lighton=1
  155. global lightmode=0
  156. load_images()
  157. init()
  158. repeat
  159. time$=GetCurrentTime()
  160. //print(""+str(spritecounter))
  161. SetTextString(500,time$)
  162. //print(""+str(objectcounter))
  163. oldx#=getobjectx(curs)
  164. oldy#=getobjecty(curs)-sy#/2
  165. oldz#=getobjectz(curs)
  166. newx#=getobjectx(curs)
  167. newy#=getobjecty(curs)+sy#
  168. newz#=getobjectz(curs)
  169. objc=caster(oldx#,oldy#,oldz#,newx#,newy#,newz#)
  170. control()
  171. //setobjectposition(curs,cx#,cy#,cz#)
  172. setcameraposition(1,cx#,cy#-CameraDistance#,cz#-CameraDistance#)
  173. FrameTime#=GetFrameTime()
  174. //Print( ScreenFPS() )
  175. if GetPointerPressed()=1
  176. PointerStartX#=GetPointerX()
  177. PointerStartY#=GetPointerY()
  178. endif
  179. if GetPointerState()=1
  180. PointerX#=GetPointerX()
  181. PointerY#=GetPointerY()
  182. //calculate the distance the pointer traveled while pressing
  183. PointerDistX#=PointerX#-PointerStartX#
  184. PointerDistY#=PointerY#-PointerStartY#
  185. // here we calculate if we swipe vertically or horizontally
  186. if abs(PointerDistX#)>abs(PointerDistY#)
  187. // change the camera angle in dependence of the frametime
  188. CameraAngleY#=CameraAngleY#-PointerDistX#*1.5*FrameTime#
  189. else
  190. // change the camera distance in dependence of the frametime
  191. CameraDistance#=CameraDistance#-PointerDistY#*1.1*FrameTime#
  192. endif
  193. endif
  194. setspriteangle(3,-CameraAngleY#)
  195. //sin and cos of the camera angle
  196. Sin#=sin(CameraAngleY#)
  197. Cos#=cos(CameraAngleY#)
  198. // calculate the camera position, with curvevalue for the smooth movement
  199. CameraX#=curvevalue(sin(CameraAngleY#),CameraX#,3)
  200. CameraZ#=curvevalue(cos(CameraAngleY#),CameraZ#,3)
  201. setobjectposition(curs,cx#,cy#,cz#)
  202. setobjectposition(collider,cx#,cy#,cz#)
  203. setcameraposition(1,cx#+CameraDistance#*0.6*CameraX#,cy#+CameraDistance#-offset*2,cz#+CameraDistance#*0.6*CameraZ#)
  204. setcameralookat(1,cx#,cy#+offset,cz#,0)
  205. if GetRawMouseRightPressed()
  206.  
  207. endif
  208. Sync()
  209. until quit=1
  210. quit=0
  211. end
  212. function control()
  213. read_boxes()
  214. if getrawkeypressed(KEY_L)
  215. inc editmode
  216. if editmode>1
  217. editmode=0
  218. endif
  219. select editmode
  220. case 0
  221. for n=1 to 100
  222. if geteditboxexists(n)
  223. seteditboxvisible(n,1)
  224. endif
  225. if gettextexists(n)
  226. settextvisible(n,1)
  227. endif
  228. next n
  229. endcase
  230. case 1
  231. for n=1 to 100
  232. if geteditboxexists(n)
  233. seteditboxvisible(n,0)
  234. endif
  235. if gettextexists(n)
  236. settextvisible(n,0)
  237. endif
  238. next n
  239. seteditboxvisible(rededitbox,1)
  240. seteditboxvisible(greeneditbox,1)
  241. seteditboxvisible(blueeditbox,1)
  242. seteditboxvisible(lightoneditbox,1)
  243. seteditboxvisible(lightmodeeditbox,1)
  244. settextvisible(rededitbox,1)
  245. settextvisible(greeneditbox,1)
  246. settextvisible(blueeditbox,1)
  247. settextvisible(lightoneditbox,1)
  248. settextvisible(lightmodeeditbox,1)
  249. scalex#=1.0
  250. scaley#=1.0
  251. scalez#=1.0
  252. seteditboxtext(scxeditbox,"1")
  253. seteditboxtext(scyeditbox,"1")
  254. seteditboxtext(sczeditbox,"1")
  255. endcase
  256. endselect
  257. change_cursor(editmode)
  258. endif
  259. if getrawkeypressed(KEY_O)
  260. offset=offset+10
  261. endif
  262. if getrawkeypressed(KEY_I)
  263. offset=offset-10
  264. endif
  265. if getrawkeystate(KEY_CONTROL)
  266. div=4
  267. else
  268. div=0
  269. endif
  270. if getrawkeypressed(KEY_LEFT)
  271. if div=0
  272. cx#=cx#+sx#
  273. else
  274. cx#=cx#+smooth#
  275. endif
  276. endif
  277. if getrawkeypressed(KEY_RIGHT)
  278. if div=0
  279. cx#=cx#-sx#
  280. else
  281. cx#=cx#-smooth#
  282. endif
  283. endif
  284. if getrawkeypressed(KEY_DOWN)
  285. if div=0
  286. cz#=cz#+sz#
  287. else
  288. cz#=cz#+smooth#
  289. endif
  290. endif
  291. if getrawkeypressed(KEY_UP)
  292. if div=0
  293. cz#=cz#-sz#
  294. else
  295. cz#=cz#-smooth#
  296. endif
  297. endif
  298. if getrawkeypressed(KEY_LBRACKET)
  299. inc ctexture
  300. setspriteimage(1,ctexture)
  301. seteditboxtext(imageeditbox,str(ctexture))
  302. endif
  303. if getrawkeypressed(KEY_RBRACKET) and ctexture>2
  304. dec ctexture
  305. setspriteimage(1,ctexture)
  306. seteditboxtext(imageeditbox,str(ctexture))
  307. endif
  308. //************ Place object ********
  309. if GetRawKeyReleased(KEY_SPACE) and objectcounter<maxobjects and shape<>6
  310. Select editmode
  311. case 0
  312. for n=1 to maxobjects
  313. if object[n].deleted=1
  314. found=1
  315. fobjectid=object[n].ID
  316. posi=n
  317. object[n].deleted=0
  318. exit
  319. endif
  320. next n
  321. select found
  322. case 0
  323. select shape
  324. case 1
  325. obj=createobjectsphere(radius#,32,32)
  326. endcase
  327. case 2
  328. //obj=loadobject("box.obj")
  329.  
  330. obj=createobjectbox(sx#,sy#,sz#)
  331. endcase
  332. case 3
  333. obj=CreateObjectCylinder(sy#,radius#,32)
  334. endcase
  335. case 4
  336. obj=CreateObjectCapsule(radius#/2,sy#,90)
  337. endcase
  338. case 5
  339. obj=createobjectcone(sy#,radius#,32)
  340. endcase
  341. case 6
  342. obj=createobjectplane(sx#,sz#)
  343. endcase
  344. endselect
  345. setobjectposition(obj,cx#,cy#,cz#)
  346. setobjectscale(obj,scalex#,scaley#,scalez#)
  347. setobjectrotation(obj,rx,ry,rz)
  348. setobjectimage(obj,ctexture,0)
  349. SetObjectTransparency(obj,tran)
  350. setobjectcolor(obj,r,g,b,255)
  351. if trepeat=1
  352. setobjectuvscale(obj,0,1.0*scaley#/2,1.0*scalex#/2)
  353. elseif trepeat=0
  354. setobjectuvscale(obj,0,1.0,1.0)
  355. endif
  356. set_object_value(obj)
  357. inc objectcounter
  358. endcase
  359. case 1
  360. select shape
  361. case 1
  362. obj=createobjectsphere(radius#,32,32)
  363. endcase
  364. case 2
  365. //obj=loadobject("box.obj")
  366. obj=createobjectbox(sx#,sy#,sz#)
  367. endcase
  368. case 3
  369. obj=CreateObjectCylinder(sy#,radius#,32)
  370. endcase
  371. case 4
  372. obj=CreateObjectCapsule(radius#/2,sy#,90)
  373. endcase
  374. case 5
  375. obj=createobjectcone(sy#,radius#,32)
  376. endcase
  377. case 6
  378. obj=createobjectplane(sx#,sz#)
  379. endcase
  380. endselect
  381. setobjectposition(obj,cx#,cy#,cz#)
  382. setobjectscale(obj,scalex#,scaley#,scalez#)
  383. setobjectrotation(obj,rx,ry,rz)
  384. setobjectimage(obj,ctexture,0)
  385. setobjectuvscale(obj,0,0.1/scalez#,0.1/scalex#)
  386. setobjectcolor(obj,r,g,b,255)
  387. SetObjectTransparency(obj,tran)
  388. if trepeat=1
  389. setobjectuvscale(obj,0,1/scalex#,1.0/scalez#)
  390. elseif trepeat=0
  391. setobjectuvscale(obj,0,1.0,1.0)
  392. endif
  393. set_object_value2(posi,obj)
  394. print ("Found deleted!!")
  395. found=0
  396. endcase
  397. endselect
  398. endcase
  399. case 1
  400. createpointlight(lightcounter,cx#,cy#,cz#,lradius#,r,g,b)
  401. if lighton=0
  402. setpointlightcolor(lightcounter,0,0,0)
  403. endif
  404. lightobject=loadobject("lightbulb.obj")
  405. setobjectposition(lightobject,cx#,cy#,cz#)
  406. setobjectcolor(lightobject,r,g,b,255)
  407. light[lightcounter].x#=cx#
  408. light[lightcounter].y#=cy#
  409. light[lightcounter].z#=cz#
  410. light[lightcounter].r=r
  411. light[lightcounter].g=g
  412. light[lightcounter].b=b
  413. light[lightcounter].oldr=r
  414. light[lightcounter].oldg=g
  415. light[lightcounter].oldb=b
  416. light[lightcounter].radius#=lradius#
  417. light[lightcounter].delay=delay
  418. light[lightcounter].olddelay=delay
  419. light[lightcounter].lightmode=lightmode
  420. light[lightcounter].lighton=lighton
  421. light[lightcounter].lightID=lightcounter
  422. light[lightcounter].lightobjectID=lightobject
  423. inc lightcounter
  424. endcase
  425. endselect
  426. endif
  427. if getrawkeypressed(KEY_K)
  428. for n=2 to 5000
  429. if light[n].lightobjectID>0
  430. deleteobject(light[n].lightobjectID)
  431. deletepointlight(light[n].lightID)
  432. light[n].lightobjectID=0
  433. light[n].r=0
  434. light[n].g=0
  435. light[n].b=0
  436. light[n].lighton=0
  437. light[n].delay=0
  438. light[n].lswitch=0
  439. light[n].lightID=0
  440. light[n].lightmode=0
  441. light[n].oldr=0
  442. light[n].oldg=0
  443. light[n].oldb=0
  444. light[n].radius#=0
  445. light[n].x#=0
  446. light[n].y#=0
  447. light[n].z#=0
  448. endif
  449.  
  450. next n
  451. lightcounter=2
  452. endif
  453. if getrawkeypressed(KEY_SHIFT)
  454. if objc>0
  455. for n=1 to maxobjects
  456. if object[n].ID=objc and objc<>curs
  457. print ("hit")
  458. select object[n].selected
  459. case 0
  460. setobjectcolor(objc,255,0,0,100)
  461. object[n].selected=1
  462. //inc objectselectedcount
  463. endcase
  464. case 1
  465. setobjectcolor(objc,object[n].r,object[n].g,object[n].b,255)
  466. object[n].selected=0
  467. //dec objectselectedcount
  468. endcase
  469. endselect
  470.  
  471. exit
  472. endif
  473. next n
  474. endif
  475. endif
  476. if getrawkeypressed(KEY_DELETE)
  477. for n=1 to maxobjects
  478. if object[n].selected=1
  479. deleteobject(object[n].ID)
  480. object[n].selected=0
  481. object[n].deleted=1
  482. reset_object(n)
  483. endif
  484. next n
  485. endif
  486. if getrawkeypressed(KEY_A)
  487. if div=0
  488. cy#=cy#+sy#
  489. else
  490. cy#=cy#+smooth#
  491. endif
  492. endif
  493. if getrawkeypressed(KEY_Z)
  494. //cy#=cy#-sy#
  495. if div=0
  496. cy#=cy#-sy#
  497. else
  498. cy#=cy#-smooth#
  499. endif
  500. endif
  501. // change the shape
  502. if editmode<>1
  503. if getrawkeypressed(KEY_S)
  504. inc shape
  505. if shape>maxshapes
  506. shape=1
  507. endif
  508. change_cursor(0)
  509. change_edit_boxes()
  510. endif
  511. if getrawkeypressed(KEY_G)
  512. inc group
  513. if group>maxgroups
  514. group=0
  515. endif
  516. select group
  517. case 0
  518. group$="Neutral"
  519. endcase
  520. case 1
  521. group$="Player"
  522. endcase
  523. endselect
  524. settextstring(groupeditbox,group$)
  525. endif
  526. endif
  527. if getrawkeypressed(KEY_Q)
  528. quit=1
  529. endif
  530. if getrawkeypressed(KEY_C)
  531. clear_level()
  532. endif
  533. if getrawkeypressed(KEY_F1)
  534. load_level(level)
  535. endif
  536. if getrawkeypressed(KEY_F4)
  537. save_level(level)
  538. endif
  539. if getrawkeypressed(KEY_T)
  540. hide_stuff()
  541. test_level()
  542. show_stuff()
  543. endif
  544. endfunction
  545. function load_images()
  546. for n=1 to 200
  547. f$=str(n) + ".png"
  548. if getfileexists(f$)
  549. loadimage (n,f$)
  550. SetImageWrapU(n,1)
  551. SetImageWrapV(n,1)
  552. endif
  553. next
  554. endfunction
  555. function curvevalue(Destination#,Current#,Smooth#)
  556. Current#=Current#+((Destination#-Current#)/Smooth#)
  557. endfunction Current#
  558. function PI()
  559. endfunction 3.14159265
  560. function change_cursor(emode)
  561. if getobjectexists(curs)
  562. deleteobject(curs)
  563. endif
  564. select emode
  565. case 0
  566.  
  567. select shape
  568. case 1
  569. createobjectsphere(curs,radius#,32,32)
  570. endcase
  571.  
  572. case 2
  573. createobjectbox(curs,sx#,sy#,sz#)
  574. endcase
  575. case 3
  576. CreateObjectCylinder(curs,sy#,radius#,32)
  577. endcase
  578. case 4
  579. CreateObjectCapsule(curs,radius#/2,sy#,90)
  580. endcase
  581. case 5
  582. createobjectcone(curs,sy#,radius#,32)
  583. endcase
  584. case 6
  585. createobjectplane(curs,sx#,sz#)
  586. endcase
  587. endselect
  588. endcase
  589. case 1
  590. loadobject(curs,"lightbulb.obj")
  591. endcase
  592. endselect
  593. setobjectposition(curs,cx#,cy#,cz#)
  594. setobjectscale(curs,scalex#,scaley#,scalez#)
  595. SetObjectTransparency(curs,1)
  596. setobjectimage(curs,1,0)
  597. setobjectrotation(curs,rx,ry,rz)
  598. endfunction
  599. function create_my_text(number,x#,y#,size,r,g,b,mystring$,depth)
  600. createtext(number,mystring$)
  601. settextsize(number,size)
  602. settextcolor(number,r,g,b,255)
  603. SetTextPosition(number,x#,y#)
  604. FixTextToScreen(number,1)
  605. settextdepth(number,depth)
  606. //SetTextFontImage ( number, 2 )
  607. endfunction
  608. function create_my_editbox(number,x#,y#,bordersize#,r,g,b,backcolor,bsizex#,bsizey#,alpha,box$)
  609. createeditbox(number)
  610. SetEditBoxTextSize( number, 20)
  611. SetEditBoxBorderSize(number,bordersize#)
  612. SetEditBoxTextColor(number,r,g,b)
  613. SetEditBoxBorderColor(number,r,g,b,alpha)
  614. SetEditBoxBackgroundColor( number, 0, 0, 0, alpha )
  615. seteditboxsize(number,bsizex#,bsizey#)
  616. SetEditBoxPosition(number,x#,y#)
  617. FixEditBoxToScreen(number,1)
  618. seteditboxdepth(number,0)
  619. SetEditBoxText(number,box$)
  620. endfunction
  621. function read_boxes()
  622. if getrawkeypressed(KEY_ENTER)
  623. repeat
  624. focus=GetCurrentEditBox()
  625. select focus
  626. //***** Only allow if not in light editing mode (1)
  627. case groupeditbox
  628. t$=geteditboxtext(groupeditbox)
  629. group=val(t$)
  630. endcase
  631. case rxeditbox
  632. t$=geteditboxtext(rxeditbox)
  633. rx=val(t$)
  634. setobjectrotation(curs,rx,ry,rz)
  635. endcase
  636. case ryeditbox
  637. t$=geteditboxtext(ryeditbox)
  638. ry=val(t$)
  639. setobjectrotation(curs,rx,ry,rz)
  640. endcase
  641. case rzeditbox
  642. t$=geteditboxtext(rzeditbox)
  643. rz=val(t$)
  644. setobjectrotation(curs,rx,ry,rz)
  645. endcase
  646. case pseditbox
  647. t$=geteditboxtext(pseditbox)
  648. ps=val(t$)
  649. //setobjectrotation(curs,rx,ry,rz)
  650. endcase
  651. case pbeditbox
  652. t$=geteditboxtext(pbeditbox)
  653. pb=val(t$)
  654. //setobjectrotation(curs,rx,ry,rz)
  655. endcase
  656. case frictioneditbox
  657. t$=geteditboxtext(frictioneditbox)
  658. friction#=valfloat(t$)
  659. //setobjectrotation(curs,rx,ry,rz)
  660. endcase
  661. case shapeeditbox
  662. t$=geteditboxtext(shapeeditbox)
  663. shape=val(t$)
  664. change_edit_boxes()
  665. //setobjectrotation(curs,rx,ry,rz)
  666. endcase
  667. case imageeditbox
  668. t$=geteditboxtext(imageeditbox)
  669. ctexture=val(t$)
  670. for n=1 to maxobjects
  671. if object[n].selected=1
  672. object[n].selected=0
  673. setobjectcolor(object[n].id,object[n].r,object[n].g,object[n].b,255)
  674. object[n].im=ctexture
  675. setobjectimage(object[n].id,object[n].im,0)
  676. endif
  677. next n
  678. setspriteimage(1,ctexture)
  679. endcase
  680. case sxeditbox
  681. t$=geteditboxtext(sxeditbox)
  682. sx#=valfloat(t$)
  683. change_cursor(0)
  684. endcase
  685. case syeditbox
  686. t$=geteditboxtext(syeditbox)
  687. sy#=valfloat(t$)
  688. change_cursor(0)
  689. endcase
  690. case szeditbox
  691. t$=geteditboxtext(szeditbox)
  692. select shape
  693. case 1
  694. radius#=valfloat(t$)
  695. endcase
  696. case 2
  697. sz#=valfloat(t$)
  698. endcase
  699. case 3
  700. radius#=valfloat(t$)
  701. endcase
  702. case 4
  703. radius#=valfloat(t$)
  704. endcase
  705. endselect
  706. change_cursor(0)
  707. endcase
  708. case scxeditbox
  709. t$=geteditboxtext(scxeditbox)
  710. scalex#=valfloat(t$)
  711. change_cursor(0)
  712. endcase
  713. case scyeditbox
  714. t$=geteditboxtext(scyeditbox)
  715. scaley#=valfloat(t$)
  716. change_cursor(0)
  717. endcase
  718. case sczeditbox
  719. t$=geteditboxtext(sczeditbox)
  720. scalez#=valfloat(t$)
  721. change_cursor(0)
  722. endcase
  723. case smootheditbox
  724. t$=geteditboxtext(smootheditbox)
  725. smooth#=valfloat(t$)
  726. endcase
  727. case delayeditbox
  728. t$=geteditboxtext(delayeditbox)
  729. delay=val(t$)
  730. endcase
  731.  
  732. case transparencyeditbox
  733. t$=geteditboxtext(transparencyeditbox)
  734. tran=val(t$)
  735. endcase
  736. case trepeateditbox
  737. t$=geteditboxtext(trepeateditbox)
  738. trepeat=val(t$)
  739. endcase
  740.  
  741. //******************************************
  742. //************** Allow this stuff regardless of editmode ***********
  743. case lightmodeeditbox
  744. t$=geteditboxtext(lightmodeeditbox)
  745. lightmode=val(t$)
  746. endcase
  747. case lightoneditbox
  748. t$=geteditboxtext(lightoneditbox)
  749. lighton=val(t$)
  750. endcase
  751. case blueeditbox
  752. t$=geteditboxtext(blueeditbox)
  753. b=val(t$)
  754. setspritecolor(1,r,g,b,255)
  755. endcase
  756. case greeneditbox
  757. t$=geteditboxtext(greeneditbox)
  758. g=val(t$)
  759. setspritecolor(1,r,g,b,255)
  760. endcase
  761. case rededitbox
  762. t$=geteditboxtext(rededitbox)
  763. r=val(t$)
  764. setspritecolor(1,r,g,b,255)
  765. endcase
  766. endselect
  767. sync()
  768. until GetRawKeyReleased(KEY_ENTER)
  769. endif
  770. endfunction
  771. function set_object_value(ID)
  772. object[objectcounter].x#=cx#
  773. object[objectcounter].y#=cy#
  774. object[objectcounter].z#=cz#
  775. object[objectcounter].sx#=sx#
  776. object[objectcounter].sy#=sy#
  777. object[objectcounter].sz#=sz#
  778. object[objectcounter].scx#=scalex#
  779. object[objectcounter].scy#=scaley#
  780. object[objectcounter].scz#=scalez#
  781. object[objectcounter].ID=ID
  782. object[objectcounter].im=ctexture
  783. object[objectcounter].rotx=rx
  784. object[objectcounter].roty=ry
  785. object[objectcounter].rotz=rz
  786. object[objectcounter].r=r
  787. object[objectcounter].g=g
  788. object[objectcounter].b=b
  789. object[objectcounter].group=group
  790. object[objectcounter].shape=shape
  791. object[objectcounter].radius#=radius#
  792. object[objectcounter].friction#=friction#
  793. object[objectcounter].tran=tran
  794. object[objectcounter].vis=vis
  795. object[objectcounter].pb=pb
  796. object[objectcounter].ps=ps
  797. object[objectcounter].trepeat=trepeat
  798.  
  799. endfunction
  800. function set_object_value2(posi,ID)
  801. object[posi].x#=cx#
  802. object[posi].y#=cy#
  803. object[posi].z#=cz#
  804. object[posi].sx#=sx#
  805. object[posi].sy#=sy#
  806. object[posi].sz#=sz#
  807. object[posi].scx#=scalex#
  808. object[posi].scy#=scaley#
  809. object[posi].scz#=scalez#
  810. object[posi].ID=ID
  811. object[posi].im=ctexture
  812. object[posi].rotx=rx
  813. object[posi].roty=ry
  814. object[posi].rotz=rz
  815. object[posi].r=r
  816. object[posi].g=g
  817. object[posi].b=b
  818. object[posi].group=group
  819. object[posi].shape=shape
  820. object[posi].radius#=radius#
  821. object[posi].friction#=friction#
  822. object[posi].tran=tran
  823. object[posi].vis=vis
  824. object[posi].pb=pb
  825. object[posi].ps=ps
  826. object[posi].trepeat=trepeat
  827. endfunction
  828. function clear_level()
  829. for n=1 to maxobjects
  830. if object[n].ID>0
  831. deleteobject(object[n].ID)
  832. object[n].x#=0
  833. object[n].y#=0
  834. object[n].z#=0
  835. object[n].sx#=0
  836. object[n].sy#=0
  837. object[n].sz#=0
  838. object[n].scx#=0
  839. object[n].scy#=0
  840. object[n].scz#=0
  841. object[n].ID=0
  842. object[n].im=0
  843. object[n].rotx=0
  844. object[n].roty=0
  845. object[n].rotz=0
  846. object[n].r=0
  847. object[n].g=0
  848. object[n].b=0
  849. object[n].group=0
  850. object[n].shape=0
  851. object[n].radius#=0
  852. object[n].friction#=0
  853. object[n].tran=0
  854. object[n].vis=0
  855. object[n].selected=0
  856. object[n].deleted=0
  857. object[n].master=0
  858. object[n].slave=0
  859. object[n].trepeat=0
  860. if light[n].lightobjectID<>0
  861. deleteobject(light[n].lightobjectID)
  862. DeletePointLight(light[n].lightID)
  863. light[n].lightID=0
  864. light[n].r=0
  865. light[n].g=0
  866. light[n].b=0
  867. light[n].x#=0
  868. light[n].y#=0
  869. light[n].z#=0
  870. light[n].radius#=0
  871. light[n].delay=0
  872. light[n].olddelay=0
  873. light[n].lightmode=0
  874. light[n].lighton=0
  875. endif
  876. endif
  877. next n
  878. objectcounter=1
  879. lightcounter=2
  880. endfunction
  881. function caster(oldx#,oldy#,oldz#,newx#,newy#,newz#)
  882. //pobj = ObjectSpherecast(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,radius#)
  883. pobj=ObjectRayCast(0,oldx#,oldy#,oldz#,newx#,newy#,newz#)
  884.  
  885. if pobj>0
  886. objc=GetObjectRayCastHitID(0)
  887. endif
  888.  
  889. endfunction objc
  890. function reset_object(posi)
  891. object[posi].x#=0
  892. object[posi].y#=0
  893. object[posi].z#=0
  894. object[posi].sx#=0
  895. object[posi].sy#=0
  896. object[posi].sz#=0
  897. object[posi].scx#=0
  898. object[posi].scy#=0
  899. object[posi].scz#=0
  900. object[posi].ID=0
  901. object[posi].im=0
  902. object[posi].rotx=0
  903. object[posi].roty=0
  904. object[posi].rotz=0
  905. object[posi].r=0
  906. object[posi].g=0
  907. object[posi].b=0
  908. object[posi].group=0
  909. object[posi].shape=0
  910. object[posi].radius#=0
  911. object[posi].friction#=0
  912. object[posi].tran=0
  913. object[posi].vis=0
  914. object[posi].master=0
  915. object[posi].slave=0
  916. object[posi].trepeat=0
  917. endfunction
  918. function init()
  919. setclearcolor(200,200,200)
  920. clearscreen()
  921. setsunactive(0)
  922. SetAmbientColor( 50,50,50 )
  923. createobjectbox(curs,sx#,sy#,sz#)
  924. setobjectscale(curs,scalex#,scaley#,scalez#)
  925. setobjectimage(curs,1,0)
  926. SetObjectTransparency(curs,1)
  927. setobjectposition(curs,cx#,cy#,cz#)
  928. createobjectplane(collider,sx#,sy#)
  929. setobjectvisible(collider,0)
  930. SetObjectCollisionMode(collider,0)
  931. SetObjectCollisionMode(curs,0)
  932. createobjectplane(myplane,2000,2000)
  933. setobjectposition(myplane,0,0-sy#,0)
  934. setobjectrotation(myplane,90,0,0)
  935. SetObjectCollisionMode(myplane,0)
  936. setobjectimage(myplane,2,0)
  937. SetObjectTransparency(myplane,1)
  938. createsprite(1,ctexture)
  939. setspritesize(1,128,128)
  940. setspriteposition(1,870,600)
  941. //
  942. create_my_editbox(groupeditbox,basex#+xgap#,basey#,2,255,0,0,0,40,20,255,str(group))
  943. create_my_editbox(rxeditbox,basex#+xgap#,basey#+ygap#,2,255,0,0,0,40,20,255,"0")
  944. create_my_editbox(ryeditbox,basex#+xgap#,basey#+ygap#*2,2,255,0,0,0,40,20,255,"0")
  945. create_my_editbox(rzeditbox,basex#+xgap#,basey#+ygap#*3,2,255,0,0,0,40,20,255,"0")
  946. create_my_text(groupeditbox,basex#,basey#,25,255,0,0,"Group",0)
  947. create_my_text(rxeditbox,basex#,basey#+ygap#,25,255,0,0,"Rotate X",0)
  948. create_my_text(ryeditbox,basex#,basey#+ygap#*2,25,255,0,0,"Rotate Y",0)
  949. create_my_text(rzeditbox,basex#,basey#+ygap#*3,25,255,0,0,"Rotate Z",0)
  950. create_my_text(500,-91,basey#+ygap#*18,25,255,0,0,"",0)
  951. //
  952. create_my_editbox(pbeditbox,basex#+xgap#*2.5,basey#,2,255,0,0,0,40,20,255,"1")
  953. create_my_editbox(pseditbox,basex#+xgap#*2.5,basey#+ygap#,2,255,0,0,0,40,20,255,"2")
  954. create_my_editbox(frictioneditbox,basex#+xgap#*2.5,basey#+ygap#*2,2,255,0,0,0,40,20,255,"0")
  955. create_my_editbox(shapeeditbox,basex#+xgap#*2.5,basey#+ygap#*3,2,255,0,0,0,40,20,255,"2")
  956. create_my_text(pbeditbox,basex#+xgap#*1.5,basey#,25,255,0,0,"PhyBody",0)
  957. create_my_text(pseditbox,basex#+xgap#*1.5,basey#+ygap#,25,255,0,0,"PhyShape",0)
  958. create_my_text(frictioneditbox,basex#+xgap#*1.5,basey#+ygap#*2,25,255,0,0,"Friction#",0)
  959. create_my_text(shapeeditbox,basex#+xgap#*1.5,basey#+ygap#*3,25,255,0,0,"Shape",0)
  960. //
  961. create_my_editbox(rededitbox,basex#+xgap#*4,basey#,2,255,0,0,0,40,20,255,"255")
  962. create_my_editbox(greeneditbox,basex#+xgap#*4,basey#+ygap#,2,255,0,0,0,40,20,255,"255")
  963. create_my_editbox(blueeditbox,basex#+xgap#*4,basey#+ygap#*2,2,255,0,0,0,40,20,255,"255")
  964. create_my_editbox(imageeditbox,basex#+xgap#*4,basey#+ygap#*3,2,255,0,0,0,40,20,255,str(ctexture))
  965. create_my_text(rededitbox,basex#+xgap#*3,basey#,25,255,0,0,"RED",0)
  966. create_my_text(greeneditbox,basex#+xgap#*3,basey#+ygap#,25,255,0,0,"GREEN",0)
  967. create_my_text(blueeditbox,basex#+xgap#*3,basey#+ygap#*2,25,255,0,0,"BLUE",0)
  968. create_my_text(imageeditbox,basex#+xgap#*3,basey#+ygap#*3,25,255,0,0,"Texture",0)
  969. //
  970. create_my_editbox(sxeditbox,basex#+xgap#*5.5,basey#,2,255,0,0,0,40,20,255,"80")
  971. create_my_editbox(syeditbox,basex#+xgap#*5.5,basey#+ygap#,2,255,0,0,0,40,20,255,"80")
  972. create_my_editbox(szeditbox,basex#+xgap#*5.5,basey#+ygap#*2,2,255,0,0,0,40,20,255,"80")
  973. create_my_editbox(smootheditbox,basex#+xgap#*5.5,basey#+ygap#*3,2,255,0,0,0,40,20,255,"2.5")
  974.  
  975. create_my_text(sxeditbox,basex#+xgap#*4.5,basey#,25,255,0,0,"SizeX#",0)
  976. create_my_text(syeditbox,basex#+xgap#*4.5,basey#+ygap#,25,255,0,0,"SizeY#",0)
  977. create_my_text(sZeditbox,basex#+xgap#*4.5,basey#+ygap#*2,25,255,0,0,"SizeZ#",0)
  978. create_my_text(smootheditbox,basex#+xgap#*4.5,basey#+ygap#*3,25,255,0,0,"Smooth#",0)
  979.  
  980. create_my_editbox(scxeditbox,basex#+xgap#*6.5,basey#,2,255,0,0,0,40,20,255,"1")
  981. create_my_editbox(scyeditbox,basex#+xgap#*6.5,basey#+ygap#,2,255,0,0,0,40,20,255,"1")
  982. create_my_editbox(sczeditbox,basex#+xgap#*6.5,basey#+ygap#*2,2,255,0,0,0,40,20,255,"1")
  983. create_my_editbox(trepeateditbox,basex#+xgap#*6.5,basey#+ygap#*3,2,255,0,0,0,40,20,255,str(trepeat))
  984.  
  985. create_my_text(scxeditbox,basex#+xgap#*5.9,basey#,25,255,0,0,"ScaleX#",0)
  986. create_my_text(scyeditbox,basex#+xgap#*5.9,basey#+ygap#,25,255,0,0,"ScaleY#",0)
  987. create_my_text(sczeditbox,basex#+xgap#*5.9,basey#+ygap#*2,25,255,0,0,"ScaleZ#",0)
  988. create_my_text(trepeateditbox,basex#+xgap#*5.9,basey#+ygap#*3,25,255,0,0,"Trepeat",0)
  989.  
  990. create_my_editbox(delayeditbox,basex#+xgap#,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(delay))
  991. create_my_editbox(lightmodeeditbox,basex#+xgap#*2.5,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(lightmode))
  992. create_my_editbox(lightoneditbox,basex#+xgap#*4,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(lighton))
  993. create_my_editbox(transparencyeditbox,basex#+xgap#*5.5,basey#+ygap#*4,2,255,0,0,0,40,20,255,str(tran))
  994. create_my_text(delayeditbox,basex#,basey#+ygap#*4,25,255,0,0,"Delay",0)
  995. create_my_text(lightmodeeditbox,basex#+xgap#*1.5,basey#+ygap#*4,25,255,0,0,"LightMode",0)
  996. create_my_text(lightoneditbox,basex#+xgap#*3,basey#+ygap#*4,25,255,0,0,"LightOn",0)
  997. create_my_text(transparencyeditbox,basex#+xgap#*4.5,basey#+ygap#*4,25,255,0,0,"Transp",0)
  998. endfunction
  999. function load_level(level)
  1000. select gametype
  1001. case 0
  1002. f$="Platformer"
  1003. endcase
  1004. case 1
  1005. f$="Shooter"
  1006. endcase
  1007. endselect
  1008. f$=f$+str(level)
  1009. f$=f$+".lev"
  1010. if getfileexists(f$)=1
  1011. clear_level()
  1012. myfile=opentoread(f$)
  1013. objectcounter=readinteger(myfile)
  1014. lightcounter=readinteger(myfile)
  1015. //cx#=readfloat(myfile)
  1016. //cy#=readfloat(myfile)
  1017. //cz#=readfloat(myfile)
  1018. for n=1 to maxobjects
  1019. object[n].name$=readstring(myfile)
  1020. object[n].x# =readfloat(myfile)
  1021. object[n].y# =readfloat(myfile)
  1022. object[n].z# =readfloat(myfile)
  1023. object[n].sx#=readfloat(myfile)
  1024. object[n].sy#=readfloat(myfile)
  1025. object[n].sz#=readfloat(myfile)
  1026. object[n].scx#=readfloat(myfile)
  1027. object[n].scy#=readfloat(myfile)
  1028. object[n].scz#=readfloat(myfile)
  1029. object[n].friction#=readfloat(myfile)
  1030. object[n].radius#=readfloat(myfile)
  1031. object[n].id=readinteger(myfile)
  1032. object[n].im=readinteger(myfile)
  1033. object[n].rotx=readinteger(myfile)
  1034. object[n].roty=readinteger(myfile)
  1035. object[n].rotz=readinteger(myfile)
  1036. object[n].shape=readinteger(myfile)
  1037. object[n].group=readinteger(myfile)
  1038. object[n].r=readinteger(myfile)
  1039. object[n].g=readinteger(myfile)
  1040. object[n].b=readinteger(myfile)
  1041. object[n].vis=readinteger(myfile)
  1042. object[n].tran=readinteger(myfile)
  1043. object[n].pb=readinteger(myfile)
  1044. object[n].ps=readinteger(myfile)
  1045. object[n].deleted=readinteger(myfile)
  1046. object[n].master=readinteger(myfile)
  1047. object[n].slave=readinteger(myfile)
  1048. object[n].trepeat=readinteger(myfile)
  1049. light[n].lightID=readinteger(myfile)
  1050. light[n].lightobjectID=readinteger(myfile)
  1051. light[n].r=readinteger(myfile)
  1052. light[n].g=readinteger(myfile)
  1053. light[n].b=readinteger(myfile)
  1054. light[n].x#=readfloat(myfile)
  1055. light[n].y#=readfloat(myfile)
  1056. light[n].z#=readfloat(myfile)
  1057. light[n].radius#=readfloat(myfile)
  1058. light[n].delay=readinteger(myfile)
  1059. light[n].olddelay=readinteger(myfile)
  1060. light[n].lightmode=readinteger(myfile)
  1061. light[n].lighton=readinteger(myfile)
  1062. if object[n].id>0
  1063. select object[n].shape
  1064. case 1
  1065. createobjectsphere(object[n].id,object[n].radius#,32,32)
  1066. endcase
  1067. case 2
  1068. createobjectbox(object[n].id,object[n].sx#,object[n].sy#,object[n].sz#)
  1069. endcase
  1070.  
  1071. case 3
  1072. CreateObjectCylinder(object[n].id,object[n].sy#,object[n].radius#,32)
  1073. endcase
  1074. case 4
  1075. obj=CreateObjectCapsule(object[n].radius#,object[n].sy#,90)
  1076. endcase
  1077. case 5
  1078. obj=createobjectcone(object[n].sy#,object[n].radius#,32)
  1079. endcase
  1080. case 6
  1081. obj=createobjectplane(object[n].sx#,object[n].sz#)
  1082. endcase
  1083. endselect
  1084. setobjectimage(object[n].id,object[n].im,0)
  1085. if object[n].trepeat=1
  1086. setobjectuvscale(object[n].id,0,1*object[n].scx#,1.0/object[n].scz#)
  1087. elseif trepeat=0
  1088. setobjectuvscale(object[n].id,0,1.0,1.0)
  1089. endif
  1090. setobjectposition(object[n].id,object[n].x#,object[n].y#,object[n].z#)
  1091. setobjectscale(object[n].id,object[n].scx#,object[n].scy#,object[n].scz#)
  1092. setobjectrotation(object[n].id,object[n].rotx,object[n].roty,object[n].rotz)
  1093. setobjectcolor(object[n].id,object[n].r,object[n].g,object[n].b,255)
  1094. setobjectvisible(object[n].id,1)
  1095. setobjecttransparency(object[n].id,object[n].tran)
  1096. endif
  1097. // place/set the lights
  1098.  
  1099. next n
  1100. closefile(myfile)
  1101. for n=1 to maxobjects
  1102. if light[n].lightobjectID>0
  1103. loadobject(light[n].lightobjectID,"lightbulb.obj")
  1104. setobjectposition(light[n].lightobjectId,light[n].x#,light[n].y#,light[n].z#)
  1105. setobjectcolor(light[n].lightobjectID,light[n].r,light[n].g,light[n].b,255)
  1106. 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)
  1107. //setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
  1108. endif
  1109. next n
  1110. sys_message(2,500)
  1111. endif
  1112. endfunction
  1113. function save_level(level)
  1114. select gametype
  1115. case 0
  1116. f$="Platformer"
  1117. endcase
  1118. case 1
  1119. f$="Shooter"
  1120. endcase
  1121. endselect
  1122. f$=f$+str(level)
  1123. f$=f$+".lev"
  1124. myfile=opentowrite(f$)
  1125. writeinteger(myfile,objectcounter)
  1126. writeinteger(myfile,lightcounter)
  1127. //writefloat(myfile,cx#)
  1128. //writefloat(myfile,cy#)
  1129. //writefloat(myfile,cz#)
  1130. for n=1 to maxobjects
  1131. writestring(myfile,object[n].name$)
  1132. writefloat(myfile,object[n].x#)
  1133. writefloat(myfile,object[n].y#)
  1134. writefloat(myfile,object[n].z#)
  1135. writefloat(myfile,object[n].sx#)
  1136. writefloat(myfile,object[n].sy#)
  1137. writefloat(myfile,object[n].sz#)
  1138. writefloat(myfile,object[n].scx#)
  1139. writefloat(myfile,object[n].scy#)
  1140. writefloat(myfile,object[n].scz#)
  1141. writefloat(myfile,object[n].friction#)
  1142. writefloat(myfile,object[n].radius#)
  1143. writeinteger(myfile,object[n].id)
  1144. writeinteger(myfile,object[n].im)
  1145. writeinteger(myfile,object[n].rotx)
  1146. writeinteger(myfile,object[n].roty)
  1147. writeinteger(myfile,object[n].rotz)
  1148. writeinteger(myfile,object[n].shape)
  1149. writeinteger(myfile,object[n].group)
  1150. writeinteger(myfile,object[n].r)
  1151. writeinteger(myfile,object[n].g)
  1152. writeinteger(myfile,object[n].b)
  1153. writeinteger(myfile,object[n].vis)
  1154. writeinteger(myfile,object[n].tran)
  1155. writeinteger(myfile,object[n].pb)
  1156. writeinteger(myfile,object[n].ps)
  1157. writeinteger(myfile,object[n].deleted)
  1158. writeinteger(myfile,object[n].master)
  1159. writeinteger(myfile,object[n].slave)
  1160. writeinteger(myfile,object[n].trepeat)
  1161. // write the lights
  1162. writeinteger(myfile,light[n].lightID)
  1163. writeinteger(myfile,light[n].lightobjectID)
  1164. writeinteger(myfile,light[n].r)
  1165. writeinteger(myfile,light[n].g)
  1166. writeinteger(myfile,light[n].b)
  1167. writefloat(myfile,light[n].x#)
  1168. writefloat(myfile,light[n].y#)
  1169. writefloat(myfile,light[n].z#)
  1170. writefloat(myfile,light[n].radius#)
  1171. writeinteger(myfile,light[n].delay)
  1172. writeinteger(myfile,light[n].olddelay)
  1173. writeinteger(myfile,light[n].lightmode)
  1174. writeinteger(myfile,light[n].lighton)
  1175. next n
  1176. closefile(myfile)
  1177. sys_message(1,2000)
  1178. endfunction
  1179. function sys_message(m,del)
  1180. select m
  1181. case 1
  1182. print("Level Saved!!")
  1183. endcase
  1184. case 2
  1185. print("Level Loaded!!")
  1186. endcase
  1187. endselect
  1188. sync()
  1189. sleep(del)
  1190. endfunction
  1191. function createobjectphysics(myobj,myphybody,myphyshape)
  1192. select myphybody
  1193. case 1
  1194. Create3DPhysicsStaticBody(myobj)
  1195. endcase
  1196. case 2
  1197. Create3DPhysicsDynamicBody(myobj)
  1198. endcase
  1199. endselect
  1200. select myphyshape
  1201. case 1
  1202. SetObjectShapesphere(myobj)
  1203. endcase
  1204. case 2
  1205. SetObjectShapebox(myobj)
  1206. endcase
  1207. case 3
  1208. SetObjectShapeCylinder(myobj,90)
  1209. endcase
  1210. endselect
  1211. endfunction
  1212. function test_level()
  1213. //setsunactive(0)
  1214. //SetAmbientColor(0,0,0)
  1215. //setcamerarotation(1,0,180,0)
  1216. //setobjectrotation(player,0,180,0)
  1217. SetAmbientColor( 0,0,0 )
  1218. setcameraposition(1,getobjectx(player),getobjecty(player),getobjectz(player))
  1219. SetCameraRange(1,1,1500)
  1220. addvirtualjoystick(1,100,600,90)
  1221. setobjectposition(curs,-1000000,-1000000,-1000000)
  1222. addvirtualbutton( 1, 94.7,93.1,9.77 )
  1223. addvirtualbutton( 2, 94.7,79.4,9.77 )
  1224. setobjectvisible(myplane,0)
  1225. for n=1 to maxobjects
  1226. if object[n].group=7
  1227. f$="mov1.avi"
  1228. loadvideo(f$)
  1229. playvideotoimage(5000)
  1230. playvideo()
  1231. setobject3dphysicsmass(object[n].id,3)
  1232. exit
  1233. endif
  1234. if object[n].id>0
  1235. createobjectphysics(object[n].id,object[n].pb,object[n].ps)
  1236. //setobject3dphysicsdamping(object[n].id,0.1,0.1)
  1237. //setobject3dphysicsfriction(object[n].id,0.01)
  1238. //setobject3dphysicsrollingfriction(object[n].id,0.01)
  1239. //SetObject3DPhysicsMass(object[n].id,0.5)
  1240. endif
  1241. if object[n].group=1
  1242. player=object[n].id
  1243. px#=object[n].x#
  1244. py#=object[n].y#
  1245. pz#=object[n].z#
  1246. select gametype
  1247. //rem we want an fps controller!
  1248. case 0
  1249. Delete3DPhysicsBody(player)
  1250. Create_character_controller(player)
  1251. endcase
  1252. endselect
  1253. endif
  1254. // if group value is set to 7 then set the texture to that used to render a video onto
  1255. if object[n].group=7
  1256. setobjectimage(object[n].id,5000,0)
  1257. endif
  1258. // hide the light objects used in the editor
  1259. if light[n].lightobjectID>0
  1260. setobjectvisible(light[n].lightobjectID,0)
  1261. endif
  1262. next n
  1263. if gametype=0
  1264. gun = createobjectbox(0.25,0.25,10)
  1265. SetObjectPosition( gun, -15, 0, -50.0 )
  1266. setobjectrotation(gun,0,180,0)
  1267. endif
  1268. repeat
  1269. Step3DPhysicsWorld()
  1270. check_lights()
  1271. rem Old position
  1272. //************ Select based on gametype.. 0 is default and is for fps
  1273. select gametype
  1274. //*******************************************************************
  1275. case 0
  1276. fps_control()
  1277. if ( GetPointerPressed() )
  1278. startx# = GetPointerX()
  1279. starty# = GetPointerY()
  1280. angx# = GetCameraAngleX(1)
  1281. angy# = GetCameraAngleY(1)
  1282. pressed = 1
  1283. endif
  1284. if ( GetPointerState() = 1 )
  1285. fDiffX# = (GetPointerX() - startx#)
  1286. fDiffY# = (GetPointerY() - starty#)
  1287. newX# = angx# + fDiffY#
  1288. if ( newX# > 89 ) then newX# = 89
  1289. if ( newX# < -89 ) then newX# = -89
  1290. SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
  1291. Rotate3DPhysicsCharacterController(player,angy# + fDiffX#)
  1292. endif
  1293. rem Gravity on camera
  1294. SetCameraPosition(1,getobjectx(player),getobjecty(player),getobjectz(player))
  1295. SetObjectRotation(gun,GetCameraAngleX(1),GetCameraAngleY(1),GetCameraAngleZ(1))
  1296. // setobjectposition(gun,getobjectx(player),getobjecty(player),getobjectz(player))
  1297. SetObjectPosition(gun,getcamerax(1),getcameray(1),getcameraz(1))
  1298. SetObjectRotation(gun,GetCameraAngleX(1),GetCameraAngleY(1),GetCameraAngleZ(1))
  1299. MoveObjectLocalZ(gun,6.1)
  1300. MoveObjectLocalx(gun,0.5)
  1301. moveobjectlocaly(gun,-0.4)
  1302. endcase
  1303. //*************************************************************************************
  1304. endselect
  1305. if objc<>0
  1306. //Print("hit object "+str(objc))
  1307. endif
  1308. // posx# = sin(timer()*40) * 250 + 2000
  1309. // SetPointLightPosition( 1, posx#, 565, -3600 )
  1310. //SetObjectPosition( 99, posx#, 565, -3600 )
  1311. rem Framerate prompt
  1312. // print("W A S D or joystick to move, click and drag to rotate")
  1313. fps=ScreenFPS() : Print("FPS: " + str(fps))
  1314. rem Update screen
  1315. if getrawkeypressed(KEY_E)
  1316. quit=1
  1317. endif
  1318. Sync()
  1319. until quit=1
  1320. if getobjectexists(gun)
  1321. deleteobject(gun)
  1322. endif
  1323. quit=0
  1324. Level_cleanup()
  1325. endfunction
  1326. Function Create_character_controller(player)
  1327. characterOffsetVec = CreateVector3( 0.0, 0.0, 0.0 )
  1328. characterOffsetVec2 = CreateVector3( 0.0, 0.0, -12 )
  1329. //This vector indicates the axis your model faces forward.
  1330. //For example if your model faces down the - Z axis use this vector.
  1331. objectOrientationVec = CreateVector3( 0.0, 0.0, -1.0 )
  1332. //The crouchScale parameter is 0.0 to 1.0, for examle 0.75 is 75% of the models standing height.
  1333. `Create3DPhysicsCharacterController(obj, 1, characterOffsetVec, objectOrientationVec, 0.75 )
  1334.  
  1335. Create3DPhysicsCharacterController(player, 1, characterOffsetVec, objectOrientationVec, 0.75 )
  1336. Set3DPhysicsCharacterControllerJumpSpeed(player,9)
  1337. //set3DPhysicsCharacterControllerGravity( player,25 )
  1338. DeleteVector3( characterOffsetVec )
  1339. DeleteVector3( characterOffsetVec2 )
  1340. DeleteVector3( objectOrientationVec )
  1341. endfunction
  1342. function hide_stuff()
  1343. for n=1 to 100
  1344. if gettextexists(n)
  1345. settextvisible(n,0)
  1346. endif
  1347. if geteditboxexists(n)
  1348. seteditboxvisible(n,0)
  1349. endif
  1350. if getspriteexists(n)
  1351. setspritevisible(n,0)
  1352. endif
  1353.  
  1354. next n
  1355. setobjectposition(curs,-100000,-100000,-1000000)
  1356. endfunction
  1357. function show_stuff()
  1358. for n=1 to 100
  1359. if gettextexists(n)
  1360. settextvisible(n,1)
  1361. endif
  1362. if geteditboxexists(n)
  1363. seteditboxvisible(n,1)
  1364. endif
  1365. if getspriteexists(n)
  1366. setspritevisible(n,1)
  1367. endif
  1368.  
  1369. next n
  1370. setobjectvisible(curs,1)
  1371. setobjectposition(curs,cx#,cy#,cz#)
  1372. endfunction
  1373. function Level_cleanup()
  1374. SetAmbientColor( 50,50,50 )
  1375. deletevirtualjoystick(1)
  1376. for n=1 to maxobjects
  1377. if object[n].id>0
  1378. setobjectposition(object[n].id,object[n].x#,object[n].y#,object[n].z#)
  1379. SetObjectRotation(object[n].id,object[n].rotx,object[n].roty,object[n].rotz)
  1380. delete3dphysicsbody(object[n].id)
  1381. endif
  1382. if light[n].lightobjectID>0
  1383. setobjectvisible(light[n].lightobjectID,1)
  1384. endif
  1385. next n
  1386. setobjectvisible(myplane,1)
  1387. setobjectvisible(player,1)
  1388. if Get3DPhysicsCharacterControllerExists(player)
  1389. Delete3DPhysicsCharacterController(player)
  1390. endif
  1391. SetCameraRange(1,100,3000)
  1392. endfunction
  1393. function change_edit_boxes()
  1394. select shape
  1395. case 1
  1396. seteditboxtext(sxeditbox,"32")
  1397. settextstring(sxeditbox,"X Segs")
  1398. seteditboxtext(syeditbox,"32")
  1399. settextstring(syeditbox,"Y Segs")
  1400. seteditboxtext(szeditbox,"80")
  1401. settextstring(szeditbox,"Radius#")
  1402. endcase
  1403. case 2
  1404. seteditboxtext(sxeditbox,"80")
  1405. settextstring(sxeditbox,"SizeX#")
  1406. seteditboxtext(syeditbox,"80")
  1407. settextstring(syeditbox,"SizeY#")
  1408. seteditboxtext(szeditbox,"80")
  1409. settextstring(szeditbox,"SizeZ#")
  1410. endcase
  1411. case 3
  1412. seteditboxtext(sxeditbox,"32")
  1413. settextstring(sxeditbox,"X Segs")
  1414. seteditboxtext(syeditbox,"32")
  1415. settextstring(syeditbox,"Y Segs")
  1416. seteditboxtext(szeditbox,"80")
  1417. settextstring(szeditbox,"Radius#")
  1418. endcase
  1419. endselect
  1420. endfunction
  1421. function check_lights()
  1422. for n=0 to lightcounter-1
  1423. if light[n].lightmode>0 and light[n].lighton=1
  1424. select light[n].lightmode
  1425. // blinking light
  1426. case 1
  1427. dec light[n].delay
  1428. if light[n].delay<=0
  1429. if light[n].lswitch=0
  1430. light[n].lswitch=1
  1431. light[n].delay=light[n].olddelay
  1432. SetPointLightcolor(light[n].lightID,0,0,0)
  1433. elseif light[n].lswitch=1
  1434. light[n].lswitch=0
  1435. light[n].delay=light[n].olddelay
  1436. setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
  1437. endif
  1438. endif
  1439. endcase
  1440. // Flickering Light
  1441. case 2
  1442. dec light[n].delay
  1443. if light[n].delay<=0
  1444. if light[n].lswitch=0
  1445. light[n].lswitch=1
  1446. light[n].delay=random2(2,20)
  1447. SetPointLightcolor(light[n].lightID,0,0,0)
  1448. elseif light[n].lswitch=1
  1449. light[n].lswitch=0
  1450. light[n].delay=random2(2,10)
  1451. setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
  1452. endif
  1453. endif
  1454. endcase
  1455. // Pulsating Light
  1456. case 3
  1457. if light[n].delay>0
  1458. dec light[n].delay
  1459. endif
  1460. if light[n].delay=0
  1461. light[n].delay=light[n].olddelay
  1462. if light[n].lswitch=0
  1463. if light[n].r>0
  1464. light[n].r=light[n].r-10
  1465. endif
  1466. if light[n].g>0
  1467. light[n].g=light[n].g-10
  1468. endif
  1469. if light[n].b>0
  1470. light[n].b=light[n].b-10
  1471. endif
  1472. if light[n].r<=0 and light[n].g<=0 and light[n].b<=0
  1473. light[n].lswitch=1
  1474. endif
  1475. SetPointLightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
  1476. elseif light[n].lswitch=1
  1477. if light[n].r<>light[n].oldr
  1478. light[n].r=light[n].r+10
  1479. endif
  1480. if light[n].g<>light[n].oldg
  1481. light[n].g=light[n].g+10
  1482. endif
  1483. if light[n].b<>light[n].oldb
  1484. light[n].b=light[n].b+10
  1485. endif
  1486. if light[n].r=light[n].oldr and light[n].g=light[n].oldg and light[n].b=light[n].oldb
  1487. light[n].lswitch=0
  1488. endif
  1489. setpointlightcolor(light[n].lightID,light[n].r,light[n].g,light[n].b)
  1490. endif
  1491. endif
  1492. endcase
  1493. endselect
  1494. endif
  1495. next n
  1496. endfunction
  1497. function load_model(currenttexture)
  1498. model$=ChooseRawFile("*.obj")
  1499. if model$>""
  1500. name$=model$
  1501. `myobject[objectnumber].name$=myname$
  1502. pobj=loadobject(model$)
  1503. setobjectposition(pobj,cx#,cy#,cz#)
  1504. setobjectscale(pobj,sx#,sy#,sz#)
  1505. setobjectimage(pobj,currenttexture,0)
  1506. setobjectcolor(pobj,r,g,b,255)
  1507. set_object_value(pobj)
  1508. //inc objpointer
  1509. endif
  1510. endfunction
  1511. function ThrowBall( initialSpeed as float, mass as float, gunPositionVec as integer )
  1512. projectileDirBox as integer
  1513. projectileDirBox = CreateObjectBox( 1.0, 1.0, 1.0 )
  1514. SetObjectPosition( projectileDirBox, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
  1515. //setobjectrotation(projectiledirbox,getobjectanglex(gun),getobjectangley(gun),getobjectanglez(gun))
  1516. MoveObjectLocalZ( projectileDirBox, -1.0 )
  1517. projectileDirVec = CreateVector3( GetobjectX( projectileDirBox )-getobjectx(gun), GetobjectY( projectileDirBox )-getobjecty(gun), GetobjectZ( projectileDirBox )-getobjectz(gun) )
  1518. DeleteObject( projectileDirBox )
  1519. throwBall as integer
  1520. throwBall = CreateObjectSphere( 10, 16, 32 )
  1521. SetObjectImage( throwBall, 12, 0 )
  1522. SetObjectPosition( throwBall, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
  1523. //setobjectrotation(throwball,getobjectanglex(gun),getobjectangley(gun),getobjectanglez(gun))
  1524. //3D Physics code
  1525. Create3DPhysicsDynamicBody( throwBall )
  1526. SetObjectShapeSphere( throwBall )
  1527. SetObject3DPhysicsMass( throwBall, mass )
  1528. SetObject3DPhysicsLinearVelocity( throwBall, projectileDirVec, initialSpeed )
  1529. SetObject3DPhysicsFriction( throwBall, 0.8 )
  1530. SetObject3DPhysicsRollingFriction( throwBall, 0.7 )
  1531. deletevector3(projectileDirVec)
  1532. deletevector3(gunPositionVec)
  1533. endfunction
  1534. function fps_control()
  1535. oldx#=GetCameraX(1)
  1536. oldy#=GetCameraY(1)-45.0
  1537. oldz#=GetCameraZ(1)
  1538. Move3DPhysicsCharacterController( player, 0, walkVel#)
  1539. if ( GetRawKeyState( 87 ) )
  1540. MoveCameraLocalZ( 1, 4 )
  1541. Move3DPhysicsCharacterController(player,1,walkvel#)
  1542. //print("Up")
  1543. endif
  1544. if ( GetRawKeyState( 83 ) )
  1545. MoveCameraLocalZ( 1, -4 )
  1546. Move3DPhysicsCharacterController(player,2,walkvel#)
  1547. // print("Down")
  1548. endif
  1549.  
  1550. if ( GetRawKeyState( 65 ) )
  1551. MoveCameraLocalX( 1, -4 )
  1552. Move3DPhysicsCharacterController(player,3,walkvel#)
  1553. // print("Left")
  1554. endif
  1555. if ( GetRawKeyState( 68 ) )
  1556. MoveCameraLocalX( 1, 4 )
  1557. Move3DPhysicsCharacterController(player,4,walkvel#)
  1558. // print("Right")
  1559. endif
  1560. if ( getvirtualbuttonstate(1) = 1 ) then MoveCameraLocalZ( 1, -4 )
  1561. if ( getvirtualbuttonstate(2) = 1 ) then MoveCameraLocalZ( 1, 4 )
  1562.  
  1563. if ( getrawjoystickexists(1) )
  1564. MoveCameraLocalZ(1,-getrawjoysticky(1)*4)
  1565. MoveCameraLocalX(1,getrawjoystickx(1)*4)
  1566. RotateCameraGlobalY(1,getrawjoystickrx(1)*4)
  1567. RotateCameraLocalX(1,getrawjoystickry(1)*4)
  1568. //RotateobjectGlobalY(player,GetCameraAngleX(1))
  1569. //Rotate3DPhysicsCharacterController(player,getcameraangleY(1))
  1570. endif
  1571. if GetrawkeyPressed(KEY_V)
  1572. //To move dynamic physics bodies we need to apply velocity to the physics body.
  1573. gunPositionVec= CreateVector3(getobjectx(gun),getobjecty(gun), getobjectz(gun) )
  1574. ThrowBall( 190.0, 1.0,gunPositionVec)
  1575. endif
  1576.  
  1577. rem New position
  1578. newx#=GetCameraX(1)
  1579. newy#=GetCameraY(1)-45
  1580. newz#=GetCameraZ(1)`
  1581. rem Adjust Y to match floor
  1582. pobj= ObjectSphereSlide(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,19.0)
  1583. if pobj>0
  1584. newx#=GetObjectRayCastSlideX(0)
  1585. newy#=GetObjectRayCastSlideY(0)
  1586. newz#=GetObjectRayCastSlideZ(0)
  1587. //SetCameraPosition(1,newx#,newy#+45.0,newz#)
  1588. //setobjectposition(player,newx#,newy#,newz#)
  1589. objc=GetObjectRayCastHitID(0)
  1590. endif
  1591. if getrawkeypressed(KEY_SPACE)
  1592. Jump3DPhysicsCharacterController(player)
  1593. endif
  1594.  
  1595. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement