Advertisement
Guest User

fixed

a guest
Feb 5th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.91 KB | None | 0 0
  1. ;last known good.
  2. ;added different health strengths and spawn times.
  3. ;added hide entities names when one player cannot see each other.
  4. ;added sound fx (crude hack)
  5.  
  6. SeedRnd MilliSecs()
  7.  
  8. Const gameLogicFPS = 60
  9.  
  10. ; first we include the KeyFix library
  11. Include "KeyFix_Constants.bb"
  12.  
  13. ; we now include the network library
  14. Include "UDPNetwork_lib.bb"
  15. ; for converting RGB values to "Tri-Hex" stringc inlude hex8.
  16. Include "Hex8.bb" ;<<< Colored txt mod by Raster Ron
  17.  
  18. Global localID
  19. ;Global localName$ = Input("Enter your name : ")
  20. ;If localName = "" Then localName = "player" + Rand(100,999)
  21.  
  22.  
  23. ;<< Enter through mod..
  24. Global localName$ = "", defaultName$ = "RCX" ; Predefined name, so just need To press enter.
  25.  
  26. Print "Change default name: '"+ defaultName$ +"' ?"
  27. Choic$ = Input$("[Press [Y]es or [ENTER] for No: ")
  28. If Choic$="y" Then ; so want to change..
  29. Cls:Locate 0,0
  30. Print "Type name & press [ENTER] or"
  31. ChangeName$=Input$("just [ENTER] to autogenerate: ")
  32. If ChangeName$="" ; so pressed enter to autogen..
  33. localName = "player" + Rand(100,999)
  34. Else ; so entered a new name..
  35. localName$=ChangeName$
  36. EndIf
  37. Else ; so entered without input.
  38. localName$ = defaultName$
  39. EndIf
  40. ;<< End enter through mod.
  41.  
  42. Global localPlayerMesh
  43.  
  44. Type player
  45. Field id
  46. Field name$
  47. Field ping
  48.  
  49. Field life
  50. Field kills
  51. Field deaths
  52.  
  53. Field mesh
  54. Field r,g,b
  55.  
  56. Field nextX#,nextY#,nextZ#
  57. Field previousX#,previousY#,previousZ#
  58. Field nextYaw#
  59. Field previousYaw#
  60. Field nextTime
  61. Field previousTime
  62.  
  63. Field lastPacket
  64.  
  65. Field currentY#
  66. Field velocityY#
  67. End Type
  68.  
  69. Type bullet
  70. Field mesh
  71. Field angle#
  72. Field time
  73. Field id ; id of player who fired
  74. End Type
  75.  
  76. Type health
  77. Field mesh
  78. Field pickupTime ; to store when was pickedup and can hide for a certain time set in
  79. Field respawnDelay ; < see above
  80.  
  81. ;Field id ; to hold healthitem's id
  82. Field power ; to hold strength of upgrade
  83. ;Field pid ; id of player who updated health
  84. End Type
  85.  
  86. Type spawn
  87. Field spawnId
  88. Field x#,y#,z#
  89. Field yaw#
  90. End Type
  91.  
  92. Global spawns ; number of spawn points
  93.  
  94. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  95. ; Camera code from jfk EO-11110, thanks
  96. Global bounce_cam=1 ; smooth camera motion? (0/1)
  97. Global bounce_div#=10.0 ; the higher, the more sluggish the camera will follow. Recc: 3.0 to 20.0
  98. ; some globals used by ChaseCam
  99. Global old_x#,old_y#,old_z#
  100. ; desired distance between camera and player mesh
  101. Global x_dis#=7.0,y_dis#=3,z_dis#=7.0,y_dis_or#=y_dis#
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103.  
  104. ; network init ----------------------------------------;
  105. Global localMode = Net_StartInput() ; bring the library "console" to connect
  106.  
  107. If localMode = 1 Or localMode = 2 ; 1 means we are client, 2 means we are server
  108.  
  109. localID = Net_CreatePlayer(localName) ; this command inits the server or local client
  110.  
  111. If localID = 0 ; error
  112. Net_StopNetwork() ; close the network properly
  113. RuntimeError("Failed to create player.")
  114. EndIf
  115.  
  116. If localMode = 1 Then AppTitle("Client : " + localName + " (port:" + net_port + "/ ID=" + localID + ")")
  117. If localMode = 2 Then AppTitle("Server : " + localName + " (port:" + net_port + "/ ID=" + localID + ")")
  118.  
  119. Else ; error
  120. Net_StopNetwork()
  121. RuntimeError("Failed to start game.")
  122. EndIf
  123. ;------------------------------------------------------;
  124.  
  125. Graphics3D 640,480,32,2
  126. SetBuffer BackBuffer()
  127.  
  128. ;--------------audio-------------
  129. Global musicOn=False, musiclevel#=.5, danger=False ;music
  130. Global bgmusic_vol#=.5, bgmusicChannel, bgmusic
  131. Global dangermusic_vol#=0, dangermusicChannel, dangermusic ;music
  132. Global wade_vol#, run_vol#, wadechannel, runchannel ;player sfx
  133. Global shoot, boom, uh ;projectile
  134.  
  135. ;Make audio
  136. ;If gamelevel=1 Then LoadMusic("spacepanic.mp3") ; load gamemusic
  137. ;If gamelevel=2 Then LoadMusic("Shadow Of The Beast - To The Castle.mp3")
  138. LoadSFX()
  139. If musicOn=False ; if music is off then turn off volume
  140. musiclevel#=0
  141. EndIf
  142.  
  143. ;--------------audio end---------
  144.  
  145. CreateScene()
  146.  
  147. CreateSpawn(-15,1,-30,-45)
  148. CreateSpawn(15,1,-30,45)
  149. CreateSpawn(-15,1,15,-135)
  150. CreateSpawn(15,1,15,135)
  151. CreateSpawn(0,12,0,0)
  152. CreateSpawn(0,1,-9,180)
  153.  
  154. Global camera = CreateCamera()
  155. CameraRange camera,0.1,1000
  156.  
  157. ; create our own local player
  158. localPlayerMesh = CreatePlayer(localID,localName)
  159. old_x = EntityX(localPlayerMesh):old_y = EntityY(localPlayerMesh):old_z = EntityZ(localPlayerMesh) ; update camera position
  160.  
  161. ; we send our color to the server
  162. p.player = Object.player(GetPlayer(localID))
  163. Net_SendMessage(3,p\r + "/" + p\g + "/" + p\b)
  164.  
  165. ; <<< colored txt mod by Raster Ron..
  166. ;store colors for chattxt.
  167. Global cR = p\r
  168. Global cG = p\g
  169. Global cB = p\b
  170. ; <<< end colored txt mod by Raster Ron..
  171.  
  172.  
  173. ; variables used to send our positions at a constant delay (saves bandwidth but makes a constant ping)
  174. Global updatePosition = MilliSecs()
  175. Global updateTick = 50
  176.  
  177. ; chat
  178. Global messageDisplayNumber = 10
  179. Global messageOffset
  180. Dim message$(messageDisplayNumber)
  181.  
  182. Global chatMode
  183. Global chatMessage$ = localName + "> "
  184. Global chatMillisecs = MilliSecs()
  185. Global chatCursor
  186.  
  187. .mainLoop
  188. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  189. tweeningPeriod = 1000 / gameLogicFPS
  190. tweeningTime = MilliSecs() - tweeningPeriod
  191. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  192. While Not KeyHit(1)
  193.  
  194. ;; I use tweening from castle demo here :
  195. ;;
  196. ;; - this allows to have very fast execution outside the tweening loop,
  197. ;; so the network is updated as fast as possible (needs Flip False)
  198. ;;
  199. ;; - this makes the game logic updated at a constant rate (Const FPS=)
  200. ;; so no need to set deltatime (and it saves CPU time for other things)
  201.  
  202.  
  203. ;; -------------------------------------------------------------------------------------------------; FAST EXECUTION (outside of tweening)
  204. ;; -------------------------------------------------------------------------------------------------;
  205.  
  206. ; see the function, the interpolation variables are set properly here
  207. UpdateNetwork()
  208.  
  209. ;; -------------------------------------------------------------------------------------------------;
  210.  
  211. Repeat
  212. tweeningElapsed = MilliSecs() - tweeningTime
  213. Until tweeningElapsed
  214. tweeningTicks = tweeningElapsed / tweeningPeriod
  215. tweeningRate# = Float(tweeningElapsed Mod tweeningPeriod)/Float(tweeningPeriod)
  216. For k = 1 To tweeningTicks
  217. tweeningTime = tweeningTime + tweeningPeriod
  218. If k = tweeningTicks Then CaptureWorld
  219.  
  220. ;; ---------------------------------------------------------------------------------------------; MAIN UPDATE
  221. ;; ---------------------------------------------------------------------------------------------;
  222.  
  223. ;sound
  224. ChannelVolume wadechannel, wade_vol# ; adjust wadesound volume 0-1
  225. ChannelVolume runchannel, run_vol# ; adjust runsound volume 0-1
  226. ChannelVolume bgmusicChannel, bgmusic_vol# ;
  227. ChannelVolume dangermusicChannel, dangermusic_vol# ;
  228.  
  229.  
  230.  
  231. ; update our player
  232. UpdateLocalPlayer()
  233.  
  234. ; the interpolation is made in this function
  235. UpdatePlayers()
  236.  
  237.  
  238.  
  239. ; update the bullets... only the server check for player kills
  240. UpdateBullets()
  241.  
  242. UpdateHealthItems()
  243.  
  244. UpdateWorld()
  245.  
  246. UpdateChaseCam(camera,localPlayerMesh)
  247.  
  248. ;; ---------------------------------------------------------------------------------------------;
  249.  
  250. Next
  251.  
  252. RenderWorld tweeningRate
  253.  
  254. ;; -------------------------------------------------------------------------------------------------; 2D UPDATE
  255. ;; -------------------------------------------------------------------------------------------------;
  256.  
  257. DrawPlayersNames()
  258. DrawHealthItemStrengths()
  259.  
  260. If ( KeyHit ( 28 ) ) And chatMode = 0 Then chatMode = 1 : FlushKeys() ; Enter for chat on/off
  261. If ( KeyHit ( 53 ) ) And chatMode = 0 Then chatMode = 1 ;/ for chat on
  262.  
  263. If chatMode Then UpdateChat()
  264.  
  265. DrawMessages()
  266.  
  267. If KeyDown(15) Then DrawScoreTable() ; Tab for scores
  268.  
  269. ;; -------------------------------------------------------------------------------------------------;
  270.  
  271. Flip
  272.  
  273. Wend
  274. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  275. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  276.  
  277. Net_StopNetwork()
  278.  
  279. End
  280.  
  281. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  282. Function UpdateNetwork()
  283.  
  284. ; update incoming packets (better check ALL incoming messages so use While Wend)
  285. While Net_CheckMessage() ; will check for a new message and fill Net_MsgType, Net_MsgString$, Net_MsgFrom and Net_MsgTo variables so we can read it
  286.  
  287. p.player = Object.player(GetPlayer(Net_MsgFrom)) ; get the player handle
  288.  
  289. If Handle(p) = 0 And Net_MsgType < 100 ; we received an update packet from a player we don't know
  290. ; so we ask the server who he is and return because we can't update him for now
  291. ; the server will resend us the info in a new player "100" message
  292. Net_RequestPlayer(Net_MsgFrom)
  293. Return
  294. EndIf
  295.  
  296. Select Net_MsgType ; check the type of message
  297.  
  298. Case 1 ; chat message
  299.  
  300. NewMessage(Net_MsgString)
  301.  
  302. Case 2 ; player position and angle, example of packing data into string
  303.  
  304. offset1 = Instr(Net_MsgString,"/",1)
  305. offset2 = Instr(Net_MsgString,"/",offset1+1)
  306. offset3 = Instr(Net_MsgString,"/",offset2+1)
  307.  
  308. p\previousX = p\nextX
  309. p\previousY = p\nextY
  310. p\previousZ = p\nextZ
  311. p\previousYaw = p\nextYaw
  312.  
  313. p\nextX = Left(Net_MsgString,offset1-1)
  314. p\nextY = Mid(Net_MsgString,offset1+1,offset2-offset1-1)
  315. p\nextZ = Mid(Net_MsgString,offset2+1,offset3-offset2-1)
  316. p\nextYaw = Right(Net_MsgString,Len(Net_MsgString)-offset3)
  317.  
  318. p\previousTime = p\nextTime
  319. p\nextTime = MilliSecs()
  320.  
  321. Case 3 ; update player colors
  322.  
  323. offset1 = Instr(Net_MsgString,"/",1)
  324. offset2 = Instr(Net_MsgString,"/",offset1+1)
  325.  
  326. p\r = Left(Net_MsgString,offset1-1)
  327. p\g = Mid(Net_MsgString,offset1+1,offset2-offset1-1)
  328. p\b = Right(Net_MsgString,Len(Net_MsgString)-offset2)
  329.  
  330. EntityColor p\mesh,p\r,p\g,p\b
  331.  
  332. Case 4 ; a player fired
  333.  
  334. CreateBullet(Net_MsgFrom)
  335.  
  336. Case 5 ; a player lost some life
  337.  
  338. p\life = Net_MsgString
  339.  
  340. Case 6 ; a player killed another one
  341.  
  342. k.player = Object.player(GetPlayer(Net_MsgString)) ; killed player ID in MsgData
  343. NewMessage(p\name + " killed " + k\name)
  344.  
  345. shootChannel = PlaySound (boom) ;boom sound is started.
  346.  
  347. ;ResetPlayer(k\id)
  348.  
  349. Case 7 ; the server sends us score update for a player
  350.  
  351. offset = Instr(Net_MsgString,"/",1)
  352.  
  353. p\kills = Left(Net_MsgString,offset-1)
  354. p\deaths = Right(Net_MsgString,Len(Net_MsgString)-offset)
  355.  
  356. Case 8 ; health pickup
  357.  
  358. h.health = Object.health(Net_MsgString)
  359. HideEntity h\mesh
  360. h\pickupTime = MilliSecs()
  361.  
  362. Case 9 ; player spawn
  363.  
  364. SpawnPlayer(p\id,Net_MsgString)
  365.  
  366.  
  367.  
  368. Case 100 ; new player connected, OR the server tells us who is already connected so we can create players when joining the game
  369.  
  370. If localMode = 2
  371. For p.player = Each player
  372. Net_SendMessage(2,p\nextX + "/" + p\nextY + "/" + p\nextZ + "/" + p\nextYaw,p\id,Net_MsgFrom)
  373. Net_SendMessage(3,p\r + "/" + p\g + "/" + p\b,p\id,Net_MsgFrom)
  374.  
  375. Net_SendMessage(5,p\life,p\id,Net_MsgFrom)
  376. Net_SendMessage(7,p\kills+"/"+p\deaths,p\id,Net_MsgFrom)
  377. Next
  378. EndIf
  379.  
  380. NewMessage(Net_MsgString + " connected")
  381. CreatePlayer(Net_MsgFrom,Net_MsgString)
  382.  
  383. Case 101 ; a player has quit
  384.  
  385. For p.player = Each player
  386. If Net_MsgFrom = p\id
  387. NewMessage(p\name + " disconnected")
  388. FreeEntity p\mesh
  389. Delete p
  390. EndIf
  391. Next
  392.  
  393. Case 102 ; host has changed
  394.  
  395. For p.player = Each player
  396. If Net_MsgFrom = p\id
  397. If p\id = localID
  398. AppTitle("Server : " + localName + " (port:" + net_port + ")")
  399. NewMessage("You are the new host")
  400. localMode = 2
  401. Else
  402. NewMessage(p\name + " is the new host")
  403. EndIf
  404. EndIf
  405. Next
  406.  
  407. Case 103 ; ping update
  408.  
  409. For p.player = Each player
  410. If Net_MsgFrom = p\id
  411. p\ping = Net_MsgString
  412. EndIf
  413. Next
  414.  
  415. End Select
  416.  
  417. Wend
  418.  
  419. End Function
  420.  
  421. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  422. Function UpdateLocalPlayer()
  423.  
  424. ; update our player
  425. p.player = Object.player(GetPlayer(localID)) ; get our player
  426.  
  427. ; inputs
  428.  
  429. If Not chatMode
  430.  
  431. If WK_DOWN ( ) Then MoveEntity p\mesh,0,0,0.3 ; up
  432. If SK_DOWN ( ) Then MoveEntity p\mesh,0,0,-0.3 ; down
  433. If AK_DOWN ( ) Then TurnEntity p\mesh,0,3,0 ; left
  434. If DK_DOWN ( ) Then TurnEntity p\mesh,0,-3,0 ; right
  435.  
  436. EndIf
  437.  
  438. If UP_KDOWN ( ) Then MoveEntity p\mesh,0,0,0.3 ; up
  439. If DOWN_KDOWN ( ) Then MoveEntity p\mesh,0,0,-0.3 ; down
  440. If LEFT_KDOWN ( ) Then TurnEntity p\mesh,0,3,0 ; left
  441. If RIGHT_KDOWN ( ) Then TurnEntity p\mesh,0,-3,0 ; right
  442.  
  443. ; jump
  444. If ( ( chatMode = 0 ) And ( KeyHit ( 57 ) ) Or ( MouseHit ( 2 ) ) ) ; right mse or Spacebar
  445. ; check if player is one the ground
  446. LinePick(EntityX(p\mesh),EntityY(p\mesh),EntityZ(p\mesh),0,-1.2,0)
  447. If PickedEntity()
  448. p\velocityY = 0.5 ; set "inverse" of gravity velocity
  449. EndIf
  450. EndIf
  451.  
  452. ; fire
  453. If ( ( chatMode = 0 ) And ( LM_DOWN ( ) ) ) ; left mouse down
  454. Net_SendMessage(4,"")
  455. CreateBullet(localID)
  456. EndIf
  457.  
  458. ; we create a message type "2" for player position
  459. If MilliSecs()-updatePosition > updateTick
  460.  
  461. Net_SendMessage(2,EntityX(p\mesh) + "/" + EntityY(p\mesh) + "/" + EntityZ(p\mesh) + "/" + EntityYaw(p\mesh))
  462.  
  463. updatePosition = MilliSecs()
  464.  
  465. EndIf
  466.  
  467. End Function
  468.  
  469. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  470. Function UpdatePlayers()
  471.  
  472. For p.player = Each player
  473.  
  474. If p\id <> localID ; update other players only
  475.  
  476. ;; LINEAR INTERPOLATION ;;;;;;;;;;
  477.  
  478. If p\nextTime <> p\previousTime ; if both packets arrived at the same time, we can't interpolate
  479.  
  480. curTime# = Float(MilliSecs()-p\nextTime) / Float(p\nextTime-p\previousTime) ; curTime will be ideally 0.0-1.0, if it's > 1.0 then it performs extrapolation
  481.  
  482. If curTime > 1 Then curTime = 1 ; extrapolation gives anoying jittering effects
  483.  
  484. ; special fix for yaw as EntityYaw returns a value beetween +180 ans -180, the interpolation can go backward
  485. If p\previousYaw < 0 Then p\previousYaw = p\previousYaw + 360
  486. If p\nextYaw < 0 Then p\nextYaw = p\nextYaw + 360
  487. If Abs(p\nextYaw-p\previousYaw) > 180
  488. If p\nextYaw > p\previousYaw
  489. p\previousYaw = p\previousYaw + 360
  490. Else
  491. p\previousYaw = p\previousYaw - 360
  492. EndIf
  493. EndIf
  494.  
  495. PositionEntity p\mesh,p\previousX+(p\nextX-p\previousX)*curTime,p\previousY+(p\nextY-p\previousY)*curTime,p\previousZ+(p\nextZ-p\previousZ)*curTime
  496. RotateEntity p\mesh,0,p\previousYaw+(p\nextYaw-p\previousYaw)*curTime,0
  497.  
  498. Else
  499.  
  500. PositionEntity p\mesh,p\nextX,p\nextY,p\nextZ
  501. RotateEntity p\mesh,0,p\nextYaw,0
  502.  
  503. EndIf
  504. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  505.  
  506. ResetEntity p\mesh ; reset entity is useful here because of collisions
  507.  
  508. Else ; update our player, basically it just compute gravity
  509.  
  510. p\velocityY = p\velocityY - 0.03 ; fake gravity
  511. If EntityY(p\mesh) - p\currentY >= 0 ; if player is not falling we limit the gravity
  512. If p\velocityY < -0.03 Then p\velocityY = -0.03
  513. EndIf
  514.  
  515. p\currentY = EntityY(p\mesh)
  516. TranslateEntity p\mesh,0,p\velocityY,0
  517.  
  518. EndIf
  519. Next
  520.  
  521. End Function
  522.  
  523. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  524. Function CreatePlayer(id,name$)
  525.  
  526. For p.player = Each player
  527. If p\id = id Then Return ; player already connected
  528. Next
  529.  
  530. p.player = New player
  531. p\id = id
  532. p\name = name
  533.  
  534. p\life = 80
  535.  
  536. ;build player entity
  537. p\mesh = CreateSphere()
  538. EntityType p\mesh,2
  539. EntityRadius p\mesh,1
  540.  
  541. NameEntity p\mesh,Handle(p)
  542.  
  543. nose = CreateSphere(8,p\mesh):EntityColor nose,255,0,0
  544. PositionEntity nose,0,0,1
  545. ScaleEntity nose,0.3,0.3,0.3
  546.  
  547. eyeLeft = CreateSphere(8,p\mesh):EntityColor eyeLeft,255,255,255
  548. PositionEntity eyeLeft ,.29,.4,.7;1
  549. ScaleEntity eyeLeft ,0.2,0.2,0.2
  550.  
  551. pupilLeft = CreateSphere(8,p\mesh):EntityColor pupilLeft ,0,0,0
  552. PositionEntity pupilLeft ,.3,.4,.9;1
  553. ScaleEntity pupilLeft ,0.05,0.05,0.02
  554.  
  555. eyeRight = CreateSphere(8,p\mesh):EntityColor eyeRight ,255,255,255
  556. PositionEntity eyeRight ,-.29,.4,.7;1
  557. ScaleEntity eyeRight ,0.2,0.2,0.2
  558.  
  559. pupilRight = CreateSphere(8,p\mesh):EntityColor pupilRight ,0,0,0
  560. PositionEntity pupilRight ,-.3,.4,.9;1
  561. ScaleEntity pupilRight ,0.05,0.05,0.02
  562.  
  563. unaBrow = CreateCone(8,1,p\mesh):EntityColor unaBrow ,0,0,0
  564. PositionEntity unaBrow ,0,.45,.7
  565. RotateEntity unaBrow ,-180,0,0
  566. ScaleEntity unaBrow ,.7,.2,.3
  567.  
  568. RandomSpawn(p\id)
  569.  
  570. ;positions
  571. ; location=Rand (1,2)
  572. ; If location=1
  573. ;
  574. ; p\nextX = -20
  575. ; p\nextY = 6.5
  576. ; p\nextZ = -20
  577. ;
  578. ; Else
  579. ; p\nextX = 20
  580. ; p\nextY = 6.5
  581. ; p\nextZ = 20
  582. ; EndIf
  583. ; p\nextYaw = -45
  584. ;
  585. ; p\previousX = p\nextX
  586. ;; p\previousY = p\nextY
  587. ; p\previousZ = p\nextZ
  588. ; p\previousYaw = p\nextYaw
  589. ;
  590. p\r = Rand(255)
  591. p\g = Rand(255)
  592. p\b = Rand(255)
  593. EntityColor p\mesh,p\r,p\g,p\b
  594.  
  595. ; PositionEntity p\mesh,p\nextX,p\nextY,p\nextZ
  596. ; RotateEntity p\mesh,0,p\nextYaw,0
  597. ; ResetEntity p\mesh
  598. ;
  599. ; p\currentY = p\nextY
  600. ;
  601. ; p\previousTime = MilliSecs()
  602. ; p\nextTime = MilliSecs()+1
  603.  
  604. Return p\mesh
  605.  
  606. End Function
  607.  
  608. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  609. Function SpawnPlayer(id,spawnId)
  610.  
  611. p.player = Object.player(GetPlayer(id))
  612.  
  613. For s.spawn = Each spawn
  614. If s\spawnId = spawnId Then Exit
  615. Next
  616.  
  617. p\life = 100
  618.  
  619. p\nextX = s\x
  620. p\nextY = s\y
  621. p\nextZ = s\z
  622. p\nextYaw = s\yaw
  623.  
  624. p\previousX = p\nextX
  625. p\previousY = p\nextY
  626. p\previousZ = p\nextZ
  627. p\previousYaw = p\nextYaw
  628.  
  629. PositionEntity p\mesh,p\nextX,p\nextY,p\nextZ
  630. RotateEntity p\mesh,0,p\nextYaw,0
  631. ResetEntity p\mesh
  632.  
  633. p\currentY = p\nextY
  634.  
  635. p\previousTime = MilliSecs()
  636. p\nextTime = MilliSecs()+1
  637.  
  638. End Function
  639.  
  640. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  641. Function RandomSpawn(id)
  642.  
  643. p.player = Object.player(GetPlayer(id))
  644.  
  645. ; if we are server, spawn player at random location
  646. If localMode = 2
  647. randSpawn = Rand(spawns)
  648. SpawnPlayer(p\id,randSpawn)
  649. Net_SendMessage(9,randSpawn,p\id)
  650. Net_SendMessage(9,randSpawn,p\id,p\id)
  651. Else ; else default spawn = first spawn created
  652. SpawnPlayer(p\id,1)
  653. EndIf
  654.  
  655. End Function
  656.  
  657. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  658. Function CreateSpawn(x#,y#,z#,yaw#)
  659.  
  660. spawns = spawns + 1
  661.  
  662. s.spawn = New spawn
  663. s\spawnId = spawns
  664. s\x = x
  665. s\y = y
  666. s\z = z
  667. s\yaw = yaw
  668.  
  669. End Function
  670.  
  671. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  672. ;Function ResetPlayer(id)
  673. ;
  674. ; p.player = Object.player(GetPlayer(id))
  675. ;
  676. ; p\life = 100
  677. ;
  678. ; location=Rand (1,2)
  679. ; If location=1
  680. ;
  681. ; p\nextX = -20
  682. ; p\nextY = 6.5
  683. ; p\nextZ = -20
  684. ;
  685. ; Else
  686. ;
  687. ; p\nextX = 20
  688. ; p\nextY = 6.5
  689. ; p\nextZ = 20
  690. ; EndIf
  691. ;
  692. ; p\nextYaw = -45
  693. ;
  694. ;
  695. ;
  696. ; p\previousX = p\nextX
  697. ; p\previousY = p\nextY
  698. ; p\previousZ = p\nextZ
  699. ; p\previousYaw = p\nextYaw
  700. ; ;back to origin.
  701. ; PositionEntity p\mesh,p\nextX,p\nextY,p\nextZ
  702. ; RotateEntity p\mesh,0,p\nextYaw,0
  703. ; ResetEntity p\mesh
  704. ;
  705. ; p\currentY = p\nextY
  706. ;
  707. ; p\previousTime = MilliSecs()
  708. ; p\nextTime = MilliSecs()+1
  709.  
  710. ;End Function
  711.  
  712. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  713. Function GetPlayer(id)
  714.  
  715. For p.player = Each player
  716. If p\id = id
  717. Return Handle(p)
  718. EndIf
  719. Next
  720.  
  721. End Function
  722.  
  723. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  724. Function DrawPlayersNames()
  725.  
  726. For p.player = Each player
  727. If EntityVisible (p\mesh,camera)
  728.  
  729. Color 255,255,255
  730. CameraProject(camera,EntityX(p\mesh),EntityY(p\mesh),EntityZ(p\mesh))
  731.  
  732. ; only when not the host
  733. If p\id <> localID Then Text ProjectedX(),ProjectedY()-60,p\name,1,1 ; the more health, the brighter the color..
  734.  
  735. Color 255,(255./100.)*p\life,(255./100.)*p\life ;?
  736. Text ProjectedX(),ProjectedY()-40,p\life,1,1
  737. EndIf
  738. Next
  739.  
  740. End Function
  741. Function DrawHealthItemStrengths()
  742.  
  743. For h.health = Each health
  744. If EntityVisible (h\mesh,camera)
  745. Color 255,0,0
  746. CameraProject(camera,EntityX(h\mesh),EntityY(h\mesh),EntityZ(h\mesh))
  747.  
  748. Color 255,(255./100.)*h\power,(255./100.)*h\power
  749. If MilliSecs() - h\pickupTime > h\respawnDelay Then ;ShowEntity h\mesh
  750. Text ProjectedX(),ProjectedY()-35,h\power,1,1
  751. EndIf
  752. EndIf
  753. Next
  754.  
  755. End Function
  756.  
  757. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  758. Function CreateBullet(id)
  759.  
  760. p.player = Object.player(GetPlayer(id))
  761.  
  762. b.bullet = New bullet
  763.  
  764. b\id = p\id
  765.  
  766. b\mesh = CreateSphere(2)
  767. ScaleEntity b\mesh,0.2,0.2,0.2
  768. EntityColor b\mesh,255,255,0
  769.  
  770. PositionEntity b\mesh,EntityX(p\mesh),EntityY(p\mesh),EntityZ(p\mesh)
  771. RotateEntity b\mesh,0,EntityYaw(p\mesh),0
  772.  
  773. EntityType b\mesh,3
  774. EntityRadius b\mesh,0.2
  775.  
  776. shootChannel = PlaySound (shoot) ;shooting sound is started.
  777.  
  778. b\time = MilliSecs()
  779.  
  780. End Function
  781.  
  782. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  783. Function UpdateBullets()
  784.  
  785. For b.bullet = Each bullet
  786.  
  787. MoveEntity b\mesh,0,0,1
  788.  
  789. If CountCollisions(b\mesh)
  790.  
  791. If localMode = 2 ; only the server compute bullets collision with player
  792. If GetEntityType(CollisionEntity(b\mesh,1)) = 2 ; a player is hit
  793.  
  794. touchedPlayer.player = Object.player(EntityName(CollisionEntity(b\mesh,1)))
  795. touchedPlayer\life = touchedPlayer\life - 10
  796.  
  797. If touchedPlayer\life > 0 ; touched
  798. Net_SendMessage(5,touchedPlayer\life,touchedPlayer\id)
  799. Net_SendMessage(5,touchedPlayer\life,touchedPlayer\id,touchedPlayer\id)
  800. Else ; killed
  801. killerPlayer.player = Object.player(GetPlayer(b\id))
  802.  
  803. killerPlayer\kills = killerPlayer\kills + 1
  804. touchedPlayer\deaths = touchedPlayer\deaths + 1
  805.  
  806. Net_SendMessage(6,touchedPlayer\id,killerPlayer\id)
  807. Net_SendMessage(6,touchedPlayer\id,killerPlayer\id,killerPlayer\id)
  808.  
  809. Net_SendMessage(7,killerPlayer\kills+"/"+killerPlayer\deaths,killerPlayer\id)
  810. Net_SendMessage(7,killerPlayer\kills+"/"+killerPlayer\deaths,killerPlayer\id,killerPlayer\id)
  811.  
  812. Net_SendMessage(7,touchedPlayer\kills+"/"+touchedPlayer\deaths,touchedPlayer\id)
  813. Net_SendMessage(7,touchedPlayer\kills+"/"+touchedPlayer\deaths,touchedPlayer\id,touchedPlayer\id)
  814.  
  815. NewMessage(killerPlayer\name + " killed " + touchedPlayer\name)
  816. RandomSpawn(touchedPlayer\id)
  817. ;ResetPlayer(touchedPlayer\id)
  818. EndIf
  819.  
  820. EndIf
  821. EndIf
  822.  
  823. FreeEntity b\mesh
  824. Delete b
  825.  
  826. ElseIf MilliSecs()-b\time > 2000
  827.  
  828. FreeEntity b\mesh
  829. Delete b
  830.  
  831. EndIf
  832.  
  833. Next
  834.  
  835. End Function
  836.  
  837. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  838. Function CreateHealthItem(x#,y#,z#,power#,respawnDelay#)
  839.  
  840. h.health = New health
  841.  
  842. h\mesh = CreateMesh()
  843.  
  844. h\power = power ; set item strength
  845.  
  846. ;h\respawnDelay = 10000
  847. h\respawnDelay = respawnDelay ; set according to valuableness(strength actually)..
  848.  
  849.  
  850.  
  851. ; create the object..
  852. mesh1 = CreateCube()
  853. mesh2 = CreateCube()
  854.  
  855. ScaleMesh mesh1,.20,.5,.20
  856. ScaleMesh mesh2,.20,.5,.20:RotateMesh mesh2,90,0,0
  857.  
  858. AddMesh(mesh1,h\mesh)
  859. AddMesh(mesh2,h\mesh)
  860.  
  861. EntityColor h\mesh,255,0,0
  862.  
  863.  
  864. ; if we are the host..
  865. If localMode = 2 Then EntityType h\mesh,4
  866. EntityRadius h\mesh,0.5
  867.  
  868. PositionEntity h\mesh,x,y,z
  869.  
  870. NameEntity h\mesh,Handle(h)
  871.  
  872. End Function
  873.  
  874. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  875. Function UpdateHealthItems()
  876.  
  877. For h.health = Each health
  878.  
  879. TurnEntity h\mesh,0,-2,0
  880.  
  881. If CountCollisions(h\mesh)
  882.  
  883. If localMode = 2 ; only the server computes collision with player
  884. If GetEntityType(CollisionEntity(h\mesh,1)) = 2 ; a player collided
  885.  
  886. touchedPlayer.player = Object.player(EntityName(CollisionEntity(h\mesh,1)))
  887.  
  888. h\pickupTime = MilliSecs() ;store time of pickup
  889. HideEntity h\mesh
  890. ResetEntity h\mesh ;empty collisions buffer for this entity
  891.  
  892. Net_SendMessage(8,Handle(h))
  893.  
  894. If touchedPlayer\life < 100 ; touched healthpowerup..
  895.  
  896. ;touchedPlayer\life = touchedPlayer\life + 10
  897. ;touchedPlayer\life = touchedPlayer\life + 50
  898. touchedPlayer\life = touchedPlayer\life + h\power
  899.  
  900. If touchedPlayer\life >100
  901. touchedPlayer\life = 100
  902.  
  903. EndIf
  904. Net_SendMessage(5,touchedPlayer\life,touchedPlayer\id)
  905. Net_SendMessage(5,touchedPlayer\life,touchedPlayer\id,touchedPlayer\id)
  906.  
  907. EndIf
  908.  
  909. EndIf
  910. EndIf
  911.  
  912. EndIf
  913.  
  914. If MilliSecs() - h\pickupTime > h\respawnDelay Then ShowEntity h\mesh
  915.  
  916. Next
  917.  
  918. End Function
  919. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  920.  
  921. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  922. Function NewMessage(msg$)
  923.  
  924. messageOffset = messageOffset + 1
  925.  
  926. If messageOffset > messageDisplayNumber
  927.  
  928. messageOffset = messageOffset - 1
  929.  
  930. For i = 2 To messageDisplayNumber
  931. message(i-1) = message(i)
  932. Next
  933.  
  934. message(messageDisplayNumber) = msg
  935.  
  936. Else
  937.  
  938. message(messageOffset) = msg
  939.  
  940. EndIf
  941.  
  942. End Function
  943.  
  944. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  945. Function DrawMessages()
  946.  
  947. Color 255,255,255
  948.  
  949. For i = 1 To messageOffset
  950.  
  951. ;Text 0,(i-1)*15,message(i)
  952.  
  953. ; <<< colored txt mod by Raster Ron
  954. loc = Instr (message(i), "¿",1)
  955. If loc > 1 Then
  956. colorMessage$ = Mid$(message(i), 1, Len(message(i)) - 7 )
  957. Hex$ = Right$(message(i),6)
  958. Set_Color_Hex(Hex$)
  959. Text 0,(i-1)*15,colorMessage$
  960. Else
  961. Color 255,255,255
  962. Text 0,(i-1)*15,message(i)
  963. End If
  964. ; <<< End colored txt mod by Raster Ron
  965.  
  966. Next
  967.  
  968. End Function
  969.  
  970. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  971. Function UpdateChat()
  972.  
  973. key = GetKey()
  974.  
  975. If key
  976. If key = 13
  977. If chatMessage <> localName + "> "
  978. For i = Len(localName + "> ") To Len(chatMessage)
  979. If Mid(chatMessage,i,1) <> " "
  980.  
  981. ; <<< colored txt mod by Raster Ron
  982. chatColor$ = RGB_To_TriHex(cR,cG,cB)
  983. chatMessage = chatMessage + "¿" + chatColor$
  984. ; <<< end colored txt mod by Raster Ron
  985.  
  986.  
  987. Net_SendMessage(1,chatMessage)
  988. NewMessage(chatMessage)
  989. Exit
  990. EndIf
  991. Next
  992. EndIf
  993. chatMessage = localName + "> "
  994. chatMode = 0
  995. ElseIf key = 8 And Len(chatMessage) > Len ( localName + "> " )
  996. chatMessage = Left(chatMessage,Len(chatMessage)-1)
  997. ElseIf key > 31 And key < 127
  998. chatMessage = chatMessage + Chr(key)
  999. EndIf
  1000. EndIf
  1001.  
  1002. Color 255,255,255
  1003. Rect 0,GraphicsHeight()-20,GraphicsWidth(),20,1
  1004.  
  1005. Color 0,0,0
  1006. Rect 0,GraphicsHeight()-20,GraphicsWidth(),20,0
  1007.  
  1008.  
  1009. If MilliSecs()-chatMillisecs > 500
  1010. chatCursor = Not chatCursor
  1011. chatMillisecs = MilliSecs()
  1012. EndIf
  1013.  
  1014. If chatCursor
  1015. Text 5,GraphicsHeight()-17,chatMessage + "|"
  1016. Else
  1017. Text 5,GraphicsHeight()-17,chatMessage
  1018. EndIf
  1019.  
  1020. End Function
  1021.  
  1022. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1023. Function DrawScoreTable()
  1024.  
  1025. For p.player = Each player
  1026. count = count + 1
  1027. Next
  1028.  
  1029. baseX = (GraphicsWidth()-350)/2
  1030. baseY = (GraphicsHeight()-(35+20*count))/2
  1031.  
  1032. Color 0,0,0
  1033. Rect baseX,baseY,350,35+20*count,1
  1034.  
  1035. Color 255,192,0
  1036. Rect baseX,baseY,350,35+20*count,0
  1037.  
  1038. Text baseX+10,baseY+10,"Player Kills Deaths Ping"
  1039. Line baseX,baseY+25,baseX+349,baseY+25
  1040.  
  1041. For p.player = Each player
  1042.  
  1043. Color 255,255,255
  1044. If p\id = localID Then Color 255,100,100
  1045.  
  1046. i = i + 1
  1047. Text baseX+10,baseY+10+20*i,p\name
  1048. Text baseX+157,baseY+10+20*i,p\kills,1,0
  1049. Text baseX+240,baseY+10+20*i,p\deaths,1,0
  1050. Text baseX+322,baseY+10+20*i,p\ping,1,0
  1051. Next
  1052.  
  1053. End Function
  1054.  
  1055. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1056. Function UpdateChaseCam(camera,player) ; thanks to jfk EO-11110 on bb forums for this function !
  1057. PositionEntity camera,EntityX(player,1),EntityY(player,1),EntityZ(player,1)
  1058. ResetEntity camera
  1059. x#=EntityX(player)+Sin(-EntityYaw(player)+180)*x_dis#
  1060. y#=EntityY(player)+y_dis#
  1061. z#=EntityZ(player)+Cos(-EntityYaw(player)+180)*z_dis#
  1062. obstacle=LinePick(EntityX(player),EntityY(player),EntityZ(player),(x-EntityX(player)),y_dis#,(z-EntityZ(player)),0.1)
  1063. If obstacle=0
  1064. new_x#=x
  1065. new_y#=y
  1066. new_z#=z
  1067. Else
  1068. new_x#=PickedX()
  1069. new_y#=PickedY()
  1070. new_z#=PickedZ()
  1071. EndIf
  1072. If bounce_cam=0
  1073. PositionEntity camera,new_x,new_y,new_z
  1074. Else
  1075. x=old_x+((New_x-old_x)/bounce_div#)
  1076. y=old_y+((New_y-old_y)/bounce_div#)
  1077. z=old_z+((New_z-old_z)/bounce_div#)
  1078. PositionEntity camera,x,y,z
  1079. EndIf
  1080. PointEntity camera,player
  1081. TurnEntity camera,-20,0,0 ; if you want the player mesh more on the bottom of the screen
  1082. old_x#=EntityX(camera)
  1083. old_y#=EntityY(camera)
  1084. old_z#=EntityZ(camera)
  1085. End Function
  1086.  
  1087. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1088. Function CreateScene()
  1089.  
  1090. texture = TextureCreate(128)
  1091.  
  1092. ground = CreatePlane()
  1093. EntityColor ground,150,150,150
  1094. EntityTexture ground,texture
  1095.  
  1096. cube = CreateCube():EntityColor cube,150,200,150
  1097. ScaleEntity cube,5,5,5:PositionEntity cube,0,5,0
  1098. EntityTexture cube,texture
  1099.  
  1100. sphere = CreateSphere(16):EntityColor sphere,200,150,150
  1101. ScaleEntity sphere,3,1,3:PositionEntity sphere,0,9.7,0
  1102.  
  1103. platform = CreateCube():EntityColor platform,150,150,200
  1104. ScaleEntity platform,3,1,10:PositionEntity platform,0,4.13,-13.15
  1105. TurnEntity platform,-30,0,0
  1106. EntityTexture platform,texture
  1107.  
  1108. ; spawnpoint
  1109. spawner1 = CreateSphere() :EntityColor spawner1 ,150,150,150; <<<<
  1110. ScaleEntity spawner1 ,2,3,2:PositionEntity spawner1 ,-20,.1,-20 ;<<<<
  1111. EntityTexture spawner1 ,texture
  1112.  
  1113. column= CreateCylinder()
  1114. ScaleEntity column,2,3,2:PositionEntity column,20,.1,20 ;<<<<
  1115. EntityTexture column,texture
  1116.  
  1117. FreeTexture texture
  1118.  
  1119.  
  1120.  
  1121. EntityType ground,1:EntityPickMode ground,2
  1122. EntityType cube,1:EntityPickMode cube,2
  1123. EntityType sphere,1:EntityPickMode sphere,2
  1124. EntityType platform,1:EntityPickMode platform,2
  1125. EntityType spawner1,1:EntityPickMode spawner1,2
  1126. EntityType column,1:EntityPickMode column,2
  1127.  
  1128.  
  1129.  
  1130. ; setup light..
  1131. light = CreateLight()
  1132. TurnEntity light,30,70,0
  1133.  
  1134. ; create health upgrade items.
  1135. CreateHealthItem(0,12,0,100,100000) ; the one on top
  1136. CreateHealthItem(0,1,-10,10,10000) ; undenneath the ramp
  1137. CreateHealthItem(0,3,-20,30,30000) ; on the ramp
  1138.  
  1139.  
  1140. ;; COLLISIONS
  1141. Collisions 2,1,2,3 ; player to scene
  1142. Collisions 2,2,1,3 ; player to player
  1143.  
  1144. Collisions 3,1,2,1 ; bullet to scene
  1145. Collisions 3,2,1,1 ; bullet to player
  1146.  
  1147. Collisions 2,4,1,2 ; player to health
  1148.  
  1149. End Function
  1150.  
  1151. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1152. Function TextureCreate(size)
  1153. texture = CreateTexture(size,size,9)
  1154. SetBuffer TextureBuffer(texture)
  1155. Color 255,255,255
  1156. Rect 0,0,size,size,1
  1157. Color 0,0,0
  1158. Rect 0,0,size,size,0
  1159. Line 0,0,size,size
  1160. Line 0,size,size,0
  1161. SetBuffer BackBuffer()
  1162. Return texture
  1163. End Function
  1164.  
  1165. Function GDI_VKeyDown ( VirtualKey, IgnoreFocus = False )
  1166.  
  1167. If ( IgnoreFocus = True ) And ( api_GetActiveWindow ( ) = 0 ) Then Return
  1168. Return ( api_GetAsyncKeyState% ( VirtualKey ) And %1000000000000000 ) > 0
  1169.  
  1170. End Function
  1171.  
  1172. Function UP_KDOWN ( ignore_focus% = 1 )
  1173.  
  1174. Return ( GDI_VKeyDown ( VK_UP, ignore_focus% ) )
  1175.  
  1176. End Function
  1177.  
  1178. Function DOWN_KDOWN ( ignore_focus% = 1 )
  1179.  
  1180. Return ( GDI_VKeyDown ( VK_DOWN, ignore_focus% ) )
  1181.  
  1182. End Function
  1183.  
  1184. Function LEFT_KDOWN ( ignore_focus% = 1 )
  1185.  
  1186. Return ( GDI_VKeyDown ( VK_LEFT, ignore_focus% ) )
  1187.  
  1188. End Function
  1189.  
  1190. Function RIGHT_KDOWN ( ignore_focus% = 1 )
  1191.  
  1192. Return ( GDI_VKeyDown ( VK_RIGHT, ignore_focus% ) )
  1193.  
  1194. End Function
  1195.  
  1196. Function WK_DOWN ( ignore_focus% = 1 )
  1197.  
  1198. Return ( GDI_VKeyDown ( VK_W, ignore_focus% ) )
  1199.  
  1200. End Function
  1201.  
  1202. Function SK_DOWN ( ignore_focus% = 1 )
  1203.  
  1204. Return ( GDI_VKeyDown ( VK_S, ignore_focus% ) )
  1205.  
  1206. End Function
  1207.  
  1208. Function AK_DOWN ( ignore_focus% = 1 )
  1209.  
  1210. Return ( GDI_VKeyDown ( VK_A, ignore_focus% ) )
  1211.  
  1212. End Function
  1213.  
  1214. Function DK_DOWN ( ignore_focus% = 1 )
  1215.  
  1216. Return ( GDI_VKeyDown ( VK_D, ignore_focus% ) )
  1217.  
  1218. End Function
  1219.  
  1220. Function LM_DOWN ( ignore_focus% = 1 )
  1221.  
  1222. Return ( GDI_VKeyDown ( VK_LEFTMOUSE, ignore_focus% ) )
  1223.  
  1224. End Function
  1225.  
  1226. Function RM_DOWN ( ignore_focus% = 1 )
  1227.  
  1228. Return ( GDI_VKeyDown ( VK_RIGHTMOUSE, ignore_focus% ) )
  1229.  
  1230. End Function
  1231.  
  1232. Function W_UP ( ignore_focus% = 1 )
  1233.  
  1234. Return ( ( WK_DOWN ( ignore_focus% ) + ( UP_KDOWN ( ignore_focus% ) ) ) )
  1235.  
  1236. End Function
  1237.  
  1238. Function S_DOWN ( ignore_focus% = 1 )
  1239.  
  1240. Return ( ( SK_DOWN ( ignore_focus% ) + ( DOWN_KDOWN ( ignore_focus% ) ) ) )
  1241.  
  1242. End Function
  1243.  
  1244. Function A_LEFT ( ignore_focus% = 1 )
  1245.  
  1246. Return ( ( AK_DOWN ( ignore_focus% ) + ( LEFT_KDOWN ( ignore_focus% ) ) ) )
  1247.  
  1248. End Function
  1249.  
  1250. Function D_RIGHT ( ignore_focus% = 1 )
  1251.  
  1252. Return ( ( DK_DOWN ( ignore_focus% ) + ( RIGHT_KDOWN ( ignore_focus% ) ) ) )
  1253.  
  1254. End Function
  1255.  
  1256. ;======================================================================================
  1257. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1258. Function LoadSFX()
  1259. run = LoadSound ("sounds\gravel.wav")
  1260. wade = LoadSound ("sounds\water.wav")
  1261. SoundVolume run, 0
  1262. SoundVolume wade, 0
  1263. LoopSound run
  1264. LoopSound wade
  1265.  
  1266. runchannel = PlaySound (run)
  1267. wadechannel = PlaySound (wade)
  1268.  
  1269. ;------------------------------
  1270.  
  1271. shoot=LoadSound( "sounds\shoot.wav" )
  1272. SoundVolume shoot, .9
  1273.  
  1274. boom=LoadSound( "sounds\boom.wav" )
  1275. SoundVolume boom, .5
  1276.  
  1277. bark = LoadSound("sounds\bark.wav")
  1278. SoundVolume bark, .5
  1279. ; barkChannel = PlaySound (bark) ;barking sound is started.
  1280.  
  1281. uh=LoadSound( "sounds\Asthma_Sound.wav_10720.wav" )
  1282. SoundVolume uh, .9
  1283. End Function
  1284.  
  1285. Function LoadMusic(files$)
  1286.  
  1287. bgmusic = LoadSound (files$)
  1288. SoundVolume bgmusic,.5
  1289. LoopSound bgmusic
  1290. bgmusicChannel= PlaySound (bgmusic)
  1291.  
  1292. dangermusic = LoadSound ("Shadow Of The Beast - Aarbronsrevenge.mp3")
  1293. SoundVolume dangermusic,0
  1294. LoopSound dangermusic
  1295. dangermusicChannel= PlaySound(dangermusic)
  1296.  
  1297. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement