All pastes #802920 Raw Edit

Anonymous

public text v1 · immutable
#802920 ·published 2007-11-30 19:12 UTC
rendered paste body
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$(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
            Player(PlayerSelect).X = NewXValue(Player(PlayerSelect).X,CameraY#,.1)
            Player(PlayerSelect).Z = NewZValue(Player(PlayerSelect).Z,CameraY#,.1)
        EndIf
        If DownKey() = 1
            Player(PlayerSelect).X = NewXValue(Player(PlayerSelect).X,CameraY#,-.1)
            Player(PlayerSelect).Z = NewZValue(Player(PlayerSelect).Z,CameraY#,-.1)
        EndIf
        If LeftKey() = 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
            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
        Player(PlayerSelect).GridX = Int((Player(PlayerSelect).X + 0.5))
        Player(PlayerSelect).GridY = Int((Player(PlayerSelect).Y + 0.5))
        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 Check For Collision
        CheckCollision()

        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())

        Rotate Camera CameraX#,CameraY#,0
        Position Camera Player(PlayerSelect).X,Player(PlayerSelect).Y,Player(PlayerSelect).Z
        `Position Camera Player(PlayerSelect).X,Player(PlayerSelect).Y+10,Player(PlayerSelect).Z-5


        REM Debug
        `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).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 CheckCollision()
    REM If Ran Into A Wall ( Cube ) Reset Old Position
    If Val(Mid$(Level$(Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX)) = 1
        Player(PlayerSelect).X = Player(PlayerSelect).OldX
        Player(PlayerSelect).Y = Player(PlayerSelect).OldY
        Player(PlayerSelect).Z = Player(PlayerSelect).OldZ
    EndIf
    If Val(Mid$(Level$(Player(PlayerSelect).GridZ),Player(PlayerSelect).GridX)) = 5
        Player(PlayerSelect).Y = Player(PlayerSelect).OldY + 1
    Else
        Player(PlayerSelect).Y = Player(PlayerSelect).OldY - 1
    EndIf
    If Player(PlayerSelect).Y > 1.0 Then Player(PlayerSelect).Y = 1.0
    If Player(PlayerSelect).Y < 0.0 Then Player(PlayerSelect).Y = 0.0
EndFunction


Function MakePlayers()
    For PlayerCount = 0 To 2
        Player(PlayerCount).ObjNum = PlayerCount + 1
        Player(PlayerCount).Jump = 0.05
        Player(PlayerCount).JumpMax = 20
        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$(9) = "1111111111"
    Level$(8) = "1500000001"
    Level$(7) = "1010000101"
    Level$(6) = "1000200001"
    Level$(5) = "1000000401"
    Level$(4) = "1000000001"
    Level$(3) = "1001000001"
    Level$(2) = "1010030101"
    Level$(1) = "1000000001"
    Level$(0) = "1111111111"

    REM Start Level Objects At 100
    ObjNum = 100
    For z = 0 To 9
        For x = 1 To 10

            REM Parse Level Data
            TempVal = Val(Mid$(Level$(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,-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,0,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,-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,-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,-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,-0.4,z
                ObjNum = ObjNum + 1
                Make Object Box ObjNum,1,0.2,0.8
                Position Object ObjNum,x,-0.2,z+0.1
                ObjNum = ObjNum + 1
                Make Object Box ObjNum,1,0.2,0.6
                Position Object ObjNum,x,0,z+0.2
                ObjNum = ObjNum + 1
                Make Object Box ObjNum,1,0.2,0.4
                Position Object ObjNum,x,0.2,z+0.3
                ObjNum = ObjNum + 1
                Make Object Box ObjNum,1,0.2,0.2
                Position Object ObjNum,x,0.4,z+0.4
            EndIf

            REM Increase Object Count
            ObjNum = ObjNum + 1

        Next x
    Next z
EndFunction