TitleScreenState = class(Group, function(o, lastState)
	local cworld = player.currentWorld
	Group.init(o)
	o:setup(cworld)
end)
function TitleScreenState:setup(cworld)
	o = self
	bludG.camera.scroll = Vec2(0,0)
	bludG.camera.scale = 1

	local groundRatio = 365/768
	local groundHeight = letterboxWidth*groundRatio+1

	o:add(GradientObject(0,0,bludG.camera.w, bludG.camera.h-groundHeight, bludColor(cworld.top_color[1], cworld.top_color[2], cworld.top_color[3], 255), bludColor(cworld.bottom_color[1], cworld.bottom_color[2], cworld.bottom_color[3], 255)))
	o.ground = o:add(GradientObject(0,bludG.camera.h-groundHeight,bludG.camera.w, groundHeight+1, bludColor(0,0,0, 255), bludColor(0,0,0, 255)))

	local pbw = 114
	local pby = bludG.camera.h-groundHeight/2-pbw/2
	o.playButtonY = pby

	-- should load the sprite for the current world that we are on
	LevelSelectState.addHotel(o, lastState, 1)
	local scale = 1
	local hHeight = o.hotel.sprite:getHeight()*scale*r_scale*0.5
	if r_scale == 4 then
		hHeight = hHeight*2
	end
	o.bad = o:add(MultilineString(bludG.camera.w/2-30*r_scale/scale, bludG.camera.h-groundHeight-hHeight, 60*r_scale/scale, " Bad\n Hotel "))
	o.bad:setScrollFactor(Vec2(0,0))
	o.bad:setPosition(o.bad.pos.x, -o.bad.h-10*r_scale)
	o.bad:setColor(0,0,0)
	o.bad:center()

	-- PauseState.loadNewSettings(o)
	o.playButton = o:add(FancyButton(bludG.camera.w/2-pbw/2,pby,"Play"))
	o.playButton:setScrollFactor(Vec2(0,0))
	o.playButton.onPress = function()
		local ws = WorldSelectState(o)
		mainState:changeState(ws)
		o:explodeTitle(ws)
		-- analytics:play()
	end
	o.playButton:setPosition(bludG.camera.w/2-o.playButton.svg:getMaxX()/2, o.ground.pos.y+o.ground.h/2-o.playButton.svg:getMaxY()/2)
	o.playButton:setColor(cworld.bottom_color[1], cworld.bottom_color[2], cworld.bottom_color[3])
	o.playButton:setScrollFactor(Vec2(1,1))
	o.playButtonY = o.playButton.pos.y+5*r_scale

	o.infoButton = o:add(FancyButton(o.playButton.pos.x+o.playButton.w/2, o.playButton.pos.y+o.playButton.h/2, "?", "button_draft", 0.5))
	o.infoButton:setPosition(bludG.camera.w/5*4-o.infoButton.svg:getMaxX()/2, o.playButton.pos.y+o.playButton.h/2-o.infoButton.svg:getMaxY()/2)
	o.infoButton:setScrollFactor(Vec2(1,1))
	o.infoButton.onPress = function()
		bg:openURL("http://www.luckyframe.co.uk/badhotel/pc_help/");
	end
	o.infoButton:setColor(cworld.bottom_color[1], cworld.bottom_color[2], cworld.bottom_color[3])

	o.settingsButton = o:add(FancyButton(o.playButton.pos.x+o.playButton.w/2, o.playButton.pos.y+o.playButton.h/2, "GEAR", "button_gear", 0.5))
	o.settingsButton:setPosition(bludG.camera.w/6*2-o.settingsButton.svg:getMaxX()/2, o.playButton.pos.y+o.playButton.h/2-o.settingsButton.svg:getMaxY()/2)
	o.settingsButton:setScrollFactor(Vec2(1,1))
	o.settingsButton.onPress = function()
		-- switch to the settings screen
		mainState = WrapperState(Group());
		mainState:changeState(SettingState(o))
	end
	o.settingsButton:setColor(cworld.bottom_color[1], cworld.bottom_color[2], cworld.bottom_color[3])

	if scf:isSteamConnected() then
		o.achievementButton = o:add(FancyButton(o.playButton.pos.x-o.playButton.w/2, o.playButton.pos.y+o.playButton.h/2, "test", "button_achievement", 0.3))
		o.achievementButton:setPosition(bludG.camera.w/6-o.achievementButton.svg:getMaxX()/2, bludG.camera.h)
		o.achievementButton.onPress = function()
			local sa = SteamAchievements()
			sa:DisplayOverlay()
		end
		o.achievementButtonShowing = false
		WorldSelectState.show(o, o.achievementButton)
		o.achievementButtonShowing = true
		o.achievementButton:setColor(cworld.bottom_color[1], cworld.bottom_color[2], cworld.bottom_color[3])
	end
end
function TitleScreenState:update()
	if not self.achievementButtonShowing then
		if gk and gk:isConnected() then
			WorldSelectState.show(self, self.achievementButton)
			self.achievementButtonShowing = true
		end
	end
end
function TitleScreenState:explodeTitle(ws)
	sx = ws.currentWorld*bludG.camera.w
	for i,v in ipairs(self.bad.lines.members) do
		for j,letter in ipairs(v.subs) do
			local l = mainState.particles:addRecycle(DeathSpin(letter.pos.x+letter.w/2+sx, letter.pos.y+letter.h/2, letter.sprite, letter.tint, letter.sheet, 0))
		end
		pd:startList("fromOF")
		pd:addSymbol("titlescreen")
		pd:addFloat(1)
		pd:finish("fromOF")
	end
end