From 0733a459cd2d8ee21db01b7ca2500214d9744ee5 Mon Sep 17 00:00:00 2001 From: parameterized Date: Fri, 25 Jan 2019 17:03:53 -0500 Subject: [PATCH] smooth tile patterns, tile debug, tile id lookup --- entities.lua | 8 +-- entityDefs/player.lua | 8 +-- gfx/tiles/all_tiles.png | Bin 0 -> 2019 bytes gfx/tiles/platformSheet.png | Bin 244 -> 0 bytes gfx/tiles/smooth_tiles.png | Bin 0 -> 1479 bytes gfx/tiles/tilesheet1.png | Bin 1575 -> 0 bytes gfx/tiles/tilesheet2.png | Bin 445 -> 0 bytes gfx/tiles/tilesheet2_round.png | Bin 0 -> 467 bytes loadassets.lua | 41 +++++------ main.lua | 6 ++ shaders/mapGen.glsl | 29 +++++--- shaders/mapRender.glsl | 128 ++++++++++++++++++++++----------- world.lua | 17 ++--- 13 files changed, 147 insertions(+), 90 deletions(-) create mode 100644 gfx/tiles/all_tiles.png delete mode 100644 gfx/tiles/platformSheet.png create mode 100644 gfx/tiles/smooth_tiles.png delete mode 100644 gfx/tiles/tilesheet1.png delete mode 100644 gfx/tiles/tilesheet2.png create mode 100644 gfx/tiles/tilesheet2_round.png diff --git a/entities.lua b/entities.lua index ab417d7..7c1fca6 100644 --- a/entities.lua +++ b/entities.lua @@ -56,8 +56,8 @@ function entities.server.update(dt) if choice ~= 'none' then local x = (cx*entities.chunkSize + math.random()*entities.chunkSize)*15 local y = (cy*entities.chunkSize + math.random()*entities.chunkSize)*15 - -- if not in spawn area - if not (x^2 + y^2 < 192^2) then + -- if not in spawn area or wall + if x^2 + y^2 > 192^2 and serverRealm.world:getTile(x, y) ~= tile2id['wall'] then entities.server.defs[choice]:new{x=x, y=y}:spawn() end end @@ -67,7 +67,7 @@ function entities.server.update(dt) local x = (cx*entities.chunkSize + math.random()*entities.chunkSize)*15 local y = (cy*entities.chunkSize + math.random()*entities.chunkSize)*15 -- if on grass - if serverRealm.world:getTile(x, y) == 1 then + if serverRealm.world:getTile(x, y) == tile2id['grass'] then entities.server.defs.tree:new{x=x, y=y}:spawn() end end @@ -76,7 +76,7 @@ function entities.server.update(dt) for j=1, entities.chunkSize do local x = (cx*entities.chunkSize + (i-1))*15 local y = (cy*entities.chunkSize + (j-1))*15 - if serverRealm.world:getTile(x, y) == 8 then + if serverRealm.world:getTile(x, y) == tile2id['wall'] then entities.server.defs.wall:new{x=x, y=y}:spawn() end end diff --git a/entityDefs/player.lua b/entityDefs/player.lua index 963c994..5048a86 100644 --- a/entityDefs/player.lua +++ b/entityDefs/player.lua @@ -92,8 +92,8 @@ for _, sc in ipairs{'server', 'client'} do dd = math.sqrt(dx^2 + dy^2) local spd = self.spd*(self.inputState.keyboard.lshift and 2.5 or 1) local tile = self.realm.world:getTile(self.x, self.y) - if tile == 5 or tile == 6 then spd = spd * 1.5 end -- platform, path - if tile == 4 then spd = spd / 2 end -- water + if tile == tile2id['platform'] or tile == tile2id['path'] then spd = spd * 1.5 end + if tile == tile2id['water'] then spd = spd / 2 end local attackItem = self.items.getItem(self.inventory.items[2]) if dd ~= 0 then self.body:applyForce(dx/dd*spd, dy/dd*spd) @@ -284,7 +284,7 @@ function player.client:draw() -- offset if on platform or path local tile = clientRealm.world:getTile(self.x, self.y) - if tile == 5 or tile == 6 then + if tile == tile2id['platform'] or tile == tile2id['path'] then love.graphics.translate(0, -2) end @@ -305,7 +305,7 @@ function player.client:draw() love.graphics.clear() -- offset/clip feet if in water - if tile == 4 then + if tile == tile2id['water'] then love.graphics.translate(0, 4) love.graphics.stencil(function() love.graphics.rectangle('fill', self.x - 50, self.y - 4, 100, 100) diff --git a/gfx/tiles/all_tiles.png b/gfx/tiles/all_tiles.png new file mode 100644 index 0000000000000000000000000000000000000000..eb884eb53dd20efedbf4e27d357eb1ed0f63642f GIT binary patch literal 2019 zcmV<92ORi`P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02p*dSaefwW^{L9 za%BK;VQFr3E^cLXAT%y9E;VFFSW*B02UJN!K~!i%?V8zdRaF$m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zh0SA*AY^gdkX=vqL58X&Z)4uglG4?STV$L{ z<^a03Qmky5czA`+o69zH5S;ustK_x+=?zJMVBrH?1@G60Z{fie@H0x@Wk~o2Z0F!q`^ux$F3*4Aj4AxAk!6#&l)(F=_=;V zWa|#fe8fX?OAI`=YM@ZLaNESYnYq47E(30kmxGY$N~PPyn;K2t+m+4_0kpd9Hm8?E z!-TJn*siay7YnHH)f4)`?G*80ki}ILWN{S*SsZ08WCVz>{D22=v0}M%nXPj0<7UaZ zh=&N)-Sdma+%Pq8fbEYT`~BYrcsU3Ywm<;HuaGooP}kvMvE?7NxH0D7+nC-ODQu&& zX3dgc1p0XO#~i|l_;iq^8{;~nAWJvK98rL!8?)=VCyXa9 z3uAmc!x-X4b}J-k1nSQV$t~0Q?Hu}i@^Tb@m@v3uHty z0a)|E;jK-Jdc!{{SZ3k(=Psmzn?o002ovPDHLkV1i;P B#(4k$ literal 0 HcmV?d00001 diff --git a/gfx/tiles/platformSheet.png b/gfx/tiles/platformSheet.png deleted file mode 100644 index 039e42753e5e1c3054edbe2910a9f7e5b5d8d488..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 244 zcmeAS@N?(olHy`uVBq!ia0vp^Na~60+7BevL9R^{>(B`g{ashpoI*cu6{1-oD!M*Vm{bR)BIwq3RjI2e zB3ZN@b!8EzjuP5vm$I}Zjv|MIIQG}s?#}EV-|zRmH}Cqq_kAx1>w<q11$p3BJ0Xw-9+?Dp^hFSDRFelVvf&plUjTs^RHfYzIe+F{R0;%+V zJu(9^byor5@kB@8M30#3iOC`H*Fdo$H=+}bqOT?DoHH^pGP{cQ1;WT#VjM1b5`xwq zFezFVsty*&ODCefW9i~>RpV|Zk~xR81jT&&oIJlf!P;h`dz$giIB19p?9wftV^aM4 z$v>apJWxvC-$v)nPESY09PA6$h9Vw!pE=mym)=s_@8N@@bUwpJTI4rBfGdgf2)UG< z@0z^=(A4hq-RFUs$j{ozV7=OiGBZgp+0-VElF=dQn$)Km%yv@6V)2^(>cYZ8*gqOH zH&54qDjnD0^?|s@#DGjBFKrR<%reVe&cVY!@mBUMX}vR3m)Z7@nF#ZuP{TS$t*y^j zM$Qk{mz^RR3!TA9@_23`ASX#Wt#yj+dP&)|a>-#9^-z7wAx7alEN84_KKX8Ki+i3~pV?1* zEZ0rLGq%`+`T@(qUEV}l>rkhL{Pb9edBo|IdkpXCV*yCz9CB`7O{x*_1P^;wX4l6e{`;MtSXHD zJ*wx%!&E})UYfmA>Sn_I>*N}k0_P-Q#@YBI*nahOjEoQm>$IJWH2&yg98}vmxij9u z!5h6rJsSYrrbRH;DU8E`)SmWv@pMD?7Y}9pWT7d^zzL@9znU7h%oHiW-bl!}CMmoZ zCGiq9`EKvW!v>vgFx_&DLfaw;5GpXnxIVj(SZVuG;}r&>JHwerCAPr3Pm>xq>Xavx zFlefJE@w2?_PX`!!-QYf_sH-_Bmm;sfTFk1Wa0KJ#-ms+d!sG%zd&iTXq4wFjiICI;0va z_&=UgP>+~A3YRGRPOW<>XfLTe)VC_Xly}91SRJxVsRxQ?Z7pU#*qaCz>t!WvG%R0X z@B_EVfI+hcuRry8(;40i9dkCCKLg>#Zllh}yUU6kxB zZV)T7VIIbH9xxhujQN0Mksi%f-Wamcxf{4`NJg$!0BF|wrOW**t-t!)m57NWHU4PP z*G}Oh-o!`A;SudS1 zNERE?XS}Z7hUg>Y;KQZc)m}b#%!FeC^jJFGWv{L7txoZ1g8NOjCtPh&VbbYX$W06awWh_%?;H1be4(r6E##-=RpiC95YX*;dUm zm{}#8$fdFho4DYWiHf61W#E$JhXO=_uyZbYRabM+fPPpd@!p3&r97KUeeOaVS`>%5aU3=Fr0#izdgb^J2=6S z#s$W_s QfISPsIJ!8{F5)u&23T+3{r~^~ literal 0 HcmV?d00001 diff --git a/gfx/tiles/tilesheet1.png b/gfx/tiles/tilesheet1.png deleted file mode 100644 index dc9c3075f8fa2c10f27f9dfadb81e5bc308a4f51..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc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wISTBB z@3KMh#kpHEfptDe_FiC`ba!`~-rim*sNACuk`}_&`pp>9iTf02)yzRnG29Qx+=qi% Z^e?ESOF&L}PV)c&002ovPDHLkV1i{*+AjbA diff --git a/gfx/tiles/tilesheet2.png b/gfx/tiles/tilesheet2.png deleted file mode 100644 index e921326fcd4decfcd4a23d1357c3ab6a0ba355a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 445 zcmeAS@N?(olHy`uVBq!ia0vp^#y~8{!3HD?j!qE=QjEnx?oJHr&dIz4a#+$GeH|GX zHuiJ>Nn{1`ISV`@iy0XB4ude`@%$AjKtYKT*NBqf{Irtt#G+J&g2c?c61}|C5(N`I zLp{?J_XwahjC!6fjv*f2cl&qq9&!+HiRE7;7^Eb%K)}g`lP{yCM{Grd8(;6msMlBD zJl8Av@L*5*=2_-juazDC^m*6ZTN;~QRN8L|OgaA5W^3St`zLCidrSI1`)oHY(dhHz ze%;d-@+ZcpMkG$StH`f3@r_^Ei>7IB_WA35iu`MM_N_L) znV9-z`@i)33FScA{Co&FEN@YQ{8T}0Ys@=ukrcH12kxr@e@Yv$hjx^G}F4X7~k`L3R&i*60ACD zQxh|EQG*Nb!!8yr=XE;tUYnnB^*^pZ8P#3w0 c|JE1gXU=mww%W{m2n<~YPgg&ebxsLQ0Mf{@Z~y=R diff --git a/gfx/tiles/tilesheet2_round.png b/gfx/tiles/tilesheet2_round.png new file mode 100644 index 0000000000000000000000000000000000000000..214b4c84df56bd661f6826ed97e90b4e614a8e45 GIT binary patch literal 467 zcmeAS@N?(olHy`uVBq!ia0vp^#y~8{!3HD?j!qE=QY`6?zK#qG8~eHcB(eheoCO|{ z#S9F5hd`K7RKu$QC@4|l8c`CQpH@QxCOI%DG6k9rk>Kv3)wm7hwY|7YYa{SJn8@ugW9^9?ey*+Dt zui-!5jhuFIa&3=|jqk<32T}9nw?F*BV`(b!=l7?Qq|mN|`|aNQukljlJYLS%uM+sR z#NSgW^n5wz;kbKsp84Xpx#5Nhvg1OXOKQOGIo|_{r?242n*LcXYyUze zt!4G|AHMrKx#{)pSE~cK*1cb~-bwR?7w-o7)UcN+Af%BxDdf7hk>{${s*+rpZy#=D zyJ3Igj@P7}Q&ko}O!rCE+G)~W`@m>w%&f<}(<9e1ep~O}z~(x)={HY#Cz$TJ@8KBg zP+e18ZvW_E`k9ol6)7e;?CCqJEvB@rn)goAbH%HldY(=%*D59Gb2OMA7^;j!fVowb+L4w-GA~%9YcEcCxc6B7ZrgKz~JfX=d#Wzp$Pz6 C-n+v9 literal 0 HcmV?d00001 diff --git a/loadassets.lua b/loadassets.lua index 9295e37..cd909ee 100644 --- a/loadassets.lua +++ b/loadassets.lua @@ -48,9 +48,8 @@ gfx = { } }, tiles = { - tileSheet1 = love.graphics.newImage('gfx/tiles/tilesheet1.png'), - platformSheet = love.graphics.newImage('gfx/tiles/platformSheet.png'), - tileSheet2 = love.graphics.newImage('gfx/tiles/tilesheet2.png') + allTiles = love.graphics.newImage('gfx/tiles/all_tiles.png'), + smoothTiles = love.graphics.newImage('gfx/tiles/smooth_tiles.png') }, environment = { tree = love.graphics.newImage('gfx/environment/tree.png'), @@ -193,14 +192,18 @@ function newTileSheet(sheet, w, h, pad, num, names) local x = (i-1)*(w + pad*2) + 1 local y = 1 local sw, sh = sheet:getDimensions() - t.quads[names[i] or i] = love.graphics.newQuad(x, y, w, h, sw, sh) + local quad = love.graphics.newQuad(x, y, w, h, sw, sh) + t.quads[i] = quad + if names[i] then + t.quads[names[i]] = quad + end end return t end -tileSheets.ts1 = newTileSheet(gfx.tiles.tileSheet1, 15, 15, 1, 4, {'grass', 'sand', 'rock', 'water'}) -tileSheets.platform = newTileSheet(gfx.tiles.platformSheet, 15, 15, 1, 2) -tileSheets.ts2 = newTileSheet(gfx.tiles.tileSheet2, 15, 15, 1, 3, {'path', 'floor', 'wall'}) +tileSheets.allTiles = newTileSheet(gfx.tiles.allTiles, 15, 15, 1, 9, + {'water', 'sand', 'grass', 'rock', 'path', 'floor', 'wall', 'platform', 'platform2'}) +tileSheets.smoothTiles = newTileSheet(gfx.tiles.smoothTiles, 15, 15, 1, 16) fonts = { f10 = love.graphics.newFont(10), @@ -233,33 +236,23 @@ love.graphics.clear(0, 0, 0) love.graphics.setCanvas() -- black tile table.insert(tileImgs, love.graphics.newImage(tileCanv:newImageData())) -for _, v in ipairs{'grass', 'sand', 'rock', 'water'} do +for i=1, 9 do love.graphics.setCanvas(tileCanv) love.graphics.clear() - love.graphics.draw(tileSheets.ts1.sheet, tileSheets.ts1.quads[v], 0, 0) + love.graphics.draw(tileSheets.allTiles.sheet, tileSheets.allTiles.quads[i], 0, 0) love.graphics.setCanvas() table.insert(tileImgs, love.graphics.newImage(tileCanv:newImageData())) end shaders.mapRender:send('tiles', unpack(tileImgs)) -local platformFrames = {} -for _, quad in ipairs(tileSheets.platform.quads) do +smoothTileImgs = {} +for i=1, 16 do love.graphics.setCanvas(tileCanv) love.graphics.clear() - love.graphics.draw(tileSheets.platform.sheet, quad, 0, 0) + love.graphics.draw(tileSheets.smoothTiles.sheet, tileSheets.smoothTiles.quads[i], 0, 0) love.graphics.setCanvas() - table.insert(platformFrames, love.graphics.newImage(tileCanv:newImageData())) + table.insert(smoothTileImgs, love.graphics.newImage(tileCanv:newImageData())) end -shaders.mapRender:send('platformFrames', unpack(platformFrames)) - -local tileImgs2 = {} -for _, v in ipairs{'path', 'floor', 'wall'} do - love.graphics.setCanvas(tileCanv) - love.graphics.clear() - love.graphics.draw(tileSheets.ts2.sheet, tileSheets.ts2.quads[v], 0, 0) - love.graphics.setCanvas() - table.insert(tileImgs2, love.graphics.newImage(tileCanv:newImageData())) -end -shaders.mapRender:send('tiles2', unpack(tileImgs2)) +shaders.mapRender:send('smoothTiles', unpack(smoothTileImgs)) shaders.lifemana:send('lifemanaEmpty', gfx.hud.lifemanaEmpty) diff --git a/main.lua b/main.lua index 4fe84a7..e477f8f 100644 --- a/main.lua +++ b/main.lua @@ -32,6 +32,10 @@ require 'chat' -- todo: better sword check isSword = {['sword0']=true, ['sword1']=true, ['sword2']=true, ['sword3']=true, ['sword4']=true} +tile2id = {} +for i, v in ipairs{'water', 'sand', 'grass', 'rock', 'path', 'floor', 'wall', 'platform', 'platform2'} do + tile2id[v] = i +end function love.load() camera = Camera{ssx=gsx, ssy=gsy} @@ -106,6 +110,8 @@ function love.update(dt) manual_gc(1e-3, 64) prof.pop('update gc') prof.pop('update') + + shaders.mapRender:send('drawDebug', drawDebug) end function love.mousepressed(x, y, btn, isTouch, presses) diff --git a/shaders/mapGen.glsl b/shaders/mapGen.glsl index 5fa6816..2c30eba 100644 --- a/shaders/mapGen.glsl +++ b/shaders/mapGen.glsl @@ -82,14 +82,16 @@ float snoise(vec2 v) } +// 1: water, 2: sand, 3: grass, 4: rock, 5: path, 6: floor, 7: wall, 8: platform + vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) { vec2 uv = screen_coords; uv += camPos; vec2 p = floor(uv); - // grass/sand/rock/water - int tileChoices[3] = int[](1, 2, 4); + // grass/sand/water + int tileChoices[3] = int[](3, 2, 1); float r1 = snoise(p/32.0)*0.5 + 0.5; int choice = 0; for (int i=0; i < 3; i++) { @@ -98,9 +100,10 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) break; } } + // rock float r2 = snoise(1000.0 + p/64.0)*0.5 + 0.5; if (r1 < 0.2 && r2 < 0.5) { - choice = 3; + choice = 4; } // buildings @@ -109,16 +112,18 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) vec4 vpts = voronoi(vp, 0.5); vec2 vd = vec2(floor(abs(vp.x - vpts.x)*freq), floor(abs(vp.y - vpts.y)*freq)); // inside + // floor if (vd.x <= 4.0 && vd.y <= 6.0) { - choice = 7; + choice = 6; } + // path if (distance(vp, vpts.xy)*freq < 2.0) { - choice = 6; + choice = 5; } // walls if ((vd.x == 4.0 && vd.y <= 6.0 || vd.y == 6.0 && vd.x <= 4.0) && vd.x > 1.0 && vd.y > 1.0) { - choice = 8; + choice = 7; } // paths @@ -126,14 +131,22 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) float angle = atan(p.y, p.x); angle += snoise(2000.0 + p/64.0)/d*4.0; if (distance(mod(angle/(2.0*M_PI)*8.0, 1.0), 0.5) < 0.3/(d/8.0)) { - choice = 6; + choice = 5; } // platform if (length(p) < 8.0) { - choice = 5; + choice = 8; } + // test + if (p == vec2(0.0) || p == vec2(1.0, 0.0) || p == vec2(0.0, 1.0) || p == vec2(1.0, 2.0)) { + choice = 5; + } + if (p == vec2(0.0)+vec2(18.0, 0.0) || p == vec2(1.0, 0.0)+vec2(18.0, 0.0) || p == vec2(0.0, 1.0)+vec2(18.0, 0.0) || p == vec2(1.0, 2.0)+vec2(18.0, 0.0)) { + choice = 5; + } + return vec4(choice/255.0, 0.0, 0.0, 1.0); } diff --git a/shaders/mapRender.glsl b/shaders/mapRender.glsl index 76c24ab..ed7f9ed 100644 --- a/shaders/mapRender.glsl +++ b/shaders/mapRender.glsl @@ -3,13 +3,21 @@ uniform vec2 tileIdRes; uniform vec2 camPos; uniform vec2 tilemapPos; uniform Image tileIds; -uniform Image tiles[5]; -uniform Image platformFrames[2]; -uniform Image tiles2[3]; +uniform Image tiles[10]; +uniform Image smoothTiles[16]; uniform float time; +uniform bool drawDebug; float tileSize = 15.0; +float min3(vec3 v) { + return min(min(v.x, v.y), v.z); +} + +float max3(vec3 v) { + return max(max(v.x, v.y), v.z); +} + vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) { vec2 uv = screen_coords; @@ -18,13 +26,12 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) vec2 tilePos = floor(uv/tileSize); //vec2 tilemapPos = floor(camPos/tileSize) - 2.0; // imprecision errors if calculated in shader? vec2 tileIdPos = tilePos - tilemapPos; - vec4 tileIdColor = Texel(tileIds, tileIdPos/(tileIdRes + vec2(1.0))); - int centerId = int(tileIdColor.r*255.0); vec4 topLeftIdColor = Texel(tileIds, (tileIdPos + vec2(-1.0, -1.0))/(tileIdRes + vec2(1.0))); vec4 topIdColor = Texel(tileIds, (tileIdPos + vec2(0.0, -1.0))/(tileIdRes + vec2(1.0))); vec4 topRightIdColor = Texel(tileIds, (tileIdPos + vec2(1.0, -1.0))/(tileIdRes + vec2(1.0))); vec4 leftIdColor = Texel(tileIds, (tileIdPos + vec2(-1.0, 0.0))/(tileIdRes + vec2(1.0))); + vec4 centerIdColor = Texel(tileIds, tileIdPos/(tileIdRes + vec2(1.0))); vec4 rightIdColor = Texel(tileIds, (tileIdPos + vec2(1.0, 0.0))/(tileIdRes + vec2(1.0))); vec4 bottomLeftIdColor = Texel(tileIds, (tileIdPos + vec2(-1.0, 1.0))/(tileIdRes + vec2(1.0))); vec4 bottomIdColor = Texel(tileIds, (tileIdPos + vec2(0.0, 1.0))/(tileIdRes + vec2(1.0))); @@ -34,54 +41,91 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) int topId = int(topIdColor.r*255.0); int topRightId = int(topRightIdColor.r*255.0); int leftId = int(leftIdColor.r*255.0); + int centerId = int(centerIdColor.r*255.0); int rightId = int(rightIdColor.r*255.0); int bottomLeftId = int(bottomLeftIdColor.r*255.0); int bottomId = int(bottomIdColor.r*255.0); int bottomRightId = int(bottomRightIdColor.r*255.0); - if (centerId < 5) { - vec4 c1 = Texel(tiles[centerId], tileUV)*color; - if (tileUV.x < 0.5) { - if (tileUV.y < 0.5) { - if (topId != centerId && leftId != centerId - && topLeftId != centerId && topLeftId < 5) { - vec4 c2 = Texel(tiles[topLeftId], tileUV)*color; - float t = length(1.0 - tileUV*2.0) < 1.0 ? 1.0 : 0.0; - return t > 0.5 ? c1 : c2; - } - } else { - if (bottomId != centerId && leftId != centerId - && bottomLeftId != centerId && bottomLeftId < 5) { - vec4 c2 = Texel(tiles[bottomLeftId], tileUV)*color; - float t = length(1.0 - tileUV*2.0) < 1.0 ? 1.0 : 0.0; - return t > 0.5 ? c1 : c2; - } - } + int outId = centerId; + float t = length(1.0 - tileUV*2.0) < 1.0 ? 1.0 : 0.0; + + // this tile, opposite, side1, side2 + vec4 corner; + if (tileUV.x < 0.5) { + if (tileUV.y < 0.5) { + corner = vec4(centerId, topLeftId, topId, leftId); } else { - if (tileUV.y < 0.5) { - if (topId != centerId && rightId != centerId - && topRightId != centerId && topRightId < 5) { - vec4 c2 = Texel(tiles[topRightId], tileUV)*color; - float t = length(1.0 - tileUV*2.0) < 1.0 ? 1.0 : 0.0; - return t > 0.5 ? c1 : c2; - } - } else { - if (bottomId != centerId && rightId != centerId - && bottomRightId != centerId && bottomRightId < 5) { - vec4 c2 = Texel(tiles[bottomRightId], tileUV)*color; - float t = length(1.0 - tileUV*2.0) < 1.0 ? 1.0 : 0.0; - return t > 0.5 ? c1 : c2; - } + corner = vec4(centerId, bottomLeftId, bottomId, leftId); + } + } else { + if (tileUV.y < 0.5) { + corner = vec4(centerId, topRightId, topId, rightId); + } else { + corner = vec4(centerId, bottomRightId, bottomId, rightId); + } + } + + vec3 debugColor = vec3(0.0); + + float maxNeighbors = max3(corner.yzw); + float minNeighbors = min3(corner.yzw); + bool clipped = false; + if (corner.x > maxNeighbors) { + outId = int(t > 0.5 ? corner.x : maxNeighbors); + debugColor.r = 1.0; + clipped = true; + } + if (minNeighbors > corner.x) { + outId = int(t > 0.5 ? corner.x : minNeighbors); + debugColor.g = 1.0; + clipped = true; + } + if (minNeighbors != corner.x && minNeighbors == corner.z && minNeighbors == corner.w) { + outId = int(t > 0.5 ? corner.x : minNeighbors); + debugColor.b = 1.0; + clipped = true; + } + + int smoothId = 0; + if (outId == 5 || outId == 6 || outId == 8) { // smooth path, floor, platform + if (corner.x == corner.y && corner.x == corner.z && corner.x == corner.w + || (corner.x == corner.z || corner.x == corner.w) && corner.z != corner.w && corner.x != corner.y) { + smoothId = 0; + if (corner.x < maxNeighbors && (corner.x != corner.z || corner.x != corner.w) && corner.y != corner.z && corner.y != corner.w) { + smoothId = 3; + } + } else if (corner.x == corner.z && corner.z == corner.w + || corner.x == corner.y && corner.z != corner.w && (corner.x == corner.z || corner.x == corner.w)) { + smoothId = 3; + } else if (corner.x != corner.y && corner.x != corner.z && corner.x != corner.w) { + smoothId = 2; + if (corner.x < maxNeighbors && (corner.y != corner.z && corner.y != corner.w || (corner.y == corner.z || corner.y == corner.w))) { + smoothId = 3; } + } else { + smoothId = 3; + } + if (int(corner.x) != outId) { + smoothId = 1; + } else if (clipped) { + smoothId = 2; } } - if (centerId == 5) { + if (drawDebug) { + return vec4(debugColor, 1.0); + } + + + if (outId == 5) { // path + return Texel(smoothTiles[0 + smoothId], tileUV)*color; + } else if (outId == 6) { // floor + return Texel(smoothTiles[4 + smoothId], tileUV)*color; + } else if (outId == 8) { // platform int frame = int(mod(floor(time - length(tilePos)/4.0), 2.0)); - return Texel(platformFrames[frame], tileUV)*color; - } else if (centerId > 5) { - return Texel(tiles2[centerId - 6], tileUV)*color; + return Texel(smoothTiles[8 + frame*4 + smoothId], tileUV)*color; } else { - return Texel(tiles[centerId], tileUV)*color; + return Texel(tiles[outId], tileUV)*color; } } diff --git a/world.lua b/world.lua index 598d6f6..3c5d139 100644 --- a/world.lua +++ b/world.lua @@ -22,14 +22,15 @@ for _, sc in ipairs{'server', 'client'} do t.chunkImages = {} t.chunkIdImages = {} t.tileColors = { - {98, 195, 116}, - {251, 228, 125}, - {98, 98, 98}, - {41, 137, 214}, - {73, 73, 73}, - {205, 140, 79}, - {183, 163, 43}, - {104, 88, 0} + {41, 137, 214}, -- water + {251, 228, 125}, -- sand + {98, 195, 116}, -- grass + {98, 98, 98}, -- rock + {205, 140, 79}, -- path + {183, 163, 43}, -- floor + {104, 88, 0}, -- wall + {73, 73, 73}, -- platform + {73, 73, 73} -- platform } for _, color in ipairs(t.tileColors) do for i=1, 3 do