<commit_before>local Platform = {}
Platform.__index = Platform
local holddown = 0

function Platform.new(node, collider)
    local platform = {}
    setmetatable(platform, Platform)

    --If the node is a polyline, we need to draw a polygon rather than rectangle
    if node.polyline or node.polygon then
        local polygon = node.polyline or node.polygon
        local vertices = {}

        for k,vertex in ipairs(polygon) do
            -- Determine whether this is an X or Y coordinate
            if k % 2 == 0 then
                table.insert(vertices, vertex + node.y)
            else
                table.insert(vertices, vertex + node.x)
            end
        end

        platform.bb = collider:addPolygon( unpack(vertices) )
        -- Stash the polyline on the collider object for future reference
        platform.bb.polyline = polygon
    else
        platform.bb = collider:addRectangle(node.x, node.y, node.width, node.height)
        platform.bb.polyline = nil
    end

    platform.bb.node = platform
    collider:setPassive(platform.bb)

    return platform
end

function Platform:collide(player, dt, mtv_x, mtv_y)
    local _, wy1, _, wy2  = self.bb:bbox()
    local px1, py1, px2, py2 = player.bb:bbox()
    local distance = math.abs(player.velocity.y * dt) + 0.10

    function updatePlayer()
        player:moveBoundingBox()
        player.jumping = false
        player.rebounding = false
    end

    if self.bb.polyline
                    and player.velocity.y >= 0
                    -- Prevent the player from being treadmilled through an object
                    and ( self.bb:contains(px2,py2) or self.bb:contains(px1,py2) ) then

        if player.state == 'crouch' and player.velocity.x == 0 then
            holddown = holddown + 1
        else
            holddown = 0
        end
        
        if holddown > 20 then
            player.jumping = true
            player.state = 'crouch'
        else
            player.velocity.y = 0
            -- Use the MTV to keep players feet on the ground,
            -- fudge the Y a bit to prevent falling into steep angles
            player.position.y = (py1 - 1) + mtv_y
            updatePlayer()
        end
    elseif player.velocity.y >= 0 and math.abs(wy1 - py2) <= distance then

        if player.state == 'crouch' and player.velocity.x == 0 then
            holddown = holddown + 1
        else
            holddown = 0
        end
        
        if holddown > 20 then
            player.jumping = true
            player.state = 'crouch'
        else
            player.velocity.y = 0
            player.position.y = wy1 - player.height<commit_msg>Move local holddown variable to platform object<commit_after>local Platform = {}
Platform.__index = Platform

function Platform.new(node, collider)
    local platform = {}
    setmetatable(platform, Platform)

    --If the node is a polyline, we need to draw a polygon rather than rectangle
    if node.polyline or node.polygon then
        local polygon = node.polyline or node.polygon
        local vertices = {}

        for k,vertex in ipairs(polygon) do
            -- Determine whether this is an X or Y coordinate
            if k % 2 == 0 then
                table.insert(vertices, vertex + node.y)
            else
                table.insert(vertices, vertex + node.x)
            end
        end

        platform.bb = collider:addPolygon( unpack(vertices) )
        -- Stash the polyline on the collider object for future reference
        platform.bb.polyline = polygon
    else
        platform.bb = collider:addRectangle(node.x, node.y, node.width, node.height)
        platform.bb.polyline = nil
    end

    platform.bb.node = platform
    collider:setPassive(platform.bb)

    platform.holddown = 0

    return platform
end

function Platform:collide(player, dt, mtv_x, mtv_y)
    local _, wy1, _, wy2  = self.bb:bbox()
    local px1, py1, px2, py2 = player.bb:bbox()
    local distance = math.abs(player.velocity.y * dt) + 0.10

    function updatePlayer()
        player:moveBoundingBox()
        player.jumping = false
        player.rebounding = false
    end

    if self.bb.polyline
                    and player.velocity.y >= 0
                    -- Prevent the player from being treadmilled through an object
                    and ( self.bb:contains(px2,py2) or self.bb:contains(px1,py2) ) then

        if player.state == 'crouch' and player.velocity.x == 0 then
            self.holddown = holddown + 1
        else
            self.holddown = 0
        end
        
        if self.holddown > 20 then
            player.jumping = true
            player.state = 'crouch'
        else
            player.velocity.y = 0
            -- Use the MTV to keep players feet on the ground,
            -- fudge the Y a bit to prevent falling into steep angles
            player.position.y = (py1 - 1) + mtv_y
            updatePlayer()
        end
    elseif player.velocity.y >= 0 and math.abs(wy1 - py2) <= distance then

        if player.state == 'crouch' and player.velocity.x == 0 then
            self.holddown = self.holddown + 1
        else
            self.holddown = 0
        end
        
        if self.holddown > 20 then
            player.jumping = true
            player.state = 'crouch'
        else
            player.velocity.y = 0
            player.position.y = wy1 - player.height
{'fraction_non_alphanumeric': 0.0820493781325413, 'fraction_numerical': 0.012994245405606088, 'mean_word_length': 1.758832565284178, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4974500', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1501, 'n_words': 472}