Page 1 of 2

Block Dash 1.0 is Out Now!

Posted: Mon Nov 07, 2022 5:36 am
by pyxledev
(removed the other post due to me posting it on the wrong category)

Hello everyone, my biggest project in Love2D, BlockDash, is finally done. Despite having to rewrite half of the code because of a major memory leak, the development was butter smooth and I'm really excited to finally release it. Of course, there is a lot of things that I plan to add, but for now, the game is at least fully playable.

If you ever find a bug/issue or just want to criticize, please don't hesitate. Download the .love file below or visit the itch.io page:
https://zerpnord.itch.io/blockdash
You can also clone the repository from here, it's completely open source:
https://github.com/Zerpnord/BlockDash

Re: Block Dash 1.0 is Out Now!

Posted: Sun Jan 08, 2023 5:57 pm
by k1ngS4krifice
cool! :D

Re: Block Dash 1.0 is Out Now!

Posted: Mon Jan 09, 2023 11:39 am
by Bigfoot71
Super cool ! :D

Here is a little trick that could be applied for the stars. You can display it only once in a canvas and then display it with a shader that would make it repeat infinitely.

Here is a demo I made very quickly that implements this:

Code: Select all

local function uniform(a,b)
	return a + (math.random()*(b-a))
end

local function genStars(nStars)

    local canvas = love.graphics.newCanvas()

    love.graphics.setCanvas(canvas)

        local size = uniform(1.7, 3.45)

        for i = 1, nStars do
            love.graphics.rectangle(
                "fill",
                uniform(0, SC_WIDTH),
                uniform(0, SC_HEIGHT),
                size, size
            )
        end

    love.graphics.setCanvas()

    return canvas

end

local repeatShader = love.graphics.newShader[[

    // extern number tex_width;     // To be used if the texture is not the same size as the screen, and replace `love_ScreenSize` with these values
    // extern number tex_height;

    extern vec2 cam_pos;

    vec4 effect(vec4 color, Image tex, vec2 tex_coords, vec2 screen_coords)
    {
        number x = mod(screen_coords.x + cam_pos.x, love_ScreenSize.x) / love_ScreenSize.x;
        number y = mod(screen_coords.y + cam_pos.y, love_ScreenSize.y) / love_ScreenSize.y;

        return Texel(tex, vec2(x, y));
    }

]]
The demo I made uses hump.camera instead of yours to save me writing time but it will be easy to readapt I guess ^^

Image

Re: Block Dash 1.0 is Out Now!

Posted: Mon Jan 09, 2023 2:14 pm
by pyxledev
Bigfoot71 wrote: Mon Jan 09, 2023 11:39 am Super cool ! :D

Here is a little trick that could be applied for the stars. You can display it only once in a canvas and then display it with a shader that would make it repeat infinitely.

Here is a demo I made very quickly that implements this:

Code: Select all

local function uniform(a,b)
	return a + (math.random()*(b-a))
end

local function genStars(nStars)

    local canvas = love.graphics.newCanvas()

    love.graphics.setCanvas(canvas)

        local size = uniform(1.7, 3.45)

        for i = 1, nStars do
            love.graphics.rectangle(
                "fill",
                uniform(0, SC_WIDTH),
                uniform(0, SC_HEIGHT),
                size, size
            )
        end

    love.graphics.setCanvas()

    return canvas

end

local repeatShader = love.graphics.newShader[[

    // extern number tex_width;     // To be used if the texture is not the same size as the screen, and replace `love_ScreenSize` with these values
    // extern number tex_height;

    extern vec2 cam_pos;

    vec4 effect(vec4 color, Image tex, vec2 tex_coords, vec2 screen_coords)
    {
        number x = mod(screen_coords.x + cam_pos.x, love_ScreenSize.x) / love_ScreenSize.x;
        number y = mod(screen_coords.y + cam_pos.y, love_ScreenSize.y) / love_ScreenSize.y;

        return Texel(tex, vec2(x, y));
    }

]]
The demo I made uses hump.camera instead of yours to save me writing time but it will be easy to readapt I guess ^^

Image
This is exactly what I needed. Thank you, I'll make sure to credit.

Re: Block Dash 1.0 is Out Now!

Posted: Mon Jan 09, 2023 2:35 pm
by Bigfoot71
pyxledev wrote: Mon Jan 09, 2023 2:14 pm This is exactly what I needed. Thank you, I'll make sure to credit.
But it was fun! If you have any other questions or need help, please do not hesitate ! ^^
(note that I forgot to put `local size = uniform(1.7, 3.45)` in the loop).

Re: Block Dash 1.0 is Out Now!

Posted: Mon Apr 17, 2023 7:35 pm
by pyxledev
Bigfoot71 wrote: Mon Jan 09, 2023 2:35 pm
pyxledev wrote: Mon Jan 09, 2023 2:14 pm This is exactly what I needed. Thank you, I'll make sure to credit.
But it was fun! If you have any other questions or need help, please do not hesitate ! ^^
(note that I forgot to put `local size = uniform(1.7, 3.45)` in the loop).
Hey man, kind of a late answer but I've been trying to implement this shader into the game, going well except one thing: resizing the window.

Here is a default 960x540 photo of the stars (infinity works well):
Image

And here is a fullscreen one:
Image

Long story short, I gotta make this adaptive to screen resizing, and have been struggling to do so. Could you help? Thanks!

Re: Block Dash 1.0 is Out Now!

Posted: Mon Apr 17, 2023 9:29 pm
by Bigfoot71
The best solution for your case in my opinion would be to first send the dimension of your texture to the shader to work with instead of the dimensions of the screen, here is the modification (I took the opportunity to optimize it a bit using fract rather than mod):

Code: Select all

extern vec2 tex_size;
extern vec2 cam_pos;

vec4 effect(vec4 color, Image tex, vec2 tex_coords, vec2 screen_coords) {
    vec2 wrapped_coords = (screen_coords + cam_pos) / tex_size;
    return Texel(tex, fract(wrapped_coords)); // Get the fractional part (xy%1)
}
About the shader, you can replace `extern vec2 tex_size` with `const vec2 tex_size = vec2(WIDTH, HEIGHT)` if the size will never change.

And then display the background with the shader by doing a "push, scale, pop" like this:

Code: Select all

love.graphics.push()

    love.graphics.scale(
        love.graphics.getWidth()/SC_WIDTH,
        love.graphics.getHeight()/SC_HEIGHT
    )

    love.graphics.setShader(repeatShader)
        love.graphics.draw(starCanvas)
    love.graphics.setShader()

love.graphics.pop()
Edit: Or just this would be more suitable in this case (always with the new shader), sorry I answered without thinking too much and with fatigue it's not optimal:

Code: Select all

    local sx = love.graphics.getWidth()/SC_WIDTH
    local sy = love.graphics.getHeight()/SC_HEIGHT

    love.graphics.setShader(repeatShader)
        love.graphics.draw(starCanvas,0,0,0,sx,sy)
    love.graphics.setShader()
The result (with this new shader the stars will always remain at the same scale, no matter the size of the window):
Image

Afterwards, nothing to see, but I thought that in your case, enlarging the window would mean enlarging the field of vision? Wouldn't it be better to completely rescale the render, while keeping the ratio if that matters? If you want I just published a little gist as an example if you want to get inspired and see what I mean: https://gist.github.com/Bigfoot71/c7a79 ... ba4a198891

Re: Block Dash 1.0 is Out Now!

Posted: Tue Apr 18, 2023 8:01 am
by pyxledev
Bigfoot71 wrote: Mon Apr 17, 2023 9:29 pm
Finally managed to get it working, thank you :)

Response to the last question: While programming the resizing window and the UI, I didn't know how to work with canvases and ended up keeping every scale the same, with only the UI moving dynamically as you resize. Plus I wanted the window to be resizable to every dimension and not only 16:9. Even if there is a way to do that better I don't think I'll be changing the code.

Re: Block Dash 1.0 is Out Now!

Posted: Tue Apr 18, 2023 9:06 am
by darkfrei
pyxledev wrote: Tue Apr 18, 2023 8:01 am Even if there is a way to do that better I don't think I'll be changing the code.
Maybe high DPI canvases?
https://love2d.org/wiki/love.graphics.newCanvas

Code: Select all

 settings ={dpiscale = 2} -- twice×twice bigger, but same size canvas
canvas = love.graphics.newCanvas( width, height, settings )

Re: Block Dash 1.0 is Out Now!

Posted: Tue Apr 18, 2023 10:55 am
by Bigfoot71
pyxledev wrote: Tue Apr 18, 2023 8:01 am Response to the last question: While programming the resizing window and the UI, I didn't know how to work with canvases and ended up keeping every scale the same, with only the UI moving dynamically as you resize. Plus I wanted the window to be resizable to every dimension and not only 16:9. Even if there is a way to do that better I don't think I'll be changing the code.
This is understandable, especially if you have already written all the calculations necessary for the adaptation of the interface, but in case I made myself misunderstood, because my message yesterday was not super clear, here is what I meant (I changed the background color to make it more meaningful. And uh... Don't pay attention to the background code that doesn't make any sense, haha):
Image

In this example I used the gist that I shared with you, and put the division by the screen dimensions back in the shader to keep everything at scale. Then, depending on the resolution of the window, the display is centered and black bands are placed where necessary to always keep the same field of vision.

Once implemented, this represents less work than constantly recalculating the positions of each interface object, or you could make the code heavier by recalculating this in love.resize, but then you might as well recalculate only the rendering scale. And with this technique, you don't have to worry about canvases, etc. You only work on the game's base resolution (e.g. 800x600) and everything will be scaled by the GPU at display time, so your code won't need to change.

Then if you want to let the player choose between 16:9 and 4:3 without rescaling the rendering of the world, unfortunately yes, the field of vision cannot always remain exactly the same, it's a design choice who is yours ^^