local Debug = {} local rgb = require("helpers.rgb") local DRAW_GRID = false local GRID_COLOR = rgb(30, 30, 30) local DRAW_COLLIDERS = false local COLLIDER_COLOR = rgb(200, 20, 200) local DRAW_PING = false function Debug:init() self.current_player = 1 end function Debug:drawColliders() local physics = self.pool:getSystem(require("systems.physics")) love.graphics.setColor(COLLIDER_COLOR) local bump = physics.bump local items = bump:getItems() for _, item in ipairs(items) do love.graphics.rectangle("line", bump:getRect(item)) end end function Debug:drawGrid() local map = self.pool:getSystem(require("systems.map")) if not map.map then return end local scaler = self.pool:getSystem(require("systems.screen-scaler")) local w, h = scaler:getDimensions() love.graphics.setColor(GRID_COLOR) for x=0, w, map.map.tilewidth do love.graphics.line(x, 0, x, h) end for y=0, h, map.map.tileheight do love.graphics.line(0, y, w, y) end end function Debug:keypressed(key) if key == "e" and love.keyboard.isDown("lshift") then local PlayerSystem = self.pool:getSystem(require("systems.player")) local player = PlayerSystem:spawnPlayer() for _, e in ipairs(self.pool.groups.controllable_player.entities) do e.controllable = false self.pool:queue(e) end player.controllable = true self.pool:queue(player) self.current_player = #self.pool.groups.player.entities+1 elseif key == "tab" then local player_entities = self.pool.groups.player.entities player_entities[self.current_player].controllable = false self.pool:queue(player_entities[self.current_player]) self.current_player = self.current_player % #player_entities + 1 player_entities[self.current_player].controllable = true self.pool:queue(player_entities[self.current_player]) end end function Debug:draw() if DRAW_GRID then self:drawGrid() end if DRAW_COLLIDERS then self:drawColliders() end if DRAW_PING and self.pool.data.host_socket then local host_socket = self.pool.data.host_socket local height = love.graphics.getFont():getHeight() for _, index in ipairs(self.connected_peers) do local peer = host_socket:get_peer(index) love.graphics.print(peer:round_trip_time(), 0, (index-1)*height) end end end return Debug