-- Quote
function obj150init()
	if (obj.equip(64)) then
		obj.yoff(2*TILE) -- Mimiga mask
	end

	-- Default gun frame and offsets
	if (obj.dir() == 2) then
		obj.gun_frame(1)
		obj.gun_x(0)
	else
		obj.gun_frame(0)
		obj.gun_x(-8)
	end
	obj.gun_y(0)
end
function obj150()
	local maxspeed = 1.5*FRACUNIT
	local acceleration = FRACUNIT/10
	local movetype = 2

	if (obj.equip(64)) then
		obj.yoff(2*TILE) -- Mimiga mask
	else
		obj.yoff(0)
	end

	-- Cutscene character stuff
	if (obj.keypress("client") ~= true) then
		if (obj.anim() == 10) and (obj.tics() == 1) then
			sfx(71)
		elseif (obj.anim() == 50) or (obj.anim() == 51) then
			if (obj.dir() == 2) then
				obj.x(obj.x()+FRACUNIT)
			else
				obj.x(obj.x()-FRACUNIT)
			end
			obj.momx(0)
			obj.momy(0)
			if (obj.do_collisions(false)) then
				if (obj.dir() == 2) then
					obj.x(obj.x()-FRACUNIT)
				else
					obj.x(obj.x()+FRACUNIT)
				end
			end
		end
		return
	end

	-- Playable character stuff from here down --

	if (movetype == 0) then
		-- Walking movement. Cave Story officially does it this way, apparently, though I dunno if the nofriction even exists in it.
		-- Turns to the right and walks in place when both keys are down.
		if (obj.keydown("left")) then
			if (obj.momx() > -maxspeed) then
				obj.momx(obj.momx()-acceleration)
				if (obj.momx() < -maxspeed) then
					obj.momx(-maxspeed)
				end
			end
			obj.dir(0)
		end
		if (obj.keydown("right")) then
			if (obj.momx() < maxspeed) then
				obj.momx(obj.momx()+acceleration)
				if (obj.momx() > maxspeed) then
					obj.momx(maxspeed)
				end
			end
			obj.dir(2)
		end
	elseif (movetype == 1) then
		-- My way of handling two keys pressed at once.
		-- Allows for moonwalking by tapping one direction while holding the other.
		if (obj.keydown("left")) and (not obj.keydown("right")) then
			if (obj.momx() > -maxspeed) then
				obj.momx(obj.momx()-acceleration)
				if (obj.momx() < -maxspeed) then
					obj.momx(-maxspeed)
				end
			end
		elseif (obj.keydown("right")) and (not obj.keydown("left")) then
			if (obj.momx() < maxspeed) then
				obj.momx(obj.momx()+acceleration)
				if (obj.momx() > maxspeed) then
					obj.momx(maxspeed)
				end
			end
		end
		if (obj.keypress("left")) then
			obj.dir(0)
		elseif (obj.keypress("right")) then
			obj.dir(2)
		end
	elseif (movetype == 2) then
		-- Hybrid method.
		-- Simply acts as if neither key is pressed if they are both down.
		if (obj.keydown("left")) and (not obj.keydown("right")) then
			if (obj.momx() > -maxspeed) then
				obj.momx(obj.momx()-acceleration)
				if (obj.momx() < -maxspeed) then
					obj.momx(-maxspeed)
				end
			end
			obj.dir(0)
		elseif (obj.keydown("right")) and (not obj.keydown("left")) then
			if (obj.momx() < maxspeed) then
				obj.momx(obj.momx()+acceleration)
				if (obj.momx() > maxspeed) then
					obj.momx(maxspeed)
				end
			end
			obj.dir(2)
		end
	end
	if (obj.keydown("left") ~= obj.keydown("right")) then
		obj.nofriction(true) -- Don't apply friction while walking
	else
		obj.nofriction(false)
	end

	-- Do gravity and collisions
	gravity()

	-- Jumping, but no longer moving up? Unset it, then.
	if (obj.jumping()) and (obj.momy() >= 0) then
		obj.jumping(false)
	end

	-- Default gun frame and offsets
	if (obj.dir() == 2) then
		obj.gun_frame(1)
		obj.gun_x(0)
	else
		obj.gun_frame(0)
		obj.gun_x(-8)
	end
	obj.gun_y(0)

	-- Do animations, sounds, and other nutty things
	if (obj.onfloor()) then
		if (obj.keypress("jump")) then
			--obj.momy(-3.2*FRACUNIT)
			obj.momy(-5*FRACUNIT)
			sfx(15)
			obj.check(false)
			obj.jumping(true)
		elseif (obj.keydown("left") or obj.keydown("right")) and ((movetype == 0) or (obj.momx() ~= 0)) then -- In official Cave Story, walking animation is based on keys pressed, NOT if you're actually moving.
			obj.check(false)
			obj.anim(50) -- Walking
			if (obj.tics() == 0) and ((obj.frame() == 0) or (obj.frame() == 2)) then
				sfx(24)
			end
			if (obj.frame() == 1) or (obj.frame() == 3) then
				obj.gun_y(obj.gun_y()-1)
			end
		elseif (obj.keypress("down")) or (obj.check()) then
			obj.check(true)
			obj.anim(80) -- On floor down
		else
			obj.anim(0) -- Standing
		end
	else -- In the air!
		if (obj.jumping() == true) and (not obj.keydown("jump")) then
			obj.momy(math.floor(obj.momy()/2))
			obj.jumping(false)
		end
		if (obj.keydown("down")) then
			obj.anim(1) -- In air down
			if (obj.dir() == 2) then
				obj.gun_frame(5)
				obj.gun_x(0)
			else
				obj.gun_frame(4)
				obj.gun_x(-8)
			end
			obj.gun_y(3)
		elseif (obj.momy() <= 0) and ((movetype ~= 0) or (not obj.keydown("up"))) then -- The key check is only because official Cave Story only has one "jumping while looking up" frame, not two.
			obj.anim(3) -- Jumping up
			obj.gun_y(obj.gun_y()-1)
		else
			obj.anim(4) -- Falling down
			obj.gun_y(obj.gun_y()-1)
		end
	end

	-- Playable character animation offset stuffs
	if (obj.keydown("up")) and ((obj.anim() == 0) or (obj.anim() == 50) or (obj.anim() == 3) or (obj.anim() == 4)) then
		obj.check(false)
		obj.xoff(3*TILE) -- Looking up
		if (obj.dir() == 2) then
			obj.gun_frame(3)
			obj.gun_x(-2)
		else
			obj.gun_frame(2)
			obj.gun_x(-6)
		end
		obj.gun_y(obj.gun_y()-3)
	else
		obj.xoff(0)
	end
end
