functions.bb 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. ;
  2. ;
  3. ; Game Functions
  4. ;
  5. ; EFX functions smoke first
  6. ;
  7. Function Update_Smoke()
  8. For a.smoke=Each smoke
  9. TranslateEntity a\ent,0,0,-EFX_SPEED
  10. ScaleSprite a\ent,a\size,a\size
  11. EntityAlpha a\ent,a\alpha
  12. a\size=a\size+a\disp
  13. a\alpha=a\alpha-a\reduct
  14. a\rot=a\rot+1
  15. RotateSprite a\ent,a\rot
  16. If a\alpha<.1 Or EntityZ(a\ent)<CameraZpos Then
  17. FreeEntity a\ent
  18. Delete a
  19. smk=smk-1
  20. End If
  21. Next
  22. End Function
  23. Function Add_Smoke_puff(size#,dis#,rduct#,x#,y#,z#,r,g,b)
  24. smk=smk+1
  25. a.smoke=New smoke
  26. a\size=size
  27. a\disp=dis
  28. a\alpha=.6
  29. a\reduct=rduct
  30. a\ent=CopyEntity(smoke_spr(Rand(1,4)))
  31. EntityColor a\ent,r,g,b
  32. ScaleSprite a\ent,size,size
  33. PositionEntity a\ent,x,y,z
  34. Return a\ent
  35. End Function
  36. Function Add_White_Smoke(size#,x#,y#,z#)
  37. ent=Add_Smoke_puff(size,.2,.04,x,y,z,255,255,255)
  38. Return ent
  39. End Function
  40. Function Add_Color_Smoke(size,x#,y#,z#,r,g,b)
  41. ent=Add_Smoke_puff(size,.2,.04,x,y,z,r,g,b)
  42. Return ent
  43. End Function
  44. ;
  45. ;Delete all smoke
  46. Function Free_Smoke()
  47. For a.smoke=Each smoke
  48. If a\ent FreeEntity a\ent
  49. Next
  50. Delete Each smoke
  51. End Function
  52. ;
  53. ;Asteroid functions
  54. Function Add_Object(x#,y#,z#,dir,speed#,size#,typ)
  55. a.Obj=New Obj
  56. a\speed=speed
  57. a\dir=dir
  58. a\typ=typ
  59. a\st=False
  60. a\piv=CreatePivot()
  61. Select a\typ
  62. Case 1 ;Normal asteroid
  63. a\ent=CopyEntity(Aster_mesh,a\piv)
  64. ScaleEntity a\ent,size,size,size
  65. RotateEntity a\ent,Rnd(360),Rnd(360),Rnd(360)
  66. PositionEntity a\piv,x,y,z
  67. EntityType a\piv,TYPE_ASTER
  68. EntityPickMode a\ent,2
  69. EntityRadius a\piv,size
  70. a\val=100
  71. Case 2 ;Double Points
  72. a\ent=CopyEntity(Aster_mesh,a\piv)
  73. ScaleEntity a\ent,size,size,size
  74. RotateEntity a\ent,Rnd(360),Rnd(360),Rnd(360)
  75. PositionEntity a\piv,x,y,z
  76. EntityType a\piv,TYPE_ASTER
  77. EntityPickMode a\ent,2
  78. EntityRadius a\piv,size
  79. a\val=200
  80. EntityColor a\ent,255,255,0
  81. Case 3
  82. a\ent=CopyEntity(Aster_mesh,a\piv)
  83. ScaleEntity a\ent,size,size,size
  84. RotateEntity a\ent,Rnd(360),Rnd(360),Rnd(360)
  85. PositionEntity a\piv,x,y,z
  86. EntityType a\piv,TYPE_ASTER
  87. EntityPickMode a\ent,2
  88. EntityRadius a\piv,size
  89. a\val=500
  90. EntityColor a\ent,255,0,0
  91. a\col=240
  92. a\cd=10
  93. Case 10
  94. a\ent=CopyEntity(Bad01_mesh,a\piv)
  95. ScaleEntity a\ent,size,size,size
  96. PositionEntity a\piv,x,y,z
  97. a\dx=0
  98. a\dy=0
  99. EntityType a\piv,TYPE_ASTER
  100. EntityPickMode a\ent,2
  101. EntityRadius a\piv,size
  102. a\val=1500
  103. EntityColor a\ent,255,0,0
  104. a\ds=100
  105. a\fx=x
  106. a\fy=y
  107. Case 1000 ;Claw
  108. a\ent=CopyEntity(Claw_Anim_Mesh,a\piv)
  109. ScaleEntity a\ent,size,size,size
  110. PositionEntity a\piv,800*Cos(x),800*Sin(x),z
  111. RotateEntity a\piv,0,0,x-180
  112. a\dx=0
  113. a\dy=0
  114. EntityType GetChild(a\ent,1),TYPE_CLAW
  115. a\ds=100
  116. a\fx=x
  117. a\fy=y
  118. Animate a\ent,3,Rnd(.3,3)
  119. End Select
  120. End Function
  121. ;Update Asteroids
  122. Function Update_Objects()
  123. For a.Obj=Each Obj
  124. Select a\typ
  125. Case 1
  126. Control_Asteroid(a,1)
  127. Case 2
  128. Control_Asteroid(a,2)
  129. Case 3
  130. Control_Asteroid(a,3)
  131. Case 1000
  132. If EntityZ(a\piv)>CameraZpos Then
  133. TranslateEntity a\piv,0,0,a\speed*a\dir
  134. Else
  135. FreeEntity a\ent
  136. FreeEntity a\piv
  137. Delete a
  138. End If
  139. End Select
  140. Next
  141. End Function
  142. Function Control_Asteroid(a.Obj,typ)
  143. Select a\typ
  144. Case 3
  145. EntityColor a\ent,a\col,255-a\col,0
  146. a\col=a\col-a\cd
  147. If a\col<140 Or a\col>250 Then a\cd=-a\cd
  148. End Select
  149. If EntityZ(a\piv)>CameraZpos Then
  150. TurnEntity a\piv,2,0,0.5
  151. TranslateEntity a\piv,-a\dx,-a\dy,a\speed*a\dir
  152. Else
  153. FreeEntity a\ent
  154. FreeEntity a\piv
  155. Delete a
  156. End If
  157. End Function
  158. ;Delete all objects
  159. Function Delete_Objects()
  160. For a.Obj=Each Obj
  161. If a\ent FreeEntity a\ent
  162. If a\piv FreeEntity a\piv
  163. Delete a
  164. Next
  165. End Function
  166. ;
  167. ; Shooting funcitons
  168. ;
  169. Function Add_Shot.shot(ent,typ,dir,firer.play)
  170. If firer<>Null Then
  171. If firer\rate>0 Then Return
  172. End If
  173. a.shot=New shot
  174. a\typ=typ
  175. a\firer=firer
  176. Select typ
  177. Case 1
  178. If firer<>Null Then
  179. a\firer\rate=6
  180. End If
  181. a\speed=8
  182. a\dx=0
  183. a\dy=0
  184. a\dz=dir
  185. a\life=125
  186. a\ent=CopyEntity(shot1_spr,ent)
  187. If firer<>Null Then
  188. PositionEntity a\ent,a\firer\ox,0,10
  189. a\firer\ox=-a\firer\ox
  190. End If
  191. EntityParent a\ent,0
  192. EntityRadius a\ent,8
  193. EntityType a\ent,TYPE_SHOT1
  194. EmitSound Shoot1_wave,a\ent
  195. End Select
  196. Return a
  197. End Function
  198. ;
  199. ;Update all players shots
  200. Function Update_Shots()
  201. For a.shot=Each shot
  202. a\life=a\life-1
  203. Select a\typ
  204. Case 1
  205. TranslateEntity a\ent,a\dx,a\dy,a\dz*a\speed
  206. a\ang=a\ang+5
  207. RotateSprite a\ent,a\ang
  208. End Select
  209. If a\life<100 Then
  210. EntityAlpha a\ent,a\life/10
  211. End If
  212. If a\life<1 Then
  213. FreeEntity a\ent
  214. Delete a
  215. Else
  216. If CountCollisions(a\ent)>0
  217. For b=1 To CountCollisions(a\ent)
  218. ent=CollisionEntity(a\ent,b)
  219. x#=EntityX(ent)
  220. y#=EntityY(ent)
  221. z#=EntityZ(ent)
  222. Set_Flash()
  223. For c=1 To 2
  224. add_color_smoke(275,x+Rnd(-2,2),y+Rnd(-2,2),z,255,10,0)
  225. add_color_smoke(170,x+Rnd(-2,2),y+Rnd(-2,2),z,255,200,0)
  226. ent2=add_white_smoke(140,x+Rnd(-2,2),y+Rnd(-2,2),z)
  227. Next
  228. PositionEntity ent,EntityX(ent),EntityY(ent),-1000
  229. EmitSound Explode_wave,ent2
  230. Next
  231. FreeEntity a\ent
  232. If a\firer<>Null Then
  233. a\firer\score=a\firer\score+150
  234. End If
  235. Delete a
  236. End If
  237. End If
  238. Next
  239. End Function
  240. ;Delete all shots
  241. Function Free_Shots()
  242. For a.shot=Each shot
  243. If a\ent FreeEntity a\ent
  244. Delete a
  245. Next
  246. End Function
  247. ;
  248. ; Player functions
  249. ; typ = 1 Mouse controled player
  250. ; 2 ana Joy Controlled player
  251. ; 3 dig Joy controlled player
  252. ; 4 keyboard controlled player
  253. ; 5 CPU Controlled player
  254. ; 6 internet player ** TO DO **
  255. ;
  256. Function Add_Player.play(typ,r,g,b,split,id,n$)
  257. a.play=New play
  258. a\dead=False
  259. a\con=typ
  260. a\id=id
  261. a\name=n
  262. a\lives=G_StartLives
  263. a\tlx=0
  264. a\tly=0
  265. a\score=0
  266. a\ox=15
  267. a\brx=GraphicsWidth()
  268. a\bry=GraphicsHeight()
  269. a\piv=CreatePivot()
  270. EntityRadius a\piv,40
  271. EntityType a\piv,TYPE_PLAYER
  272. a\ent=CopyEntity(player_mesh,a\piv)
  273. EntityColor a\ent,r,g,b
  274. a\shield=100
  275. a\shield_ent=CopyEntity(shield_mesh,a\piv)
  276. ;
  277. a\cam=CreateCamera()
  278. CameraRange a\cam,1,24000
  279. CameraFogRange a\cam,12000,24000
  280. CameraFogMode a\cam,1
  281. PositionEntity a\cam,0,0,CameraZpos
  282. EntityType a\cam,TYPE_CAM
  283. EntityRadius a\cam,40
  284. If split=True Then
  285. Select id
  286. Case 0
  287. CameraViewport a\cam,0,0,GraphicsWidth(),GraphicsHeight()/2
  288. a\tlx=0
  289. a\tly=0
  290. a\brx=GraphicsWidth()
  291. a\bry=GraphicsHeight()/2
  292. Case 1
  293. CameraViewport a\cam,0,GraphicsHeight()/2,GraphicsWidth(),GraphicsHeight()/2
  294. a\tlx=0
  295. a\tly=GraphicsHeight()/2
  296. a\brx=GraphicsWidth()
  297. a\bry=GraphicsHeight()
  298. End Select
  299. End If
  300. ;
  301. Return a
  302. End Function
  303. ;
  304. ;Main players update
  305. Function Update_Players()
  306. For a.play=Each play
  307. ;
  308. ;
  309. If a\rate>0 Then a\rate=a\rate-1
  310. score(a\id)=a\score
  311. EntityAlpha a\shield_ent,a\glow
  312. If a\dead=False
  313. If a\glow>0 Then a\glow=a\glow-.05
  314. PositionEntity a\piv,EntityX(a\piv),EntityY(a\piv),0
  315. PositionEntity a\cam,EntityX(a\cam),EntityY(a\cam),CameraZpos
  316. If Cheater=False Then ;Cheat Mode
  317. cnt=CountCollisions(a\piv)
  318. If cnt>0 Then
  319. For b=1 To cnt
  320. te=CollisionEntity(a\piv,cnt)
  321. add_color_Smoke(25,CollisionX(a\piv,b),CollisionY(a\piv,b),CollisionZ(a\piv,b),255,Rnd(100,200),Rnd(100,200))
  322. If te<>Tunnel_Mesh Then
  323. a\shield=a\shield-10
  324. Else
  325. a\shield=a\shield-.5
  326. End If
  327. a\glow=1
  328. Next
  329. End If
  330. End If
  331. ;
  332. ; Do Camera Code
  333. ;
  334. dx#=EntityX(a\piv,True)-EntityX(a\cam,True)
  335. dy#=EntityY(a\piv,True)-(EntityY(a\cam,True)-30)
  336. TranslateEntity a\cam,dx*.05,dy*.05,0
  337. ;
  338. If a\shield<20 And a\shield>0 Then
  339. add_color_Smoke(15,EntityX(a\piv)+Rnd(-1,1),EntityY(a\piv),EntityZ(a\piv),255,Rnd(50,140),Rnd(50,140))
  340. End If
  341. If a\shield<100 And a\shield>0 Then
  342. a\shield=a\shield+.01
  343. End If
  344. If a\shield<0 Then
  345. a\dead=True
  346. a\lives=a\lives-1
  347. End If
  348. If a\dead=True Then
  349. PositionEntity a\piv,0,0,CameraZpos-100
  350. a\waiting=(CameraZpos-100)
  351. a\shield=100
  352. End If
  353. Else ;If dead the do dead routene
  354. If a\waiting<0 Then
  355. ResetEntity a\piv
  356. PositionEntity a\piv,EntityX(a\piv),EntityY(a\piv),a\waiting
  357. a\waiting=a\waiting+1
  358. ResetEntity a\piv
  359. Update_PLCam(a)
  360. RotateEntity a\piv,0,0,0
  361. Else
  362. a\dead=False
  363. End If
  364. End If
  365. If a\lives=0 Then
  366. score(a\id)=a\score
  367. Cls
  368. Num_Players=Num_Players-1
  369. Select a\id
  370. Case 0
  371. Go1_timer=300
  372. Case 1
  373. Go2_timer=300
  374. End Select
  375. Free_Player(a)
  376. End If
  377. Next
  378. End Function
  379. Function Resize_Last_Player()
  380. For a.play=Each play
  381. CameraViewport a\cam,0,0,GraphicsWidth(),GraphicsHeight()
  382. a\tlx=0
  383. a\tly=0
  384. a\brx=GraphicsWidth()
  385. a\bry=GraphicsHeight()
  386. cont=a\con
  387. Next
  388. Return cont
  389. End Function
  390. Function Free_Player(a.play)
  391. If a\shield_ent FreeEntity a\shield_ent
  392. If a\ent FreeEntity a\ent
  393. If a\piv FreeEntity a\piv
  394. If a\cam FreeEntity a\cam
  395. Delete a
  396. End Function
  397. ;
  398. ;Manual update of players camera
  399. Function Update_PLCam(a.play)
  400. ;
  401. ; Do Camera Code
  402. ;
  403. dx#=EntityX(a\piv,True)-EntityX(a\cam,True)
  404. dy#=EntityY(a\piv,True)-(EntityY(a\cam,True)-30)
  405. TranslateEntity a\cam,dx*.05,dy*.05,0
  406. End Function
  407. ;Delete all players in memory
  408. Function delete_Players()
  409. For a.play=Each play
  410. If a\shield_ent FreeEntity a\shield_ent
  411. If a\ent FreeEntity a\ent
  412. If a\piv FreeEntity a\piv
  413. If a\cam FreeEntity a\cam
  414. Delete a
  415. Next
  416. End Function
  417. ;View Update (players)
  418. Function Update_Players_Views()
  419. For a.play=Each play
  420. Color 255,255,255
  421. Text a\tlx,a\tly,a\score
  422. If a\shield<40 Then
  423. Color 255,255,0
  424. End If
  425. If a\shield<20 Then
  426. Color 255,0,0
  427. End If
  428. Rect a\tlx,a\tly+16,a\shield,10
  429. Color 255,255,255
  430. Text a\brx-100,a\bry-16,a\name
  431. Text a\brx-176,a\tly,"Lives:"
  432. For x=0 To a\lives-1
  433. DrawImage Lives_image,a\brx-80+(x*16),a\tly
  434. Next
  435. Next
  436. End Function
  437. ;Find a player from id
  438. Function Get_Player_id.play(id)
  439. For a.play=Each play
  440. If a\id=id Then Return a
  441. Next
  442. Return Null
  443. End Function
  444. ;
  445. ;Update explosion Flash
  446. Function Update_Flash()
  447. AmbientLight Flash_Cnt,Flash_Cnt,Flash_Cnt
  448. If Flash_Cnt>G_Brightness Then Flash_Cnt=Flash_Cnt-5
  449. End Function
  450. Function Set_Flash()
  451. Flash_Cnt=255
  452. End Function
  453. ;
  454. ;
  455. ;
  456. ;
  457. ;
  458. ;