それで、私はこのゲームに少し取り組んできました。ただし、過去 1 日間、衝突検出の仕組みがわかりませんでした。
デフォルトのスケールは 2 です。
プレーヤーは 41*scale × 64*scale です。
私のプレーヤーは、x 軸と y 軸の両方で画面の中央に配置されています。
プレイヤーが中心にいるので、世界が動くので、これらの変数は worldx と worldy です。プレイヤーは常に画面の中央に留まります。
タイル マップは配列に格納され、画像のピクセルの色に基づいています。map[x][y] でピクセルが白の場合、値は 0 に設定され、それ以外の場合はブロックに設定されます。ブロックがレンダリングされないことを意味します。
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
地図を描画する関数
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 を返す必要があります。