All pastes #895638 Raw Edit

foo bar baz

public lua v1 · immutable
·published 2008-02-07 23:26 UTC
rendered paste body
-- Pushes an object out of the slope it hit.function hit_slope(dir, tile_x, tile_y, mom, slope, was_onfloor)	-- Not done yet: X collisions, cieling slopes.	--if (not dir) or (slope < 4) or (mom < 0) then	if(not dir) or (mom < 0) then		return false	end	local x = math.floor(obj.x/FRACUNIT - tile_x*TILE)	local nx = math.floor(tile_x*TILE - obj.x/FRACUNIT) + TILE	local y = math.floor(obj.y/FRACUNIT + obj.collision.y - tile_y*TILE)	local ny = math.floor(tile_y*TILE - obj.y/FRACUNIT) + TILE	if (x < 0) or (x > TILE) or (y < 0) or (y > TILE) then		-- No collision.		return false	end	if (slope == 0) then		if (y < math.floor(x/2)) and (not was_onfloor) then			return false		end		--obj.y = (tile_x*TILE - math.floor(y/2) + obj.collision.y)*FRACUNIT		local oldy=obj.y		--obj.y = (tile_y*TILE + math.floor(x/2) + obj.collision.y)*FRACUNIT+TILE		obj.y=oldy+(TILE*FRACUNIT)	elseif (slope == 1) then		if (y < math.floor((x+TILE/2))) and (not was_onfloor) then			return false		end		--obj.y = (tile_x*TILE - math.floor(y/2 + TILE/2) + obj.collision.y)*FRACUNIT		local oldy=obj.y		--obj.y = (tile_y*TILE + math.floor((nx+TILE)/2) + obj.collision.y)*FRACUNIT+TILE		obj.y=oldy+(TILE*FRACUNIT)	elseif (slope == 2) then		if (y < math.floor((ny+TILE/2))) and (not was_onfloor) then			return false		end		--obj.y = (tile_x*TILE - math.floor(ny/2 + TILE/2) + obj.collision.y)*FRACUNIT		local oldy=obj.y		obj.y = oldy+(TILE*FRACUNIT)		--obj.y = (tile_y*TILE + math.floor((nx+TILE)/2) + obj.collision.y)*FRACUNIT+TILE	elseif (slope == 3) then		if (y < math.floor(ny/2)) and (not was_onfloor) then			return false		end		--obj.y = (tile_x*TILE - math.floor(ny/2) + obj.collision.)*FRACUNIT		--obj.y = (tile_y*TILE + math.floor(nx/2) + obj.collision.y)*FRACUNIT+TILE		local oldy=obj.y		obj.y=oldy+(TILE*FRACUNIT)		--Floor slopes now.	elseif (slope == 4) then		if (y < math.floor(x/2)) and (not was_onfloor) then			return false		end		obj.y = (tile_y*TILE + math.floor(x/2) - obj.collision.h)*FRACUNIT	elseif (slope == 5) then		if (y < math.floor(x/2 + TILE/2)) and (not was_onfloor) then			return false		end		obj.y = (tile_y*TILE + math.floor(x/2 + TILE/2) - obj.collision.h)*FRACUNIT	elseif (slope == 6) then		if (y < math.floor(nx/2 + TILE/2)) and (not was_onfloor) then			return false		end		obj.y = (tile_y*TILE + math.floor(nx/2 + TILE/2) - obj.collision.h)*FRACUNIT	elseif (slope == 7) then		if (y < math.floor(nx/2)) and (not was_onfloor) then			return false		end		obj.y = (tile_y*TILE + math.floor(nx/2) - obj.collision.h)*FRACUNIT	end	obj.momy = 0	obj.onfloor = 2	return trueend