1. alterecco
  2. MarkOne

Commits

alterecco  committed c544886

player position is now a vector

  • Participants
  • Parent commits 559c55d
  • Branches master

Comments (0)

Files changed (1)

File main.lua

View file
  • Ignore whitespace
 require 'lib/fizz'
 require 'lib/AnAL.lua'
 
-class = {}
-class.map = require 'lib/map.lua'
-
-player = {
-	x = 0,
-	y = 0,
-	w = 26,
-	h = 54,
-	physBox = nil,
-	anim = nil,
-	controlSet =  {up = "w", left = "a", down = "s", right = "d"},
-	images = {},
-	facing,
+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
+	, 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)
+			player.physBox.yv = -5000 
+			love.audio.play(pl_jump)
 			end
-		else
+			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.x = player.physBox.x
-		player.y = player.physBox.y
-	end,
-	draw = function()
-		player.anim:draw(player.x - player.w / 2 - camera.x, player.y - player.h / 2 - camera.y)
-		
-		love.graphics.setColor(127,255,127, 100)
-		camera.rectangle("fill", player.x-player.w/2,player.y-player.h/2, player.w, player.h)
-		love.graphics.setColor(0,0,0, 127)
-		camera.rectangle("line", player.x-player.w/2,player.y-player.h/2, player.w, player.h)
-	end,
-}
+			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 = class.map("map002")
+
+	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.x, player.y, player.w, player.h, 3)
+	player.physBox = fizz.addDynamic("rect", player.pos.x, player.pos.y, player.w, player.h, 3)
 	player.physBox.hover = 0.5
-	player.x = map.data.player.x * 64
-	player.y = map.data.player.y * 64
+
+	-- 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.mp3")
 	pl_jump:setVolume(1)
 	-- Some music
 	player.update(dt)
 	
 	local mouseAimMul = 0.8
-	camera.x = (player.x - 400 + (love.mouse.getX() - 400) * mouseAimMul - camera.x) * dt * 5 + camera.x
-	camera.y = (player.y - 320 + (love.mouse.getY() - 320) * mouseAimMul - camera.y) * dt * 5 + camera.y
+	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()