<commit_before>require ("lib.lclass")

require ("src.EventManager")

require ("src.data.PositionData")

require ("src.events.FocusGainedEvent")
require ("src.events.FocusLostEvent")
require ("src.events.KeyboardKeyDownEvent")
require ("src.events.KeyboardKeyUpEvent")
require ("src.events.MouseButtonDownEvent")
require ("src.events.MouseButtonUpEvent")
require ("src.events.ResizeEvent")

require ("src.Ship")

class "Game"

-- Constructs a new game
function Game:Game ()
	--
	self.eventManager = EventManager ()

	self.eventManager:subscribe ("FocusGainedEvent", self)
	self.eventManager:subscribe ("FocusLostEvent", self)
	self.eventManager:subscribe ("KeyboardKeyDownEvent", self)
	self.eventManager:subscribe ("KeyboardKeyUpEvent", self)
	self.eventManager:subscribe ("MouseButtonDownEvent", self)
	self.eventManager:subscribe ("MouseButtonUpEvent", self)
	self.eventManager:subscribe ("ResizeEvent", self)

  self.bg = love.graphics.newImage("gfx/bg.jpg")

	self.log = {}
	self.shipoflife = Ship ()
  self.eventManager:subscribe ("KeyboardKeyDownEvent", self.shipoflife)
  self.eventManager:subscribe ("KeyboardKeyUpEvent", self.shipoflife)
end

-- Raises (queues) a new event
function Game:raise (event)
	--
	self.eventManager:push (event)
end

-- Callback used by EventManager
function Game:handle (event)
	--
	print ("trying to handle " .. type (event))
	if event:getClass () == "MouseButtonUpEvent" then
		table.insert (self.log, {
			timestamp = tostring (os.date ("%c")),
			ttl = 4,
			tal = 0,
			message = tostring (event)
		})
	end
end

-- Updates game logic
function Game:onUpdate (dt)
	--
	self.eventManager:update (dt)
	self.shipoflife:onUpdate (dt)

	local toberemoved = {}
	for i, v in pairs (self.log) do
		if (v.ttl - v.tal) <= 0 then
			table.insert (toberemoved, i)
		else
			v.tal = v.tal + dt
		end
	end
	for i, v in pairs (toberemoved) do
		table.remove (self.log, v)
	end
end

-- Renders stuff onto the screen
function Game:onRender ()
	--
  local width = love.graphics.getWidth()
  local height = love.graphics.getHeight()
  local scaleX = self.bg:getWidth() / width
  local scaleY = self.bg:getHeight() / height
  
  love.graphics.draw(self.bg, 0, 0, 0, scaleX, scaleY)
	self:renderLog ()
	self.shipoflife:onRender ()
  
end

-- Gets called when game exits. May be used to do some clean up.
function Game:onExit ()
	--
end

function Game:renderLog ()
	--
	local basepos = {x = 42, y = 42}
	for i, v in pairs (self.log) do
		local msg = "[" .. v.timestamp .. "]: " .. v.message
		local y = basepos.y + (i - 1) * 21
		love.graphics.print (msg, basepos.x, y)
	end
end<commit_msg>removed debug messages and fixed bg dimensions<commit_after>require ("lib.lclass")

require ("src.EventManager")

require ("src.data.PositionData")

require ("src.events.FocusGainedEvent")
require ("src.events.FocusLostEvent")
require ("src.events.KeyboardKeyDownEvent")
require ("src.events.KeyboardKeyUpEvent")
require ("src.events.MouseButtonDownEvent")
require ("src.events.MouseButtonUpEvent")
require ("src.events.ResizeEvent")

require ("src.Ship")

class "Game"

-- Constructs a new game
function Game:Game ()
	--
	self.eventManager = EventManager ()

	self.eventManager:subscribe ("FocusGainedEvent", self)
	self.eventManager:subscribe ("FocusLostEvent", self)
	self.eventManager:subscribe ("KeyboardKeyDownEvent", self)
	self.eventManager:subscribe ("KeyboardKeyUpEvent", self)
	self.eventManager:subscribe ("MouseButtonDownEvent", self)
	self.eventManager:subscribe ("MouseButtonUpEvent", self)
	self.eventManager:subscribe ("ResizeEvent", self)

	self.bg = love.graphics.newImage("gfx/bg.jpg")

	self.log = {}
	self.shipoflife = Ship ()
	self.eventManager:subscribe ("KeyboardKeyDownEvent", self.shipoflife)
	self.eventManager:subscribe ("KeyboardKeyUpEvent", self.shipoflife)
end

-- Raises (queues) a new event
function Game:raise (event)
	--
	self.eventManager:push (event)
end

-- Callback used by EventManager
function Game:handle (event)
	--
end

-- Updates game logic
function Game:onUpdate (dt)
	--
	self.eventManager:update (dt)
	self.shipoflife:onUpdate (dt)
end

-- Renders stuff onto the screen
function Game:onRender ()
	--
	local width = love.graphics.getWidth()
	local height = love.graphics.getHeight()
	local scaleX = width / self.bg:getWidth()
	local scaleY = height / self.bg:getHeight()
	love.graphics.draw(self.bg, 0, 0, 0, scaleX, scaleY)

	self.shipoflife:onRender ()
end

-- Gets called when game exits. May be used to do some clean up.
function Game:onExit ()
	--
end
{'fraction_non_alphanumeric': 0.13633340722677897, 'fraction_numerical': 0.0035468853912657946, 'mean_word_length': 4.611940298507463, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2700863', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1498, 'n_words': 375}