Source

MarkOne / main.lua

Full commit
require 'tiles'
require 'lib/fizz'
require 'lib/AnAL.lua'

local Vector = require 'lib/hump/vector'
local Map = require 'lib/map'

player = 
	{ pos = Vector(0,0)
	,	w = 26
	,	h = 54
	,	physBox = nil
	,	anim = nil
	,	controlSet =  {up = "w", left = "a", down = "s", right = "d"}
	,	images = {}
	,	facing
	
	
	
	, update = function(dt)
			local up = love.keyboard.isDown(player.controlSet.up)
			local left = love.keyboard.isDown(player.controlSet.left)
			local down = love.keyboard.isDown(player.controlSet.down)
			local right = love.keyboard.isDown(player.controlSet.right)
			player.facing = right

			player.physBox.xm = left and -2000 or right and 2000 or 0
			player.physBox.ym = up and -2000 or down and 2000 or 0
			--[[
			if fizz.isTouching(player.physBox) then
			if up then 
			player.physBox.yv = -5000 
			love.audio.play(pl_jump)
			end
			else
			player.physBox.xm = player.physBox.xm/2
			player.physBox.ym = (love.keyboard.isDown("w") and player.physBox.yv<0) and -1000 or 0
			end]]

			player.anim:setSpeed(math.abs(player.physBox.xv) / 128)
			player.anim:update(dt)

			player.pos.x = player.physBox.x
			player.pos.y = player.physBox.y
		end
	, draw = function()
			player.anim:draw(player.pos.x - player.w / 2 - camera.x, player.pos.y - player.h / 2 - camera.y)

			love.graphics.setColor(127,255,127, 100)
			camera.rectangle("fill", player.pos.x-player.w/2,player.pos.y-player.h/2, player.w, player.h)
			love.graphics.setColor(0,0,0, 127)
			camera.rectangle("line", player.pos.x-player.w/2,player.pos.y-player.h/2, player.w, player.h)
		end
	}

function love.load()
	love.graphics.setBackgroundColor(255, 255, 255)

	map = Map("map002")
	-- map = Map("test1")
	map:load()

	dynamics = {}

	-- place player on spawn tile
	player.pos = (map.data.player * map.data.tileset.width) + Vector(map.data.tileset.width/2, 0)

	-- player related things
	player.images.walk = love.graphics.newImage("assets/tiles/character/walk.png")
	player.anim = newAnimation(player.images.walk, 26, 53.5, 0.15, 0)
	player.physBox = fizz.addDynamic("rect", player.pos.x, player.pos.y, player.w, player.h, 3)
	player.physBox.hover = 0.5

	-- player.pos.x = map.player.x * 64
	-- player.pos.y = map.player.y * 64
	-- quit immediately
	-- love.event.push("q")
	
	
	pl_jump = love.audio.newSource("assets/audio/pl_jump.wav")
	pl_jump:setVolume(1)
	-- Some music
	music = love.audio.newSource("assets/audio/nysang.mp3") music:setVolume(0.5) love.audio.play(music)
end

function love.update(dt)
	dt = math.min(dt, .05)
	fizz.update(dt)
	player.update(dt)
	
	local mouseAimMul = 0.8
	camera.x = (player.pos.x - 400 + (love.mouse.getX() - 400) * mouseAimMul - camera.x) * dt * 5 + camera.x
	camera.y = (player.pos.y - 320 + (love.mouse.getY() - 320) * mouseAimMul - camera.y) * dt * 5 + camera.y
end

function love.draw()
	map:draw()
	player.draw()

	--Debug
	--[[
	for k,v in ipairs(tileset.static) do
		local x,y, w,h = v.x, v.y, v.w, v.h
		love.graphics.setColor(127,255,127, 100) camera.rectangle("fill", x-w/2,y-h/2, w,h)
		love.graphics.setColor(0,0,0, 127) camera.rectangle("line", x-w/2,y-h/2, w,h)
	end

	for k,v in pairs(dynamics) do
		local x,y, w,h = v.x, v.y, v.w, v.h
		love.graphics.setColor(191,191,255, 255)
		camera.rectangle("fill", x-w/2,y-h/2, w,h)
		love.graphics.setColor(0,0,0, 127)
		camera.rectangle("line", x-w/2,y-h/2, w,h)
	end]]
	
	-- Draw the current FPS.
	love.graphics.print("FPS: " .. love.timer.getFPS() .. " - DT: " .. love.timer.getDelta(), 10, 10)
	love.graphics.setColor(255,255,255,255)
end

function love.keypressed(k)
	if k=="escape" then love.event.push("q")
	elseif k=="z" then spark = love.audio.newSource("assets/audio/spark.ogg") spark:setVolume(1) love.audio.play(spark) table.insert(dynamics, fizz.addDynamic("rect", love.mouse.getX() + camera.x, love.mouse.getY() + camera.y, 64, 64))
	elseif k=="x" then kill = love.audio.newSource("assets/audio/megasphere_pickup.ogg") kill:setVolume(1) love.audio.play(kill) for k,v in ipairs(dynamics) do fizz.remove(v) dynamics[k]=nil end
	elseif k=="c" then for k,v in ipairs(dynamics) do fizz.disable(v) end
	elseif k=="v" then for k,v in ipairs(dynamics) do fizz.enable(v) end
	end
end























camera = {
	x = 0,
	y = 0,
	drawq = function(image, quad, x, y, r, sx, sy, ox, oy)
		x = x - camera.x
		y = y - camera.y
		love.graphics.drawq( image, quad, x, y, r, sx, sy, ox, oy )
	end,
	draw = function(...)
		
	end,
	rectangle = function(mode, x, y, width, height)
		x = x - camera.x
		y = y - camera.y
		love.graphics.rectangle( mode, x, y, width, height )
	end
}