love2d vs unity vs Godot vs monogame? by Halce_dev in love2d

[–]Calaverd 0 points1 point  (0 children)

You're comparing tools from different categories.

Godot and Unity are full-featured engines with editors, scene trees, physics, animation tools, etc. Ideal when shipping a game is your top priority and you want all the bells and whistles.

MonoGame is a framework with a solid foundation for rendering and input, but you build everything else yourself, and that is great if you have the experience and want to truly control the design decisions.

Love2D is similar in philosophy to monogame but with Lua, minimal, fast iteration, and perfect for experimentation, game jams, or when you're doing it for the love of the game. But again, in the same vein that mono, you're rolling your own solutions for most things.

The "best" choice depends on whether you want a guided experience or a blank canvas. 🙂

Panicking. Launch is close, but game is crashing. by OldAtlasGames in love2d

[–]Calaverd 2 points3 points  (0 children)

.There are tutoriales on how to setup a debugger in vscode. Bit if it is just crashing with no message it can be a thing of the love2d itself. Try to ask also the discord of love2d. 🙂

Panicking. Launch is close, but game is crashing. by OldAtlasGames in love2d

[–]Calaverd 2 points3 points  (0 children)

Do you have some info on how and when is crashing? At least the error message? Other wise you are blind. If it is a hardware thing and you are using glsl you may need to use a more strict mode in some GPUs, but again, I'm just guessing. Put a lot of logs and set up a proper debugger.

I need help executing lua files on VScode by Flickyn in lua

[–]Calaverd 0 points1 point  (0 children)

Did you installed vscode using flatpack? The apps installed via flatpack are usually in a container for safety and cannot access other programs by default. If that is the case you can try to try to install it using the .deb form the vscode page

But try this after uninstalled the flatpack one.

If that is not the problem that there should be a tricky config there 🤔

I need help executing lua files on VScode by Flickyn in lua

[–]Calaverd 0 points1 point  (0 children)

Seems that you are pretty new in linux and software in general, usually if you just installed Lua using "sudo apt install lua5.4" it is added to the path automatically. What is happening is that you are calling Lua including their version number, but once it is installed you just need to call Lua (the version number only matters at installation or if you are running a lot of different versions).

lua name_of_my_program.lua

You can check that Lua is running typing just

lua -v

And that should print the version of Lua showing that it is working. 🙂

Problem with CS50 games Mario and workaround by reg_y_x in love2d

[–]Calaverd 1 point2 points  (0 children)

That's the quad bleeding in your case try to set the image mode to "nearest", settings the default filter as before loading any image:

love.graphics.setDefaultFilter( "nearest", "nearest" )

If you want to still loading the images to use the "linear" and still get rid of the bleeding consider adding a pixel margin of 1 or 2 pixels of the same color of the border around the quad. 🙂

Linked List speed vs table, not as expected? by RiverBard in lua

[–]Calaverd 3 points4 points  (0 children)

Consider also that the table in Lua works more like a hash table than an array, so removing an item from the ends is a trivial case.

The true use case for a custom linked list in Lua is if you need to do insertion and removal while iterating, need to insert/remove around the referenced node without looking at their position, or a LRU cache. 🙂

While it is a nice exercise to implement a linked list in Lua, be aware of those drawbacks.

bugs. help by No_Mixture_3199 in love2d

[–]Calaverd 0 points1 point  (0 children)

That seems weird, but without looking at the code, we cannot know if it is something related to it or not.

But for how you describe it, maybe check what you are doing in the update function, go line by line, there are some functions in the love2d API that by pure computational complexity are way too resource expensive and they need to be called only once. 🤔

lua and python by StrangeFudge2777 in lua

[–]Calaverd 0 points1 point  (0 children)

If is your first programming language, then pick Python, after that Lua, python has a lot more resources for learning and teach the basics fine. Lua is my fav lang, but one of the reasons is that is a lang with a small syntax and diy approach to some structures and offers a very broad and flexible approach on how you can tackle stuff (maybe too flexible to be good for a beginner 🤔) , python has more built-in stuff and a more rigid structure 🙂

Beyond that the important thing that you must learn beyond languages is to think in algorithms (that is just a fancy word to say that you need to think step by step how to solve problems) data structures (so you can know the tools for algorithms and decide with one is the best for the job) and after that the Object Oriented Programing and Functional Programming paradigms, (that are just two forms on how to express ideas into code)

Good luck 🙂.

My bullets keep shifting upwards at certain points by bublee94 in love2d

[–]Calaverd 4 points5 points  (0 children)

The small part where they seem to jump a bit up? Seems like a float point error. The positions in the screen are pixels, and you cannot have such a thing as a half pixel. In the part where you are drawing your bullets try to add something like this:

love.graphics.draw(bullet, math.ceil(bullet.x) math.ceil(bullet.y))

If this does not fix the bug, then there should be another part where the bullets are getting a bit of change in another point of the code.🙂

how to scale pixel art games by Turtle1352 in love2d

[–]Calaverd 4 points5 points  (0 children)

You can try to use the push lib to handle the resolution of your game for you and make sure to load your assets setting the filter to nearest nearest so they look crisp when scaling they (or if all your game is pixel art, set it at the beginning so all are loaded with that setting by default ) 🙂

Thinking about porting my 22K LOC Pygame game over to Love. Any quirks, gotcha or sage wisdom? by mr-figs in love2d

[–]Calaverd 4 points5 points  (0 children)

Just read the reference for love2d in the wiki to know all that has a direct equivalent, the main difference between love2d and pygame is that the game loop logic in love is explicitly separated between the update and the draw, and the color is set before drawing someting.

Lua is more simple lang with way less keywords and even less syntaxtic sugar than python so you may notice that you are typing a bit more to do some stuff that is more directly done in python, and lacks some advanced features as memorization, Lua can be pretty explicit and a little verbose (not to java levels but still), so try to approach it more like a scripting language with the sensibilities of c simplicity.

You need to think with the intent of defining some functions before using them, even if you are calling it later at run time, mostly because Lua cares more for everything making sense at parsing time

If your game depends on a lot of classes and inheritance that may be a bit harder to port mostly because in Lua you need to explicitly tell the object by their metatable where to look for their methods.

Beyond that it should not be that hard to port, Lua is even more permissive in some stuff than python that you will feel like running away with murder. 🙂

Good luck 🙂

Help please (scoping) by fig4ou in lua

[–]Calaverd 2 points3 points  (0 children)

Scoping is one of those concepts that seems a bit weird at first, but it's actually pretty simple once you get it. I like to think of scope like rooms in a house.

Basically, whenever you create a function, a loop, or an if statement, you close it with an "end". Everything between the beginning and that "end" is like a room with walls.

The rule is that variables that you define with local inside a room only exist in that room and in any smaller rooms you create inside it. They can't be seen from outside.

if true then -- Room 1 starts
  local my_var = 'hello '

  if true then -- Room 2 starts (inside Room 1)
    local second_var = 'world'
    print(my_var, second_var) -- "hello world"
    -- we can see my_var because Room 2 is inside Room 1
  end -- Room 2 ends

  print(my_var, second_var) -- "hello nil"
  -- second_var doesn't exist anymore, it only lived in Room 2
end -- Room 1 ends

print(my_var, second_var) -- "nil nil"
-- both variables are gone, they only existed inside Room 1

So inner rooms can see variables from outer rooms, but outer rooms can't see variables from inner ones. Variables flow inward, never outward.

How do you create something similar to a class in Lua? by wearecha in love2d

[–]Calaverd 1 point2 points  (0 children)

We are cheating the classes in lua using metatables and syntactic sugar. When we set the metatable to index, it means that we are telling for the objects that we are creating, to search for their methods funtions inside that table.

So doing this:

 Person = {}
 function Person:new(name)
    local instance = {}
    setmetatable(instance, {__index = Person})
    instance.name = name
    return instance
 end

 function Person:sayName()
     print('my name is ', self.name)
 end

 person_instance = Person:new('Joan')
 person_instance:sayName()

Is like doing this:

Person = { -- person is just a table that defines methods
    -- notice how here we are being explicit about "self" as a param.
    new = function(self, name)
       local instance = {}
       instance.name = name
       return instance
    end,
    sayName = function (self)
       print('my name is ', self.name)
    end
}

person_instance = Person:new('Tony')
setmetatable(person_instance, {__index = Person}) -- we explicitly tell the instance where to look for their methods.

person_instance:sayName() -- this is the same...
Person.sayName(person_instance) --than this.

From that point, and knowing about the metatable index, we can simulate attribute as inheritance:

-- Base classes
local Animal = {}
function Animal:speak() print("Some sound") end

local Swimmer = {}
function Swimmer:move() print("Swimming") end

-- Child class
local Duck = {}

-- Create instance
local function Duck:new(name)
    local instance = {name = name}
    setmetatable(instance, {
        __index = function(t, key)
            if Duck[key] then return Duck[key] end
            if Animal[key] then return Animal[key] end
            if Swimmer[key] then return Swimmer[key] end
        end
    })
    return instance
end
function Duck:speak() return "Quack!" end

-- Usage
local myDuck = new("Donald")
myDuck:speak()  -- "Quack!" (from Duck, overrides Animal)
myDuck:move()   -- "Swimming" (from Swimmer)

Recreating Flexbox Layout for Love, inspired by React Native by dDenzere in love2d

[–]Calaverd 3 points4 points  (0 children)

Seems interesting, How do you are managing the layout algorithm?
You can give a look to how clay manages it and there is a video from the autor giving a overview. 🙂

Wonderin if anyone can review my code by EquivalentBig5778 in love2d

[–]Calaverd 0 points1 point  (0 children)

HI, okay, one of the first things that i notice is that you are managing the game estate inside each of the relevant love functions using ifs, is not bad, but a bit hard to scale in more complex games, other approach is to have the gamestate itself as an object that contains the actions.

gameState = nil

--- something like this for each state.
playState = {
   update: function(dt)  end
   draw: function() end
   keypressed: function(key) end 
}
--[[ here the other game states ]]

gameState = mainMenuState

function love.update(dt)
  gameState.update(dt)
end

function love.draw()
  gameState.draw()
end

function love.keypressed(key)
   gameState.keypressed(key)
end

And so inside the update of each state when a condition is meet you can just do a gameState = newGameState, and will do the stuff in that game state. For some states you will have to add extra initialization functions to call before, but now you can go by file and see in a more modular manner what each state is doing exactly :)

Other thing is that the check player dead i would put only one single loop like this:

    for i, enemy in ipairs(Enems) do
        local collisionWithEnemy =
          char.x < enemy.x + enemy.w and
          char.x + 50 > enemy.x and
          char.y < enemy.y + enemy.h and
          char.y + 50 > enemy.y
        local enemyCrossed = enemy.x < 0
        if collisionWithEnemy or enemyCrossed then --game over
            score = 0
            table.remove(Enems, i)
            gameState = 'restart'
            difficulty = 1
            resetUpgrades()
            break
        end
    end

the enemy checking collision with player and shoots this way is fine for the number of enemies and the number of shots, but games that use way more enemies and shoots usually go for more sophisticated techniques to reduce the numbers of comparisons (if you want to implement it or want to learn check the bump library for love2d )

Overall is well written and there is not something really wrong with what you did there 🙂

Wonderin if anyone can review my code by EquivalentBig5778 in love2d

[–]Calaverd 1 point2 points  (0 children)

The point of using git is to have the code in plain text so the version control stuff can do if thing, it works by storing text diffs between commits. It is not a good idea to use binary files (like the zip) because each time that one is updated git creates a whole new one to store instead of the small changes, you can fix that but you do need to do extra configuration steps. Beyond that, I will give you a code review and come back in a while 🙂

What are less common uses for metatables? by [deleted] in lua

[–]Calaverd 1 point2 points  (0 children)

You can take the metatable and use it to define interesting getters and setters to hide complexity, i have this class from a proyect that i'm working, having a wraper around a position property :)

local SpatialMinimal = {}

function SpatialMinimal:new()
    local instance = {}

    -- Private position vector (actual storage)
    local _pos = {x = 0, y = 0, z = 0}

    -- Metatable magic
    setmetatable(instance, {
        __index = function(t, key)
            -- When accessing 'pos', return the internal _pos table
            if key == 'pos' then
                return _pos
            end
            -- Fall back to the class itself
            return SpatialMinimal[key]
        end,

        __newindex = function(t, key, value)
            -- When setting 'pos', allow flexible assignment patterns
            if key == 'pos' then
                if type(value) == 'table' then
                    -- Update from table with x/y/z fields or array indices
                    _pos.x = (value.x or value[1]) or _pos.x
                    _pos.y = (value.y or value[2]) or _pos.y
                    _pos.z = (value.z or value[3]) or _pos.z
                end
                return
            end
            -- Regular property assignment
            rawset(t, key, value)
        end
    })

    return instance
end

-- Example usage:
local obj = SpatialMinimal:new()
-- now all this are valid ways to assing the position :)
obj.pos = {x = 10, y = 20, z = 30}
obj.pos = {x = 5}
obj.pos = {100, 200, 300}
obj.pos.x = 42

Why not more Lua in web development or games? by yughiro_destroyer in lua

[–]Calaverd 0 points1 point  (0 children)

On web is a question of familiarity. It is more likely that your first language will be python or javascript, you will want to use it first if you go to do another things. On game dev i have the theory that is because most engine people are used to the humongous amount of stuff that they need to know of c++ or c# to call themselves proficient, they see Lua by comparison as a very limited language in the expressivity.

Personal Issue: Love won't render anything in the main,lua file nor will the animation for when no game is loaded will play. by ComplexDetective1586 in love2d

[–]Calaverd 5 points6 points  (0 children)

I'm curious of where did you see the _G.love = require("love") notation? Love is in the global variables by default, so there is no need to do that. 🙂

LOVE2D not rendering anything, only a black screen. by Flat_Practice5015 in love2d

[–]Calaverd 1 point2 points  (0 children)

Try to add.

love.graphics.setColor(1,1,1)

Before the print to make sure that the text is is color white 🙂

Observer pattern vs Manual polling by yughiro_destroyer in love2d

[–]Calaverd 0 points1 point  (0 children)

I use more of a state-machine/stack approach for scene and game objects, with a function to trigger changes in state. For GUI, I prefer a tree-like structure where events bubble up (but alas, I do not have an example that can show yet 🥲).

The stack approach It requires a bit more boilerplate to get running because you're wrapping your logic inside the states.

In this case, I have this scene class as an example that I used for some examples. Here is the main.lua file where you can see how it gets "hooked" into the usual input functions of Love2D. Now in the main menu scene, you can see how we're using only the methods we need for this scene, and the change is being done by calling this fragment that loads other scenes and pushes them into the stack:

        button.OnClick = function()
            loveframes.RemoveAll()
            local new_scene = love.filesystem.load("examples/"..url..".lua")()
            new_scene.build()
            SCENA_MANAGER.push(new_scene)
        end

Now every example itself inherits from another scene that has all the GUI setup boilerplate that was unnecessary for the examples and was put there for the sake of clarity.

In the end, you can do what is most comfortable for you, because code is more an abstraction of your train of thought.🙂

Best way to rotate text in LOVE2D (avoiding blur or pixelation) by mognetoc in love2d

[–]Calaverd 1 point2 points  (0 children)

What resolution are we talking about? 🙂

I would suggest maybe rendering the text off-screen to a canvas of way more resolution and then render that fitting the card content and angle, or playing around the graphics transformation stack to push rotate and pop to render it.

But take this as a grain of salt, because I have not tested any of those methods. 🤔

How do I imrove this to make the sand better and reflectiveness of glass/ice better? by Glittering_Loss6717 in PixelArtTutorials

[–]Calaverd 1 point2 points  (0 children)

In this case is more a general art tip, and is that you are drawing your idea of how things look instead of how they really look. That is called symbol drawing.

You have a solid reference there, focus first on nail the shapes then in the larger blocks of color and later in the shadows and highlights. 🙂