I'm having a hard time wrapping my head around bump.lua

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
rgbmew
Prole
Posts: 2
Joined: Sun Oct 10, 2021 1:04 am

I'm having a hard time wrapping my head around bump.lua

Post by rgbmew »

Hi, I'm obviously new to Löve & Lua, but not new to programming in general. I've used Gamemaker Studio 1 & 2 since 2014, but I recently switched to Linux and had endless problems with getting them to run under Wine, so I decided to give Löve a shot.
I've spent most of today learning about Lua and Löve syntax, but I just can't figure out the proper usage of Bump. I've read a bunch of guides, both on this forum and the entire GitHub page, but it's just not really clicking with me. What I'm used to, from using Gamemaker for so long, is checking collision with place_meeting. For people that haven't used GML, place_meeting's usage is like this:

Code: Select all

if place_meeting(x,y,object){ }
Which works great for how Gamemaker is set up. Every viewable and interactable "instance" is called an "Object" and every "Object" has it's own x and y coordinates built-in. So parameters 1 and 2 are for where you want to check for collision, and parameter 3 is for the Object you plan on colliding the Object containing the code with.

Now that that's all out of the way, onto my confusion with Bump.
I somehow managed to get basic collisions working with Bump, but I don't completely understand how they work still? What I assume is happening, at least in my usage of it (below), is that it stops player.x and player.y from being changed if collision is detected, but I'm not completely understanding *how* collision is BEING detected.

main.lua

Code: Select all

local STI = require "sti"
local bump = require "bump"
require("player")

function lerp(pos1, pos2, perc)
    return (1-perc)*pos1 + perc*pos2
end

function bool_to_number(value)
    return value and 1 or 0
end  

function love.load()
    map = STI("map/map1.lua", {"bump"})
    world = bump.newWorld(16)
    map:bump_init(world)
    player:load()
    world:add(player, player.x, player.y, player.w, player.h)
end

function love.update(dt)
    map:update(dt)
    player:update(dt)
end

function love.draw()
    love.graphics.setBackgroundColor(0.5,0.5,0.5)
    map:draw(0,0,1,1)
    player:draw()
end

player.lua

Code: Select all

player = {}

function player:load()
    self.x = 40
    self.y = 40
    self.w = 12
    self.h = 12
    self.hspd = 0
    self.vspd = 0
    self.movespd = 40
    self.fric = 30
    self.spdmax = 125

end

function player:update(dt)
    if love.keyboard.isDown("left") or love.keyboard.isDown("right") then
        if math.abs(self.hspd) <= (self.spdmax)*dt then
            self.hspd = self.hspd+((self.movespd*dt)*(bool_to_number(love.keyboard.isDown("right"))-bool_to_number(love.keyboard.isDown("left"))))
        else
            self.hspd = ((self.spdmax*dt)*(bool_to_number(love.keyboard.isDown("right"))-bool_to_number(love.keyboard.isDown("left"))))
        end
    else
        self.hspd = lerp(self.hspd,0,self.fric*dt)
    end

    self.x, self.y = world:move(self,self.x+self.hspd,self.y+self.vspd) 
end

function player:draw()
    love.graphics.setColor(1,0,0)
    love.graphics.rectangle("fill",self.x,self.y-self.h,self.w,self.h)
end
I understand that Bump is used by creating a sort of "index" for the objects that collide, but I'm just not understanding how they interact.
Specifically, I'm trying to write code that will check if there is a wall to the left/right of the player while they're moving, so I can set the player.hspd/player.vspd variables to 0, but I don't understand how to check for that?
In Gamemaker, I would just do:

Code: Select all

if place_meeting(x+hspd+(1*sign(hspd)),y,solid){
	hspd = 0
}
and that would do all the work for me. It simply checks ahead of the player for a solid object. But there doesn't really seem to be any kind of.... "replacement" for precision collision checking like that in Bump? Like, if I wanted to check 1 pixel below player.y to check if my player was grounded, I don't understand how that would be accomplished.

Apologies for such a long post, I wanted to be as verbose as possible with my understanding of Bump, and my history of coding to explain *why* I'm having a hard time understanding it.
I don't understand what .love files are for, if they are a way to access your source code, or if they're just a standard build of the game with obfuscated code, but I've added one anyway just in case. Either way, ALL the code for my game (excluding STI and Bump obviously) is included above.
loveplatformertest.love
(31.25 KiB) Downloaded 333 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests