Advertisement
Guest User

MediPack Patch

a guest
Jan 11th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SeedRnd MilliSecs()
  2.  
  3. Include "UDPNetwork_lib.bb"
  4.  
  5. Global localID
  6. Global localName$ = "<Guy Fawkes>"
  7.  
  8. Global localPlayerMesh
  9.  
  10. Global hide_pointer
  11.  
  12. Global itemcollcnt
  13.  
  14. Global onground
  15.  
  16. Global all_scene_collisions_on         =     0
  17. Global player_scene_collisions_on      =     1
  18. Global player_player_collisions_on     =     1
  19. Global bullet_scene_collisions_on      =     1
  20. Global bullet_player_collisions_on     =     1
  21. Global player_item_collisions_on       =     1
  22.  
  23. Type player
  24.  
  25.     Field id
  26.  
  27.     Field name$
  28.    
  29.     Field life
  30.    
  31.     Field mesh
  32.    
  33.     Field nextX#,nextY#,nextZ#
  34.     Field previousX#,previousY#,previousZ#
  35.     Field nextYaw#
  36.     Field previousYaw#
  37.     Field nextTime#
  38.     Field previousTime#
  39.    
  40.     Field currentY#
  41.     Field velocityY#
  42.    
  43.     Field r,g,b
  44.  
  45.     Field health_factor
  46.     Field max_health_factor
  47.  
  48.     Field magic_factor
  49.     Field max_magic_factor
  50.  
  51.     Field bullet_factor
  52.     Field max_bullet_factor
  53.  
  54. End Type
  55.  
  56. Type item
  57.  
  58.     Field id
  59.  
  60.     Field xpos#
  61.     Field ypos#
  62.     Field zpos#
  63.    
  64.     Field itemcount
  65.  
  66.     Field r,g,b
  67.  
  68. End Type
  69.  
  70. Type bullet
  71.  
  72.     Field mesh
  73.     Field angle#
  74.     Field time
  75.     Field id ; id of player who fired
  76.  
  77. End Type
  78.  
  79. Global maxhealthpacks = 4
  80.  
  81. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  82. ; Camera code from jfk EO-11110, thanks
  83. Global bounce_cam=1 ;  smooth camera motion? (0/1)
  84. Global bounce_div#=40.0 ; the higher, the more sluggish the camera will follow. Recc: 3.0 to 20.0
  85. ; some globals used by ChaseCam
  86. Global old_x#,old_y#,old_z#
  87. ; desired distance between camera and player mesh
  88. Global x_dis#=7.0,y_dis#=1,z_dis#=7.0,y_dis_or#=y_dis#
  89. ;Player Collision Type
  90. Global type_player = 1
  91. ;Scene Collision Type
  92. Global type_scene = 2
  93. ;Bullet Collision Type
  94. Global type_bullet = 3
  95. ;Item Collision Type
  96. Global type_item = 4
  97. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  98.  
  99. api_ShowWindow ( SystemProperty$ ( "apphWnd" ), 1 )
  100.  
  101. ; network init ----------------------------------------;
  102. Global localMode = Net_StartInput() ; bring the library "console" to connect
  103.  
  104. If localMode = 1 Or localMode = 2 ; 1 means we are client, 2 means we are server
  105.  
  106.     If localMode = 1 Then AppTitle("Client : " + localName + " (port:" + net_port + ")")
  107.     If localMode = 2 Then AppTitle("Server : " + localName + " (port:" + net_port + ")")
  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. Else ; error
  117.     Net_StopNetwork()
  118.     RuntimeError("Failed to start game.")
  119. EndIf
  120. ;------------------------------------------------------;
  121.  
  122. Graphics3D 640,480,32,2
  123. SetBuffer BackBuffer()
  124.  
  125. api_ShowWindow ( SystemProperty$ ( "apphWnd" ), 1 )
  126.  
  127. CreateScene()
  128.  
  129. Global sky = CreateCube ( )
  130.  
  131. ScaleEntity sky, 15, 15, 15
  132.  
  133. EntityFX sky, 1
  134.  
  135. EntityColor sky, 102, 102, 255
  136.  
  137. EntityOrder sky, 1000
  138.  
  139. FlipMesh sky
  140.  
  141. Global camera = CreateCamera()
  142. CameraRange camera,0.1,10000.0
  143.  
  144. ; create our own local player
  145. localPlayerMesh = CreatePlayer(localID,localName)
  146. old_x = EntityX(localPlayerMesh):old_y = EntityY(localPlayerMesh):old_z = EntityZ(localPlayerMesh) ; update camera position
  147.  
  148. ; we send our color to the server
  149. p.player = Object.player(GetPlayer(localID))
  150. Net_SendMessage(3,p\r + "/" + p\g + "/" + p\b)
  151.  
  152. ; variables used to send our positions at a constant delay (saves bandwidth but makes a constant ping)
  153. Global updatePosition = MilliSecs()
  154. Global updateTick = 50
  155.  
  156. ; chat
  157. Global messageDisplayNumber = 10
  158. Global messageOffset
  159. Dim message$(messageDisplayNumber)
  160.  
  161. Global chatMode
  162. Global chatMessage$ = localName + ": "
  163. Global chatMillisecs = MilliSecs()
  164. Global chatCursor
  165.  
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  168. While Not KeyDown(1)
  169.  
  170.     If all_scene_collisions_on
  171.    
  172.         ;; ALL COLLISIONS
  173.  
  174.         player_scene_collisions_on      =     1
  175.         player_player_collisions_on     =     1
  176.         bullet_scene_collisions_on      =     1
  177.         bullet_player_collisions_on     =     1
  178.         player_item_collisions_on       =     1
  179.  
  180.     Else
  181.  
  182.         ;; FEW COLLISIONS
  183.  
  184.         If  player_scene_collisions_on Then Collisions type_player, type_scene, 2, 3 ; player to scene
  185.         If  player_player_collisions_on Then Collisions type_player, type_player, 1, 3 ; player to player
  186.         If  bullet_scene_collisions_on Then Collisions type_bullet, type_scene, 2, 1 ; bullet to scene
  187.         If  bullet_player_collisions_on Then Collisions type_bullet, type_player, 1, 1 ; bullet to player
  188.         If  player_item_collisions_on Then Collisions type_player, type_item, 1, 1  ; player to item
  189.  
  190.     EndIf
  191.  
  192.     ;; ALL the Collisions on at the SAME TIME
  193.     If all_scene_collisions_on
  194.  
  195.         Collisions type_player, type_scene, 2, 3 ; player to scene
  196.         Collisions type_player, type_player, 1, 3 ; player to player
  197.         Collisions type_bullet, type_scene, 2, 1 ; bullet to scene
  198.         Collisions type_bullet, type_player, 1, 1 ; bullet to player
  199.         Collisions type_player, type_item, 1, 1  ; player to item
  200.        
  201.     EndIf
  202.  
  203.     ; update our player
  204.     UpdateLocalPlayer()
  205.  
  206.     ; see the function, the interpolation variables are set properly here
  207.     UpdateNetwork()
  208.    
  209.     ; the interpolation is made in this function
  210.     UpdatePlayers()
  211.    
  212.     ; update the bullets... only the server check for player kill
  213.     UpdateBullets()
  214.  
  215.     UpdateItems()
  216.  
  217.     UpdateWorld()
  218.     RenderWorld()
  219.  
  220.         DrawPlayersNames()
  221.    
  222.             If KeyHit(28) And chatMode = 0 Then chatMode = 1 : FlushKeys()
  223.    
  224.             If chatMode = 1 Then UpdateChat()
  225.    
  226.         DrawMessages()
  227.  
  228.     Flip
  229.  
  230. Wend
  231.  
  232. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  233. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  234.  
  235. Net_StopNetwork()
  236.  
  237. End
  238.  
  239. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  240. Function Jump ( )
  241.  
  242.     For p.player = Each player
  243.  
  244.         ; check if player is on the ground
  245.         groundcoll = LinePick(EntityX(p\mesh),EntityY(p\mesh),EntityZ(p\mesh),0,-1.2,0)
  246.  
  247.         If PickedEntity()
  248.  
  249.             onground = 1
  250.  
  251.             ;Detect Ceiling
  252.             ceilingpicked = LinePick ( EntityX ( p\mesh ), EntityY ( p\mesh ), EntityZ ( p\mesh ), 0.0, 300.0, 0.0 )
  253.    
  254.             ;Stop Ceiling "Floating"
  255.             If ceilingpicked
  256.    
  257.                 p\velocityY = 0.0
  258.    
  259.             Else
  260.    
  261.                 p\velocityY = 0.5 ; set "inverse" of gravity velocity
  262.  
  263.             EndIf
  264.            
  265.         Else
  266.        
  267.             onground = 0
  268.    
  269.         EndIf
  270.        
  271.     Next
  272.  
  273. End Function
  274.  
  275. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  276. Function UpdateNetwork()
  277.  
  278.     ; update incoming packets (better check ALL incoming messages so use While Wend)
  279.     While Net_CheckMessage() ; will check for a new message and fill Net_MsgType, Net_MsgData$, Net_MsgFrom and Net_MsgTo variables so we can read it
  280.        
  281.         p.player = Object.player(GetPlayer(Net_MsgFrom)) ; get the player handle
  282.        
  283.         Select Net_MsgType ; check the type of message
  284.  
  285.             Case 1 ; chat message
  286.            
  287.                 NewMessage(Net_MsgData)
  288.                                    
  289.             Case 2 ; player position and angle, example of packing data into string
  290.                
  291.                 offset1 = Instr(Net_MsgData,"/",1)
  292.                 offset2 = Instr(Net_MsgData,"/",offset1+1)
  293.                 offset3 = Instr(Net_MsgData,"/",offset2+1)
  294.                                
  295.                 p\previousX = p\nextX
  296.                 p\previousY = p\nextY
  297.                 p\previousZ = p\nextZ
  298.                 p\previousYaw = p\nextYaw
  299.                
  300.                 p\nextX = Left(Net_MsgData,offset1-1)
  301.                 p\nextY = Mid(Net_MsgData,offset1+1,offset2-offset1-1)
  302.                 p\nextZ = Mid(Net_MsgData,offset2+1,offset3-offset2-1)
  303.                 p\nextYaw = Right(Net_MsgData,Len(Net_MsgData)-offset3)
  304.                                
  305.                 p\previousTime = p\nextTime
  306.                 p\nextTime = MilliSecs()
  307.                            
  308.             Case 3 ; update player colors
  309.                        
  310.                 offset1 = Instr(Net_MsgData,"/",1)
  311.                 offset2 = Instr(Net_MsgData,"/",offset1+1)
  312.                            
  313.                 p\r = Left(Net_MsgData,offset1-1)
  314.                 p\g = Mid(Net_MsgData,offset1+1,offset2-offset1-1)
  315.                 p\b = Right(Net_MsgData,Len(Net_MsgData)-offset2)
  316.                                
  317.                 EntityColor p\mesh,p\r,p\g,p\b
  318.                
  319.             Case 4 ; a player fired
  320.            
  321.                 CreateBullet(Net_MsgFrom)
  322.            
  323.             Case 5 ; a player lost some life
  324.            
  325.                 p\life = Net_MsgData
  326.            
  327.             Case 6 ; a player killed another one
  328.            
  329.                 k.player = Object.player(GetPlayer(Net_MsgData)) ; killed player ID in MsgData
  330.                 NewMessage(p\name + " killed " + k\name)
  331.                 ResetPlayer(k\id)
  332.  
  333.             Case 100 ; new player connected, OR the server tells us who is already connected so we can create players when joining the game
  334.                            
  335.                 If localMode = 2
  336.                     For p.player = Each player
  337.                         Net_SendMessage(2,p\nextX + "/" + p\nextY + "/" + p\nextZ + "/" + p\nextYaw,p\id,Net_MsgFrom)
  338.                         Net_SendMessage(3,p\r + "/" + p\g + "/" + p\b,p\id,Net_MsgFrom)
  339.                        
  340.                         Net_SendMessage(5,p\life,p\id,Net_MsgFrom)
  341.                     Next
  342.                 EndIf
  343.                
  344.                 NewMessage(Net_MsgData + " connected")
  345.                 CreatePlayer(Net_MsgFrom,Net_MsgData)
  346.                
  347.             Case 101 ; a player has quit
  348.                        
  349.                 For p.player = Each player
  350.                     If Net_MsgFrom = p\id
  351.                         NewMessage(p\name + " disconnected")
  352.                         FreeEntity p\mesh
  353.                         Delete p
  354.                     EndIf
  355.                 Next
  356.  
  357.             Case 102 ; host has changed
  358.  
  359.                 For p.player = Each player
  360.                     If Net_MsgFrom = p\id
  361.                         If p\id = localID
  362.                             AppTitle("Server : " + localName + " (port:" + net_port + ")")
  363.                             NewMessage("You are the new host")
  364.                             localMode = 2
  365.                         Else
  366.                             NewMessage(p\name + " is the new host")
  367.                         EndIf                    
  368.                     EndIf
  369.                 Next
  370.  
  371.         End Select
  372.  
  373.     Wend
  374.  
  375. End Function
  376.  
  377. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  378. Function UpdateLocalPlayer()
  379.  
  380.     ; update our player
  381.     p.player = Object.player(GetPlayer(localID)) ; get our player
  382.  
  383.         ; inputs
  384.         If chatmode = 0
  385.             If KeyDown(200) Or KeyDown(17) Then MoveEntity p\mesh,0,0,0.3
  386.             If KeyDown(208) Or KeyDown(31) Then MoveEntity p\mesh,0,0,-0.3
  387.             If KeyDown(203) Or KeyDown(30) Then TurnEntity p\mesh,0,3,0
  388.             If KeyDown(205) Or KeyDown(32) Then TurnEntity p\mesh,0,-3,0
  389.         EndIf
  390.        
  391.         ; fire
  392.         If MouseDown(1)
  393.             hide_pointer = 1
  394.             MoveMouse GraphicsWidth ( ) / 2, GraphicsHeight ( ) / 2
  395.             Net_SendMessage(4,"")
  396.             CreateBullet(localID)
  397.         Else
  398.             hide_pointer = 0
  399.         EndIf
  400.  
  401.         If hide_pointer <> 0 Then HidePointer ( )
  402.         If hide_pointer  = 0 Then ShowPointer ( )
  403.        
  404.         If Not ( KeyDown ( 29 ) Or KeyDown ( 157 ) )
  405.  
  406.             ; jump
  407.             If KeyHit(57) And chatmode = 0 Then Jump ( )
  408.  
  409.         Else
  410.  
  411.             ; spawn items
  412.             If KeyHit(57) And chatmode = 0
  413.  
  414.                 For x = 1 To maxhealthpacks
  415.  
  416.                     i.item = New item
  417.                     i\id = CreateCube()
  418.                     i\itemcount = ( maxhealthpacks )
  419.                     PositionEntity i\id, Rnd ( -25, 25 ), 1.001, ( Rnd ( -25, 25 ) )
  420.                     EntityPickMode i\id, 2
  421.                     EntityType i\id, type_item
  422.                     EntityRadius i\id, 1
  423.                     EntityColor i\id, 0, ( Rnd ( 64, 255 ) ), ( Rnd ( 64, 255 ) )
  424.                     EntityAlpha i\id, ( Rnd ( 0.25, 0.65 ) )
  425.            
  426.                 Next
  427.  
  428.             EndIf
  429.        
  430.         EndIf
  431.        
  432.         ; we create a message type "2" for player position
  433.         If MilliSecs()-updatePosition > updateTick    
  434.             Net_SendMessage(2,EntityX#(p\mesh, 1) + "/" + EntityY#(p\mesh, 1) + "/" + EntityZ#(p\mesh, 1) + "/" + EntityYaw#(p\mesh, 1))
  435.             updatePosition = MilliSecs()
  436.         EndIf
  437.  
  438.     UpdateChaseCam(camera,p\mesh)
  439.  
  440. End Function
  441.  
  442. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  443. Function UpdatePlayers()
  444.  
  445.     For p.player = Each player
  446.                
  447.         If p\id <> localID ; update other players
  448.        
  449.             ResetEntity p\mesh ; reset entity is useful here because of collisions
  450.        
  451.             ;; LINEAR INTERPOLATION ;;;;;;;;;;
  452.             curTime# = (MilliSecs()-p\nextTime) / (p\nextTime-p\previousTime) ; curTime will be ideally 0.0-1.0, if it's > 1.0 then it performs extrapolation
  453.             PositionEntity p\mesh,p\previousX+(p\nextX-p\previousX)*curTime,p\previousY+(p\nextY-p\previousY)*curTime,p\previousZ+(p\nextZ-p\previousZ)*curTime
  454.            
  455.             ; special fix for yaw as EntityYaw returns a value beetween +180 ans -180, the interpolation can go backward
  456.             If p\previousYaw < 0 Then p\previousYaw = p\previousYaw + 360
  457.             If p\nextYaw < 0 Then p\nextYaw = p\nextYaw + 360
  458.             If Abs(p\nextYaw-p\previousYaw) > 180
  459.                 If p\nextYaw > p\previousYaw
  460.                     p\previousYaw = p\previousYaw + 360
  461.                 Else
  462.                     p\previousYaw = p\previousYaw - 360
  463.                 EndIf
  464.             EndIf
  465.            
  466.             RotateEntity p\mesh,0,p\previousYaw+(p\nextYaw-p\previousYaw)*curTime,0
  467.             ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  468.  
  469.         Else ; update our player, basically it just compute gravity
  470.  
  471.             p\velocityY = p\velocityY - 0.003 ; fake gravity
  472.             If EntityY(p\mesh) - p\currentY >= 0 ; if player is not falling we limit the gravity
  473.                 If p\velocityY < -0.003 Then p\velocityY = -0.003
  474.             EndIf
  475.  
  476.             p\currentY = EntityY(p\mesh)
  477.             TranslateEntity p\mesh,0,p\velocityY,0
  478.  
  479.         EndIf
  480.        
  481.     Next
  482.  
  483. End Function
  484.  
  485. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  486. Function CreatePlayer(id,name$)
  487.  
  488.     p.player = New player
  489.     p\id = id
  490.     p\name = name
  491.    
  492.     p\life = 10
  493.    
  494.     p\mesh = CreateCube()
  495.     EntityType p\mesh,type_player
  496.     EntityRadius p\mesh,0.1
  497.  
  498.     ScaleEntity p\mesh, .1, .1, .1
  499.  
  500.     NameEntity p\mesh,Handle(p)
  501.    
  502.     nose = CreateSphere(8,p\mesh):EntityColor nose,255,0,0
  503.     PositionEntity nose,0,0,1
  504.     ScaleEntity nose,0.3, 0.3, 0.3
  505.    
  506.     p\nextX = -20
  507.     p\nextY = 1
  508.     p\nextZ = -20
  509.     p\nextYaw = -45
  510.    
  511.     p\previousX = p\nextX
  512.     p\previousY = p\nextY
  513.     p\previousZ = p\nextZ
  514.     p\previousYaw = p\nextYaw
  515.    
  516.     p\r = 0
  517.     p\g = Rand ( 64, 255 )
  518.     p\b = Rand ( 64, 255 )
  519.     EntityColor p\mesh,p\r,p\g,p\b
  520.    
  521.     PositionEntity p\mesh,p\nextX,p\nextY,p\nextZ
  522.     RotateEntity p\mesh,0,p\nextYaw,0
  523.     ResetEntity p\mesh
  524.    
  525.     p\currentY = p\nextY
  526.    
  527.     p\previousTime = MilliSecs()
  528.     p\nextTime = MilliSecs()+1
  529.  
  530.     Return p\mesh
  531.  
  532. End Function
  533.  
  534. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  535. Function ResetPlayer(id)
  536.  
  537.     p.player = Object.player(GetPlayer(id))
  538.  
  539.     p\life = 90
  540.  
  541.     p\nextX = -20
  542.     p\nextY = 1
  543.     p\nextZ = -20
  544.     p\nextYaw = -45
  545.  
  546.     p\previousX = p\nextX
  547.     p\previousY = p\nextY
  548.     p\previousZ = p\nextZ
  549.     p\previousYaw = p\nextYaw
  550.  
  551.     PositionEntity p\mesh,p\nextX,p\nextY,p\nextZ
  552.     RotateEntity p\mesh,0,p\nextYaw,0
  553.     ResetEntity p\mesh
  554.    
  555.     p\currentY = p\nextY
  556.    
  557.     p\previousTime = MilliSecs()
  558.     p\nextTime = MilliSecs()+1
  559.  
  560. End Function
  561.  
  562. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  563. Function GetPlayer(id)
  564.  
  565.     For p.player = Each player
  566.         If p\id = id
  567.             Return Handle(p)                    
  568.         EndIf
  569.     Next
  570.  
  571. End Function
  572.  
  573. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  574. Function GetItem(id)
  575.  
  576.     For i.item = Each item
  577.         If i\id = id
  578.             Return Handle(i)
  579.         EndIf
  580.     Next
  581.  
  582. End Function
  583.  
  584. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  585. Function DrawPlayersNames()
  586.  
  587.     For p.player = Each player
  588.    
  589.         Color 255,255,255
  590.         CameraProject(camera,EntityX(p\mesh),EntityY(p\mesh),EntityZ(p\mesh))            
  591.         If p\id <> localID Then Text ProjectedX(),ProjectedY()-60,p\name,1,1
  592.        
  593.         Color 255,(255.0/100.0)*p\life,(255.0/100.0)*p\life
  594.         Text ProjectedX(),ProjectedY()-40,p\life,1,1
  595.  
  596.     Next
  597.    
  598. End Function
  599.  
  600. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  601. Function CreateBullet(id)
  602.  
  603.     p.player = Object.player(GetPlayer(id))
  604.  
  605.     b.bullet = New bullet
  606.    
  607.     b\id = p\id
  608.    
  609.     b\mesh = CreateSphere(2)
  610.     ScaleEntity b\mesh,0.2,0.2,0.2
  611.     EntityColor b\mesh,255,0,0
  612.        
  613.     PositionEntity b\mesh,EntityX(p\mesh),EntityY(p\mesh),EntityZ(p\mesh)
  614.     RotateEntity b\mesh,0,EntityYaw(p\mesh),0
  615.  
  616.     EntityType b\mesh,type_bullet
  617.     EntityRadius b\mesh,0.2
  618.        
  619.     b\time = MilliSecs()
  620.  
  621. End Function
  622.  
  623. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  624. Function UpdateBullets()
  625.  
  626.     For b.bullet = Each bullet
  627.    
  628.         MoveEntity b\mesh,0,0,1
  629.        
  630.         If CountCollisions(b\mesh)
  631.        
  632.             If localMode = 2 ; only the server compute bullets collision with player
  633.                 If GetEntityType(CollisionEntity(b\mesh,1)) = type_player ; a player is hit
  634.                
  635.                     touchedPlayer.player = Object.player(EntityName(CollisionEntity(b\mesh,1)))
  636.                     touchedPlayer\life = touchedPlayer\life - 10
  637.                    
  638.                     If touchedPlayer\life > 0 ; touched
  639.                         Net_SendMessage(5,touchedPlayer\life,touchedPlayer\id)
  640.                         Net_SendMessage(5,touchedPlayer\life,touchedPlayer\id,touchedPlayer\id)
  641.                     Else ; killed
  642.                         killerPlayer.player = Object.player(GetPlayer(b\id))
  643.                         Net_SendMessage(6,touchedPlayer\id,killerPlayer\id)
  644.                         Net_SendMessage(6,touchedPlayer\id,killerPlayer\id,killerPlayer\id)
  645.                         NewMessage(killerPlayer\name + " killed " + touchedPlayer\name)
  646.                         ResetPlayer(touchedPlayer\id)
  647.                     EndIf
  648.                
  649.                 EndIf
  650.             EndIf
  651.            
  652.             FreeEntity b\mesh
  653.             Delete b
  654.            
  655.         ElseIf MilliSecs()-b\time > 2000
  656.        
  657.             FreeEntity b\mesh
  658.             Delete b
  659.            
  660.         EndIf
  661.    
  662.     Next
  663.  
  664. End Function
  665.  
  666. Function UpdateItems ( )
  667.  
  668.     ;For every Player in the Scene
  669.     For p.player = Each player
  670.  
  671.         ;For every Item in the Scene
  672.         For i.item = Each item
  673.  
  674.             TurnEntity i\id, 0, -1.0, 0
  675.  
  676.             ;Is Item Collision on ?
  677.             If player_item_collisions_on
  678.  
  679.                 ;How many times did the Player hit an Item ?
  680.                 itemcollcnt = CountCollisions ( i\id )
  681.  
  682.                 ;Count the amount of collisions between an item
  683.                 For collcnt = 1 To itemcollcnt
  684.  
  685.                     ;Get Collision between Player & Item
  686.                     healthpackcoll = CollisionEntity ( p\mesh, itemcollcnt )
  687.  
  688.                     ;If there was a collision between Player & Item
  689.                     If GetEntityType ( healthpackcoll ) = type_item
  690.  
  691.                         ;Get the Touched Item
  692.                         ;touchedItem.item = Object.item(GetItem(i\id))
  693.                            
  694.                         ; If the Player already has Max Health
  695.                         If p\life < 90
  696.                            
  697.                             ; Raise the Player's Health by a Factor
  698.                             p\life = p\life + 10
  699.                        
  700.                                 ; Delete the touched Object from Game
  701.                                 FreeEntity i\id
  702.                                                
  703.                             ; Remove each touched Item from Memory
  704.                             Delete i
  705.                                                    
  706.                         ; Otherwise
  707.                         Else
  708.                        
  709.                             ; Do not let the Player get any more Health
  710.                             p\life = 90
  711.    
  712.                                 ; Delete the touched Object from Game
  713.                                 FreeEntity i\id
  714.                        
  715.                             ; Remove each touched Item from Memory
  716.                             Delete i
  717.                                
  718.                         EndIf
  719.                            
  720.                     EndIf
  721.                    
  722.                 Next
  723.                
  724.             Else
  725.  
  726.                 ; Shoot a pick Line from the player straight to Item
  727.                 itempicked = LinePick ( EntityX# ( p\mesh, 1 ), EntityY# ( p\mesh, 1 ), EntityZ# ( p\mesh, 1 ), 0.0, 0.0, 1.0 )
  728.  
  729.                 ; If the Player is within the vicinity of an Item, or the Player "sees" the Item
  730.                 If EntityDistance ( p\mesh, i\id ) <= 2.0 Or ( EntityDistance ( p\mesh, i\id ) <= 2.0 And itempicked ) Or ( EntityDistance ( p\mesh, i\id ) <= 2.0 And EntityInView ( i\id, camera ) )
  731.  
  732.                     ; If the Player already has Max Health
  733.                     If p\life < 90
  734.                            
  735.                         ; Raise the Player's Health by a Factor
  736.                         p\life = p\life + 10
  737.                                
  738.                             ; Delete the touched Object from Game
  739.                             ;FreeEntity i\id
  740.                        
  741.                         ; Remove Each touched Item from Memory
  742.                         ;Delete i
  743.    
  744.                     ; Otherwise
  745.                     Else
  746.                                                
  747.                         ; Don't give the Player anymore Health
  748.                         p\life = 90
  749.                                
  750.                             ; Delete the touched Object from Game
  751.                             FreeEntity i\id
  752.                        
  753.                         ; Remove Each touched Item from Memory
  754.                         Delete i
  755.                                
  756.                     EndIf
  757.                                    
  758.                 EndIf
  759.  
  760.             EndIf
  761.  
  762.         Next
  763.  
  764.         PositionEntity sky, EntityX# ( p\mesh, 1 ), EntityY# ( p\mesh, 1 ), EntityZ# ( p\mesh, 1 ), 1
  765.    
  766.     Next
  767.  
  768. End Function
  769.  
  770. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  771. Function NewMessage(msg$)
  772.  
  773.     messageOffset = messageOffset + 1
  774.    
  775.     If messageOffset > messageDisplayNumber
  776.    
  777.         messageOffset = messageOffset - 1
  778.        
  779.         For i = 2 To messageDisplayNumber
  780.             message(i-1) = message(i)        
  781.         Next
  782.        
  783.         message(messageDisplayNumber) = msg
  784.    
  785.     Else
  786.    
  787.         message(messageOffset) = msg
  788.    
  789.     EndIf
  790.  
  791. End Function
  792.  
  793. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  794. Function DrawMessages()
  795.  
  796.     Color 255,255,255
  797.  
  798.     For i1 = 1 To messageOffset
  799.    
  800.         Text 0,(i1-1)*15,message(i1)    
  801.  
  802.     Next
  803.    
  804. End Function
  805.  
  806. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  807. Function UpdateChat()
  808.  
  809.     key = GetKey()
  810.  
  811.     If key
  812.         If key = 13
  813.             If chatMessage <> localName + ": "
  814.                 For i = Len(localName + ": ") To Len(chatMessage)
  815.                     If Mid(chatMessage,i,1) <> " "
  816.                         Net_SendMessage(1,chatMessage)
  817.                         NewMessage(chatMessage)
  818.                         Exit
  819.                     EndIf
  820.                 Next
  821.             EndIf
  822.             chatMessage = localName + ": "
  823.             chatMode = 0
  824.         ElseIf key = 8 And Len(chatMessage) > Len ( localName + ": " )
  825.             chatMessage = Left(chatMessage,Len(chatMessage)-1)
  826.         ElseIf key > 31 And key < 127
  827.             chatMessage = chatMessage + Chr(key)
  828.         EndIf
  829.     EndIf
  830.    
  831.     Color 255,255,255
  832.     Rect 0,GraphicsHeight()-20,GraphicsWidth(),20,1
  833.    
  834.     Color 0,0,0
  835.     Rect 0,GraphicsHeight()-20,GraphicsWidth(),20,0
  836.    
  837.    
  838.     If MilliSecs()-chatMillisecs > 500
  839.         chatCursor = Not chatCursor
  840.         chatMillisecs = MilliSecs()
  841.     EndIf
  842.    
  843.     If chatCursor
  844.         Text 5,GraphicsHeight()-17,chatMessage + "|"
  845.     Else
  846.         Text 5,GraphicsHeight()-17,chatMessage
  847.     EndIf
  848.  
  849. End Function
  850.  
  851. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  852. Function UpdateChaseCam(camera,player) ; thanks to jfk EO-11110 on bb forums for this function !
  853.     PositionEntity camera,EntityX(player,1),EntityY(player,1),EntityZ(player,1)
  854.     ResetEntity camera
  855.     x#=EntityX(player)+Sin(-EntityYaw(player)+180)*x_dis#
  856.     y#=EntityY(player)+y_dis#
  857.     z#=EntityZ(player)+Cos(-EntityYaw(player)+180)*z_dis#
  858.     obstacle=LinePick(EntityX(player),EntityY(player),EntityZ(player),(x-EntityX(player)),y_dis#,(z-EntityZ(player)),0.1)
  859.     If obstacle=0
  860.         new_x#=x
  861.         new_y#=y
  862.         new_z#=z
  863.     Else
  864.         new_x#=PickedX()
  865.         new_y#=PickedY()
  866.         new_z#=PickedZ()
  867.     EndIf
  868.     If bounce_cam=0
  869.         PositionEntity camera,new_x,new_y,new_z
  870.     Else
  871.         x=old_x+((New_x-old_x)/bounce_div#)
  872.         y=old_y+((New_y-old_y)/bounce_div#)
  873.         z=old_z+((New_z-old_z)/bounce_div#)
  874.         PositionEntity camera,x,y,z
  875.     EndIf
  876.     PointEntity camera,player
  877.     TurnEntity camera,-20,0,0     ; if you want the player mesh more on the bottom of the screen
  878.     old_x#=EntityX(camera)
  879.     old_y#=EntityY(camera)
  880.     old_z#=EntityZ(camera)
  881. End Function
  882.  
  883. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  884. Function CreateScene()
  885.  
  886.     texture = TextureCreate(128)
  887.    
  888.     ground = CreatePlane()
  889.     EntityColor ground,150,150,150
  890.     EntityTexture ground,texture
  891.    
  892.     cube = CreateCube():EntityColor cube,150,200,150
  893.     ScaleEntity cube,5,5,5:PositionEntity cube,0,5,0
  894.     EntityTexture cube,texture
  895.    
  896.     sphere = CreateSphere(16):EntityColor sphere,200,150,150
  897.     ScaleEntity sphere,3,1,3:PositionEntity sphere,0,9.7,0
  898.    
  899.     platform = CreateCube():EntityColor platform,150,150,200
  900.     ScaleEntity platform,3,1,10:PositionEntity platform,0,4.13,-13.15
  901.     TurnEntity platform,-30,0,0
  902.     EntityTexture platform,texture
  903.  
  904.     FreeTexture texture
  905.    
  906.     EntityType ground,type_scene:EntityPickMode ground,2
  907.     EntityType cube,type_scene:EntityPickMode cube,2
  908.     EntityType sphere,type_scene:EntityPickMode sphere,2
  909.     EntityType platform,type_scene:EntityPickMode platform,2
  910.  
  911.     light = CreateLight()
  912.     TurnEntity light,30,70,0
  913.  
  914.     For x = 0 To maxhealthpacks
  915.  
  916.         i.item = New item
  917.         i\id = CreateCube()
  918.         i\itemcount = ( maxhealthpacks + 1 )
  919.         PositionEntity i\id, Rnd ( -25, 25 ), 1.001, ( Rnd ( -25, 25 ) )
  920.         EntityPickMode i\id, 2
  921.         EntityType i\id, type_item
  922.         EntityRadius i\id, 1
  923.         EntityColor i\id, 0, ( Rnd ( 64, 255 ) ), ( Rnd ( 64, 255 ) )
  924.         EntityAlpha i\id, ( Rnd ( 0.25, 0.65 ) )
  925.  
  926.     Next
  927.  
  928. End Function
  929.  
  930. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  931. Function TextureCreate(size)
  932.     texture = CreateTexture(size,size,9)
  933.     SetBuffer TextureBuffer(texture)
  934.     Color 255,255,255
  935.     Rect 0,0,size,size,1
  936.     Color 0,0,0
  937.     Rect 0,0,size,size,0
  938.     Line 0,0,size,size
  939.     Line 0,size,size,0
  940.     SetBuffer BackBuffer()
  941.     Return texture
  942. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement