STI and Making My 1st Platformer

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
uemtux
Prole
Posts: 1
Joined: Wed Dec 02, 2020 4:33 am

STI and Making My 1st Platformer

Post by uemtux »

Hi Folks,

I recently started playing around with Love. I come from more of a backend coding background, PHP and NodeJS sort of stuff, and I've never coded a game before. (I did used to do Quake mods, many many years ago)

A friend and I decided to work on a game together, so a bit of research later and I found Simple Tiled Implementation and the basic "top down rpg" tutorial: https://github.com/karai17/Simple-Tiled ... -to-sti.md

I used this to get my "engine" (such as it is) loading maps made in Tiled, and I figured out enough from just reading docs and examples that I figured out how to scroll the map around the viewport. My question for you folks is... how do I get a sprite into my map that collides with the tiles I choose, is affected by gravity, and can move and jump? I'm rendering a map and moving the "camera" so I seem to be moving in a good direction, but I find the STI docs a bit opaque and am having trouble finding good examples.

I used to do QuakeC, so movement physics aren't completely alien to me, so with that in mind, what do you folks suggest? Where do I start? How do I get a sprite spawned, accelerating downwards when there's nothing under it, and how do I identify what kinda tile is under its feet?

Thanks in advance for helping a noob learn the ropes.

Code: Select all

-- load simeple tiled implementation library
local sti = require "sti"


-- viewport offsets for now
map_y = 0;
map_x = 0;


function love.load()
	-- set viewport
	love.window.setMode( 1280, 720, {minwidth=1280, minheight=720} )
	-- Load map file
	map = sti("assets/1080.lua")
end

function love.update(dt)

	--scroll map
	if love.keyboard.isDown("up") then
		map_y = map_y + 5
	end
	
	if love.keyboard.isDown("down") then
		map_y = map_y - 5
	end
	
	if love.keyboard.isDown("left") then
		map_x = map_x + 5
	end
	
	if love.keyboard.isDown("right") then
		map_x = map_x - 5
	end
	


	-- Update world
	map:update(dt)
end

function love.draw()
	-- Draw world
	map:draw(map_x, map_y)
end
User avatar
darkfrei
Party member
Posts: 1178
Joined: Sat Feb 08, 2020 11:09 pm

Re: STI and Making My 1st Platformer

Post by darkfrei »

Such code maybe better:

Code: Select all

if love.keyboard.isDown("left") then
	map_x = map_x + 5*dt*60
elseif  love.keyboard.isDown("right") then
        map_x = map_x - 5*dt*60
end
On 60 fps the dt is about 1/60, but it goes up on the lower fps.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1088
Joined: Thu Dec 10, 2020 1:57 am

Re: STI and Making My 1st Platformer

Post by Gunroar:Cannon() »

You could use the bump or box2d plugins mentioned in examples and the docs.
I recommend bump because it's easier and more managable for platformers and rpgs.
Just include a bump world to the map.

Code: Select all

 STI(path,{"bump"})
I think.
Last edited by Gunroar:Cannon() on Tue Dec 15, 2020 3:32 pm, edited 1 time in total.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Gunroar:Cannon()
Party member
Posts: 1088
Joined: Thu Dec 10, 2020 1:57 am

Re: STI and Making My 1st Platformer

Post by Gunroar:Cannon() »

Learn more about bump : https://github.com/kikito/bump.lua
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

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