Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mirage Source 4
Trimmed PlayerMove sub.

There is probably more, actually I know there is more that can be done to it, but I was sort of rushed. It's mostly done though.

Code:
Sub PlayerMove(ByVal Index As Long, ByVal Dir As Long, ByVal Movement As Long)
Dim Packet As String
Dim MapNum As Long
Dim x As Long
Dim y As Long
Dim PlayerX As Long, PlayerY As Long
Dim Moved As Byte

    ' Check for subscript out of range
    If IsPlaying(Index) = False Or Dir < DIR_UP Or Dir > DIR_RIGHT Or Movement < 1 Or Movement > 2 Then
        Exit Sub
    End If
    
    Call SetPlayerDir(Index, Dir)
    
    Moved = NO
    
    Select Case Dir
        Case DIR_UP
            If GetPlayerY(Index) > 0 Then
                PlayerX = GetPlayerX(Index)
                PlayerY = GetPlayerY(Index) - 1
            Else
                If Map(GetPlayerMap(Index)).Up > 0 Then
                    Call PlayerWarp(Index, Map(GetPlayerMap(Index)).Up, GetPlayerX(Index), MAX_MAPY)
                    Moved = YES
                End If
            End If
        Case DIR_DOWN
            If GetPlayerY(Index) < MAX_MAPY Then
                PlayerX = GetPlayerX(Index)
                PlayerY = GetPlayerY(Index) + 1
            Else
                If Map(GetPlayerMap(Index)).Down > 0 Then
                    Call PlayerWarp(Index, Map(GetPlayerMap(Index)).Down, GetPlayerX(Index), 0)
                    Moved = YES
                End If
            End If
        Case DIR_LEFT
            If GetPlayerX(Index) > 0 Then
                PlayerX = GetPlayerX(Index) - 1
                PlayerY = GetPlayerY(Index)
             Else
                If Map(GetPlayerMap(Index)).Left > 0 Then
                    Call PlayerWarp(Index, Map(GetPlayerMap(Index)).Left, MAX_MAPX, GetPlayerY(Index))
                    Moved = YES
                End If
            End If
        Case DIR_RIGHT
            If GetPlayerX(Index) > MAX_MAPX Then
                PlayerX = GetPlayerX(Index) + 1
                PlayerY = GetPlayerY(Index)
            Else
                If Map(GetPlayerMap(Index)).Right > 0 Then
                    Call PlayerWarp(Index, Map(GetPlayerMap(Index)).Right, 0, GetPlayerY(Index))
                    Moved = YES
                End If
            End If
    End Select

        If Map(GetPlayerMap(Index)).Tile(PlayerX, PlayerY).Type  TILE_TYPE_BLOCKED Then
            ' Check to see if the tile is a key and if it is check if its opened
            If Map(GetPlayerMap(Index)).Tile(PlayerX, PlayerY).Type  TILE_TYPE_KEY Or (Map(GetPlayerMap(Index)).Tile(PlayerX, PlayerY).Type = TILE_TYPE_KEY And TempTile(GetPlayerMap(Index)).DoorOpen(PlayerX, PlayerY) = YES) Then
                Call SetPlayerY(Index, PlayerY)
                
                Packet = SPlayerMove & SEP_CHAR & Index & SEP_CHAR & PlayerX & SEP_CHAR & PlayerY & SEP_CHAR & GetPlayerDir(Index) & SEP_CHAR & Movement & END_CHAR
                Call SendDataToMapBut(Index, GetPlayerMap(Index), Packet)
                Moved = YES
            End If
        End If
        
    ' Check to see if the tile is a warp tile, and if so warp them
    If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).Type = TILE_TYPE_WARP Then
        MapNum = Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).Data1
        x = Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).Data2
        y = Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).Data3
                        
        Call PlayerWarp(Index, MapNum, x, y)
        Moved = YES
    End If
    
    ' Check for key trigger open
    If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).Type = TILE_TYPE_KEYOPEN Then
        x = Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).Data1
        y = Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).Data2
        
        If Map(GetPlayerMap(Index)).Tile(x, y).Type = TILE_TYPE_KEY And TempTile(GetPlayerMap(Index)).DoorOpen(x, y) = NO Then
            TempTile(GetPlayerMap(Index)).DoorOpen(x, y) = YES
            TempTile(GetPlayerMap(Index)).DoorTimer = GetTickCount
                            
            Call SendDataToMap(GetPlayerMap(Index), SMapKey & SEP_CHAR & x & SEP_CHAR & y & SEP_CHAR & 1 & END_CHAR)
            Call MapMsg(GetPlayerMap(Index), "A door has been unlocked.", White)
        End If
    End If
    
    ' They tried to hack
    If Moved = NO Then
        Call HackingAttempt(Index, "Position Modification")
    End If
End Sub
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)