Page 1 of 1

Platformer help

Posted: Thu Apr 09, 2015 6:55 pm
by fboeft
Hello,

I am very new here. I am making a small platformer.
I have a tiled map. and i loaded it into my code. I also used adv tiled collider.
First of all i am not really sure if my collision stuff is okay. And i need help scaling up my map.

This is my code:

Code: Select all

function love.load()
	
	atl = require 'libs.ATL'
	atlMap = atl.Loader.load 'assets/maps/map.tmx'
	entity = require 'libs.atc.atc'

	player = entity.new(100, 100, 8, 8, atlMap,select(2,next(atlMap.layers)))
	playerSkin = love.graphics.newImage("assets/player/Hero_Idle.png")

	function player:isResolvable(side,tile,gx,gy)
		
		local tp = tile.properties

		if tp.type == 'solid' then
			if side == 'Ground' then floorFound = true; vy = 0 end
			return true
		end

		if (tp.type == 'slopeUp' or tp.type == 'slopeDown') and side == 'bottom' then
			vy = 0
			floorFound = true
			return true
		end

		if tp.type == 'ceilingDown' and side == 'right' then
			return true
		end

		if tp.type == 'ceilingUp' and side == 'left' then
			return true
		end
	end

	local h = {}; local h2 = {}
	for i = 1,32 do
		h[i] = i
	end
	for i = 1,32 do
		h[i] = 33-1
	end

	for id,tile in pairs(atlMap.tiles) do
			local tp = tile.properties
			if tp.type == 'slopeUp' then
					tp.verticalHeightMap = h
			elseif tp.type == 'slopeDown' then
					tp.verticalHeightMap = h2
			elseif tp.type == 'ceilingUp' then
					tp.horizontalHeightMap = h2
			elseif tp.type == 'ceilingDown' then
					tp.horizontalHeightMap = h2
			end
	end

	inAir = true
	vx, vy = 200,0
	gravity = 200

end

function love.mousepressed(x,y,k)
	if k == 'l' then player.x = x-player.w/2; player.y = y-player.h/2 end
end

function love.update(dt)
	if love.keyboard.isDown('a') then
			dx = -vx*dt
	elseif love.keyboard.isDown('d') then
			dx = vx*dt
	else
			dx = 0
	end

	vy = vy + gravity*dt
	dy = vy*dt+gravity*dt^2/2

	if not inAir and love.keyboard.isDown('w') then
			inAir = true
			vy = -vx
			dy = vy*dt
	end
	floorFound = false
	player:move(dx,dy)
	if not floorFound then inAir = true else inAir = false end
end

function love.draw()
	atlMap:draw()

	love.graphics.draw(playerSkin, 300, 300, 0, 4)
	playerSkin:setFilter("nearest")
end

Re: Platformer help

Posted: Fri Apr 10, 2015 2:59 pm
by Jeeper
ATL (Advanced Tile Loader) is very old and no longer up to date. I would strongly suggest that you use STI (Simple Tiled Implementation), Check it out here: viewtopic.php?f=5&t=76983

Re: Platformer help

Posted: Fri Apr 10, 2015 6:00 pm
by bobbyjones
Also posting a .love would be a very lovely thing to do. Also someone else just mentioned you should use STI. Once you do that we can help with the physics hopefully. :)