그래서 저는이 게임을 조금만 진행해 왔습니다. 그러나 과거의 날에는 충돌 감지 작업 방법을 파악하지 못했습니다. 기본적으로타일 충돌 감지
스케일 플레이어가 64 * 스케일하여 41 * 스케일 2.
같다.
내 플레이어의 중심은 x 축과 y 축 모두 가운데에 있습니다.
플레이어가 가운데에 배치되어 있기 때문에 세계는 무엇이 움직이는 지, 그 변수는 worldx와 worldy입니다. 플레이어는 항상 화면 중앙에 있습니다.
내 타일 맵은 배열에 저장되며 이미지 픽셀 색상을 기반으로합니다. map [x] [y]에서 픽셀이 흰색 인 경우 값은 0으로 설정되고 그렇지 않으면 블록으로 설정됩니다. 블록이 렌더링되지 않는다는 것을 의미합니다.
for x = 0, w-1 do --draws the map
for y = 0, h-1 do
if amap[x][y] ~= 0 then
love.graphics.drawq(ImgBlocks, Blocks[amap[x][y]], 32*x*(3/bscale) + worldx, 32*y*(3/bscale) + worldy + jy, 0 , 3/bscale, 3/bscale)
end
if amap[x][y] == 4 then
end
end
end --end function
기능은 플레이어와 블록 사이의 충돌이있는 경우에 true 또는 false 기지를 반환해야지도를 그립니다
for x = 0, w-1 do --scans the image and builds the map array
amap[x] = {}
for y = 0, h-1 do
local r, g, b, a = source:getPixel(x, y)
if r == 255 and g == 255 and b == 255 then
block = 0
end
if r == 255 and g == 100 and b == 0 then
block = 1
end
if r == 130 and g == 125 and b == 0 then
block = 2
end
if r == 76 and g == 76 and b == 76 then
block = 3
end
if r == 255 and g == 0 and b == 255 then
--this is the spawn pixel yet to build
end
amap[x][y] = block
end
end --end function
기능.