Sync On Sync Rate 0 REM Variables Type PlayerType OldX As Float OldY As Float OldZ As Float X As Float Y As Float Z As Float GridX As Integer GridY As Integer GridZ As Integer Jump As Float JumpCount As Integer JumpFlag As Integer JumpMax As Integer ObjNum As Integer EndType REM Current Player Global PlayerSelect As Integer = 0 REM Make Array For 3 Players Dim Player(2) As PlayerType REM Create Array To Hold Level Data Dim Level$(1,9) REM Create Objects MakePlayers() MakeLevel() REM Position Camera `Position Camera 6,50,0 Set Camera Range 0.005,100 Point Camera 6,0,5 REM TimerSync Variables TimerStart = Timer() TimerDelay = 20 REM Main Loop Do REM TimerSync If Timer() >= TimerStart + TimerDelay REM Save Current Coordinates Player(PlayerSelect).OldX = Player(PlayerSelect).X Player(PlayerSelect).OldY = Player(PlayerSelect).Y Player(PlayerSelect).OldZ = Player(PlayerSelect).Z REM Press 1 For Player 1 If KeyState(2) = 1 Then PlayerSelect = 0 REM Press 2 For Player 2 If KeyState(3) = 1 Then PlayerSelect = 1 REM Press 3 For Player 3 If KeyState(4) = 1 Then PlayerSelect = 2 REM Move Player If UpKey() = 1 Or KeyState(17) = 1 Player(PlayerSelect).X = NewXValue(Player(PlayerSelect).X,CameraY#,.1) Player(PlayerSelect).Z = NewZValue(Player(PlayerSelect).Z,CameraY#,.1) EndIf If DownKey() = 1 Or KeyState(31) = 1 Player(PlayerSelect).X = NewXValue(Player(PlayerSelect).X,CameraY#,-.1) Player(PlayerSelect).Z = NewZValue(Player(PlayerSelect).Z,CameraY#,-.1) EndIf If LeftKey() = 1 Or KeyState(30) = 1 Player(PlayerSelect).X = NewXValue(Player(PlayerSelect).X,CameraY#-90.0,.1) Player(PlayerSelect).Z = NewZValue(Player(PlayerSelect).Z,CameraY#-90.0,.1) EndIf If RightKey() = 1 Or KeyState(32) = 1 Player(PlayerSelect).X = NewXValue(Player(PlayerSelect).X,CameraY#+90.0,.1) Player(PlayerSelect).Z = NewZValue(Player(PlayerSelect).Z,CameraY#+90.0,.1) EndIf REM Update Position On Grid And Check For Sliding Collision REM Update Grid Then Check For Collision Along X Axis Then Update Again Player(PlayerSelect).GridX = Int((Player(PlayerSelect).X + 0.5)) CheckCollisionX() Player(PlayerSelect).GridX = Int((Player(PlayerSelect).X + 0.5)) REM Update Grid Then Check For Collision Along Y Axis Then Update Again Player(PlayerSelect).GridY = Int((Player(PlayerSelect).Y + 0.5)) CheckCollisionY() Player(PlayerSelect).GridY = Int((Player(PlayerSelect).Y + 0.5)) REM Update Grid Then Check For Collision Along Z Axis Then Update Again Player(PlayerSelect).GridZ = Int((Player(PlayerSelect).Z + 0.5)) CheckCollisionZ() Player(PlayerSelect).GridZ = Int((Player(PlayerSelect).Z + 0.5)) REM Jump If Player(PlayerSelect).JumpCount = 0 Then Player(PlayerSelect).JumpFlag = 0 If SpaceKey() = 1 And Player(PlayerSelect).JumpFlag = 0 Then Player(PlayerSelect).JumpFlag = 1 If Player(PlayerSelect).JumpFlag = 2 Then Player(PlayerSelect).JumpCount = Player(PlayerSelect).JumpCount - 1 If Player(PlayerSelect).JumpFlag = 1 Then Player(PlayerSelect).JumpCount = Player(PlayerSelect).JumpCount + 1 If Player(PlayerSelect).JumpCount = Player(PlayerSelect).JumpMax Then Player(PlayerSelect).JumpFlag = 2 REM Position Player Object Position Object Player(PlayerSelect).ObjNum,Player(PlayerSelect).X,Player(PlayerSelect).Y + (Player(PlayerSelect).Jump * Player(PlayerSelect).JumpCount),Player(PlayerSelect).Z REM First Person Controls CameraX# = WrapValue(CameraX# + MouseMoveY()) CameraY# = WrapValue(CameraY# + MouseMoveX()) `If CameraX# < 270.0 Then CameraX# = 270.0 `If CameraX# < -90.0 Then CameraX# = -90.0 Rotate Camera CameraX#,CameraY#,0 `Position Camera Player(PlayerSelect).X,Player(PlayerSelect).Y + (Player(PlayerSelect).Jump * Player(PlayerSelect).JumpCount),Player(PlayerSelect).Z Position Camera Player(PlayerSelect).X,Player(PlayerSelect).Y+10,Player(PlayerSelect).Z-5 REM Debug Text 0,50,Str$(Player(PlayerSelect).Z) + " : " + Str$(Player(PlayerSelect).GridZ) `Text 0,80,Mid$(Level$(Player(PlayerSelect).GridZ + 1),Player(PlayerSelect).GridX - 1) `Text 30,80,Mid$(Level$(Player(PlayerSelect).GridZ + 1),Player(PlayerSelect).GridX) `Text 60,80,Mid$(Level$(Player(PlayerSelect).GridZ + 1),Player(PlayerSelect).GridX + 1) `Text 0,110,Mid$(Level$(Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX - 1) Text 30,110,Mid$(Level$(Player(PlayerSelect).GridY,Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX) `Text 60,110,Mid$(Level$(Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX + 1) `Text 0,140,Mid$(Level$(Player(PlayerSelect).GridZ - 1),Player(PlayerSelect).GridX - 1) `Text 30,140,Mid$(Level$(Player(PlayerSelect).GridZ - 1),Player(PlayerSelect).GridX) `Text 60,140,Mid$(Level$(Player(PlayerSelect).GridZ - 1),Player(PlayerSelect).GridX + 1) REM Reset Timer Values TimerStart = Timer() EndIf Sync Loop Function CheckCollisionX() REM If Ran Into A Wall On X Axis ( Cube ) Reset Old X Position If Val(Mid$(Level$(Player(PlayerSelect).GridY,Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX)) = 1 Player(PlayerSelect).X = Player(PlayerSelect).OldX EndIf EndFunction Function CheckCollisionY() REM Gravity Player(PlayerSelect).OldY = Player(PlayerSelect).OldY - 1 Player(PlayerSelect).Y = Player(PlayerSelect).Y - 1 REM Make Sure You Don't Fall Through The Floor If Player(PlayerSelect).OldY < 0.0 Then Player(PlayerSelect).OldY = 0.0 If Player(PlayerSelect).Y < 0.0 Then Player(PlayerSelect).Y = 0.0 REM Check Collision With Stairs If Val(Mid$(Level$(Player(PlayerSelect).GridY,Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX)) = 5 If Player(PlayerSelect).Z > Player(PlayerSelect).GridZ - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).Z > (Player(PlayerSelect).GridZ + 0.2) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).Z > (Player(PlayerSelect).GridZ + 0.4) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).Z > (Player(PlayerSelect).GridZ + 0.6) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).Z > (Player(PlayerSelect).GridZ + 0.8) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf EndIf If Val(Mid$(Level$(Player(PlayerSelect).GridY,Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX)) = 6 If Player(PlayerSelect).X > Player(PlayerSelect).GridX - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).X > (Player(PlayerSelect).GridX + 0.2) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).X > (Player(PlayerSelect).GridX + 0.4) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).X > (Player(PlayerSelect).GridX + 0.6) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf If Player(PlayerSelect).X > (Player(PlayerSelect).GridX + 0.8) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf EndIf If Val(Mid$(Level$(Player(PlayerSelect).GridY,Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX)) = 8 If Player(PlayerSelect).Z > Player(PlayerSelect).GridZ - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 If Player(PlayerSelect).Z > (Player(PlayerSelect).GridZ + 1.0) - 0.5 Player(PlayerSelect).Y = Player(PlayerSelect).Y + 0.2 EndIf EndIf endif REM Make Sure You Don't Go Through The Ceiling If Player(PlayerSelect).OldY > 0.0 Then Player(PlayerSelect).OldY = 0.6 If Player(PlayerSelect).Y > 0.0 Then Player(PlayerSelect).Y = 0.6 EndFunction Function CheckCollisionZ() REM If Ran Into A Wall On Z Axis ( Cube ) Reset Old Z Position If Val(Mid$(Level$(Player(PlayerSelect).GridY,Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX)) = 1 Player(PlayerSelect).Z = Player(PlayerSelect).OldZ EndIf EndFunction Function MakePlayers() REM Create Spheres For Players For PlayerCount = 0 To 2 Player(PlayerCount).ObjNum = PlayerCount + 1 Player(PlayerCount).Jump = 0.05 Player(PlayerCount).JumpMax = 40 Player(PlayerCount).JumpFlag = 0 Player(PlayerCount).JumpCount = 0 Make Object Sphere Player(PlayerCount).ObjNum,1 Next PlayerCount EndFunction Function MakeLevel() REM Store Level Data For Level Creation And Collision REM 1 = Walls : 0 = Floor : 2 = Player(0) Start Position : 3 = Player(1) Start Position Level$(0,9) = "1111111111" Level$(0,8) = "1500000001" Level$(0,7) = "1010000101" Level$(0,6) = "1000200061" Level$(0,5) = "1000000401" Level$(0,4) = "1000000001" Level$(0,3) = "1001000061" Level$(0,2) = "1010030101" Level$(0,1) = "1000000001" Level$(0,0) = "1111111111" REM 7 Is Empty Space : 8 Is Floor Tile Level$(1,9) = "1111111111" Level$(1,8) = "1788888881" Level$(1,7) = "1777787771" Level$(1,6) = "1777787771" Level$(1,5) = "1777777771" Level$(1,4) = "1777777771" Level$(1,3) = "1777777771" Level$(1,2) = "1777777771" Level$(1,1) = "1777777771" Level$(1,0) = "1111111111" REM Start Level Objects At 100 ObjNum = 100 For y = 0 To 1 For z = 0 To 9 For x = 1 To 10 REM Parse Level Data TempVal = Val(Mid$(Level$(y,z),x)) REM If Level Data Is 0 Make A Floor Tile If TempVal = 0 Make Object Plain ObjNum,1,1 Rotate Object ObjNum,90,0,0 Position Object ObjNum,x,y-0.5,z EndIf REM If Level Data Is 1 Make A Wall ( Cube ) If TempVal = 1 Make Object Cube ObjNum,1 Position Object ObjNum,x,y,z EndIf REM If Level Data Is 2 Make A Floor Tile And Set Start Position For Player(0) If TempVal = 2 Make Object Plain ObjNum,1,1 Rotate Object ObjNum,90,0,0 Position Object ObjNum,x,y-0.5,z Player(0).X = x Player(0).Y = y Player(0).Z = z Player(0).GridX = x Player(0).GridY = 0 Player(0).GridZ = z Position Object Player(0).ObjNum,Player(0).X,Player(0).Y,Player(0).Z EndIf REM If Level Data Is 2 Make A Floor Tile And Set Start Position For Player(1) If TempVal = 3 Make Object Plain ObjNum,1,1 Rotate Object ObjNum,90,0,0 Position Object ObjNum,x,y-0.5,z Player(1).X = x Player(1).Y = y Player(1).Z = z Player(1).GridX = x Player(1).GridY = 0 Player(1).GridZ = z Position Object Player(1).ObjNum,Player(1).X,Player(1).Y,Player(1).Z EndIf `4 is player 3 If TempVal = 4 Make Object Plain ObjNum,1,1 Rotate Object ObjNum,90,0,0 Position Object ObjNum,x,y-0.5,z Player(2).X = x Player(2).Y = y Player(2).Z = z Player(2).GridX = x Player(2).GridY = 0 Player(2).GridZ = z Position Object Player(2).ObjNum,Player(2).X,Player(2).Y,Player(2).Z EndIf REM Make stairs If TempVal = 5 Make Object Box ObjNum,1,0.2,1 Position Object ObjNum,x,y-0.4,z ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.8 Position Object ObjNum,x,y-0.2,z+0.1 ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.6 Position Object ObjNum,x,y,z+0.2 ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.4 Position Object ObjNum,x,y+0.2,z+0.3 ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.2 Position Object ObjNum,x,y+0.4,z+0.4 EndIf If TempVal = 6 Make Object Box ObjNum,1,0.2,1 rotate object ObjNum,0,90,0 Position Object ObjNum,x,y-0.4,z ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.8 rotate object ObjNum,0,90,0 Position Object ObjNum,x+0.1,y-0.2,z ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.6 rotate object ObjNum,0,90,0 Position Object ObjNum,x+0.2,y,z ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.4 rotate object ObjNum,0,90,0 Position Object ObjNum,x+0.3,y+0.2,z ObjNum = ObjNum + 1 Make Object Box ObjNum,1,0.2,0.2 rotate object ObjNum,0,90,0 Position Object ObjNum,x+0.4,y+0.4,z ObjNum = ObjNum + 1 EndIf REM If Level Data Is 0 Make A Floor Tile If TempVal = 8 Make Object Plain ObjNum,1,1 Rotate Object ObjNum,270,0,0 Color Object ObjNum,RGB(255,0,0) Position Object ObjNum,x,y-0.6,z EndIf REM Increase Object Count ObjNum = ObjNum + 1 Next x Next z Next y EndFunction