From 9f884751cca62e485e5ccb644de837149f7dd9f6 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 19 Jun 2025 13:58:44 +0200 Subject: [PATCH] - [ONGOING] Treballant en la clase "level" --- data/game.ini | 4 +-- data/level.lua | 88 ++++++++++++++++++++++++++++++++++++++++---------- data/lynx.glsl | 41 +++++++++++++++++++++++ data/main.lua | 23 +++++++------ 4 files changed, 127 insertions(+), 29 deletions(-) create mode 100644 data/lynx.glsl diff --git a/data/game.ini b/data/game.ini index 725a0c5..72e0c9a 100644 --- a/data/game.ini +++ b/data/game.ini @@ -1,5 +1,5 @@ title=PAKU SIMBEL PROFANATION config=paku width=160 -height=144 -zoom=3 +height=104 +zoom=4 diff --git a/data/level.lua b/data/level.lua index 5d6df90..6c960da 100644 --- a/data/level.lua +++ b/data/level.lua @@ -1,36 +1,90 @@ level = { - background = nil, - foreground = nil, + surf_background = nil, + surf_foreground = nil, + surf_items = nil, + surf_original_items = nil, + + pos = {x=0, y=0}, init = function() - level.background = surf.new(20*8,17*8) - level.foreground = surf.new(20*8,17*8) - map.surf(level.background) - for y=0,17*8 do + level.pos.x, level.pos.y = 0,0 + if level.surf_background ~= nil then surf.free(level.surf_background) end + --level.surf_background = surf.load("rooms_background.bin") + level.surf_background = surf.new(20*8,12*8) + + if level.surf_foreground ~= nil then surf.free(level.surf_foreground) end + --level.surf_foreground = surf.load("rooms_foreground.bin") + level.surf_foreground = surf.new(20*8,12*8) + + if level.surf_items ~= nil then surf.free(level.surf_items) end + --level.surf_items = surf.load("rooms_items.bin") + level.surf_items = surf.new(20*8,12*8) + + level.surf_original_items = surf.new(20*8,12*8) + surf.source(level.surf_items) + surf.target(level.surf_original_items) + draw.surf(0,0,160,96,0,0) + + map.surf(level.surf_background) + for y=0,12*8 do for x=0,20*8 do map.tile(x,y,1) end end - map.surf(level.foreground) + map.surf(level.surf_foreground) map.tile(10,10,16) + + surf.save(level.surf_background, "data/rooms_background.bin") + surf.save(level.surf_foreground, "data/rooms_foreground.bin") + surf.save(level.surf_items, "data/rooms_items.bin") + + shader.init("lynx.glsl") + shader.enable(); end, - draw_background = function() - view.clip(0,8,160,136) - view.origin(0,8) - map.surf(level.background) + + draw = function() + -- Retallem la pantalla a la zona de joc + view.clip(0,8,160,96) + + -- Movem la càmara a l'habitació on estem + view.origin(level.pos.x*8,level.pos.y*8+8) + + -- Pintem el background + surf.source(tiles) + map.surf(level.surf_background) map.draw() - view.origin(4,8+4) - map.surf(level.foreground) + + -- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground + view.origin(level.pos.x*8+4,level.pos.y*8+12) + + -- Pintem el foreground de negre + map.surf(level.surf_foreground) pal.subpal(0,32,1) map.draw() - end, - draw_foreground = function() - view.origin(0,8) + -- Pintem els sprites de negre + -- [TODO] + surf.source(sprites) + draw.surf(0, 0, 16, 17, 10, 10, 16, 17) + + -- Movem la càmara al lloc que toca de nou, i tornem la paleta normal + view.origin(level.pos.x*8,level.pos.y*8+8) pal.subpal() - map.surf(level.foreground) + + -- Pintem el foreground + surf.source(tiles) + map.surf(level.surf_foreground) map.draw() + + -- Pintem els sprites + -- [TODO] + surf.source(sprites) + draw.surf(0, 0, 16, 17, 10, 10, 16, 17) + + -- Pintem la rejilla + --for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end + --for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end end, peiv = function() diff --git a/data/lynx.glsl b/data/lynx.glsl new file mode 100644 index 0000000..6b6787f --- /dev/null +++ b/data/lynx.glsl @@ -0,0 +1,41 @@ +varying vec2 tex_coord; +varying vec2 pix_coord; + +#if defined(VERTEX) + +void main() +{ + pix_coord = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001; + tex_coord = vec2((gl_Vertex.x+1.0)*0.5, (-gl_Vertex.y+1.0)*0.5); + vec4 pos = vec4(gl_Vertex.x * 2.0, gl_Vertex.y * 2.0, gl_Vertex.z, gl_Vertex.w); + gl_Position = gl_Vertex; //(gl_Vertex*2)-vec3(1.0, 1.0, 1.0);//gl_ModelViewProjectionMatrix * gl_Vertex; +} + +#elif defined(FRAGMENT) + +uniform sampler2D Texture; + +void main() +{ + float x = sign(pix_coord.x)*floor(abs(pix_coord.x)+0.5); + float column = mod(x,4.0); + vec4 color = texture2D(Texture, tex_coord); + float xfade = abs((tex_coord.s * 2.0) - 1.0); + xfade = xfade * xfade * xfade * xfade * xfade; + float yfade = abs((tex_coord.t * 2.0) - 1.0); + yfade = yfade * yfade * yfade * yfade * yfade; + color = color + vec4(0.7, 0.7, 0.7, 0.0) * (1.0-tex_coord.t) * (1.0-xfade) * (1.0-yfade); + vec4 newcolor; + if (column == 0.0) { + newcolor = color * vec4(1.0, 0.4, 0.6, 1.0); + } else if (column == 1.0) { + newcolor = color * vec4(0.4, 1.0, 0.4, 1.0); + } else if (column == 2.0) { + newcolor = color * vec4(0.6, 0.4, 1.0, 1.0); + } else { + newcolor = color * vec4(0.2, 0.2, 0.2, 1.0); + } + gl_FragColor = newcolor; +} + +#endif diff --git a/data/main.lua b/data/main.lua index 2ff07f7..85acb00 100644 --- a/data/main.lua +++ b/data/main.lua @@ -14,17 +14,20 @@ end function mini.update() view.origin(0,0) surf.cls(1) - - level.draw_background() - surf.source(sprites) - draw.surf(0, 0, 16, 17, 10, 10, 16, 17) - surf.source(tiles) - level.draw_foreground() - surf.source(sprites) - draw.surf(0, 0, 16, 17, 10, 10, 16, 17) - surf.source(tiles) + surf.target(0) - --draw.surf(0, 0, 64, 64, 10, 10) + -- Pintar el marcador + -- [TODO] + + -- Pintar el mapa i sprites + level.draw() + + view.origin(0,0) + local mx, my = mouse.pos() + mx, my = math.floor(mx/8)*8, math.floor(my/8)*8 + + draw.rect(mx-1, my-1, 10, 10, 28) + draw.rect(mx, my, 8, 8, 1) if (key.down(key.ESCAPE)) then sys.quit() end