Compare commits

...

3 Commits

Author SHA1 Message Date
Pascal Abresch a5dfbfa561 Add main menu 2022-06-24 19:55:24 +02:00
Pascal Abresch a090e72706 misc fixes 2022-06-24 19:54:54 +02:00
Pascal Abresch 6a44319ec9 reorganize textures for colors 2022-06-24 19:53:09 +02:00
55 changed files with 180 additions and 66 deletions

View File

@ -5,7 +5,7 @@ camera.target = 0
camera.offset = { x = 0, y = 300 }
local fullscreen = false
local altPressed, enterPressed = false
local altPressed, enterPressed = false, false
function camera.keypressed(key, _)
if key == "return" then enterPressed = true end
if key == "lalt" then altPressed = true end

View File

@ -12,7 +12,7 @@ function drawing.clearAllCanvases()
love.graphics.setCanvas(gameloop.buffer.pixel.dbg)
love.graphics.clear()
love.graphics.setCanvas()
buffer.physics = {}
gameloop.buffer.physics = {}
end
@ -25,11 +25,11 @@ end
function drawing.fillCanvas(layer, hash)
love.graphics.setCanvas(gameloop.buffer.pixel[layer])
love.graphics.clear()
for x = 0, gameloop.world.x -textures[hash].image:getPixelWidth(),
textures[hash].image:getPixelWidth() do
for y = 0, gameloop.world.y -textures[hash].image:getPixelHeight(),
textures[hash].image:getPixelHeight() do
love.graphics.draw(textures[hash].image, x, y)
for x = 0, gameloop.world.x -gameloop.textures[hash].image:getPixelWidth(),
gameloop.textures[hash].image:getPixelWidth() do
for y = 0, gameloop.world.y -gameloop.textures[hash].image:getPixelHeight(),
gameloop.textures[hash].image:getPixelHeight() do
love.graphics.draw(gameloop.textures[hash].image, x, y)
end
end
love.graphics.setCanvas()
@ -44,13 +44,13 @@ end
function drawing.keyreleased(key, _)
if key == "c" then
drawing.clearAllCanvases()
drawing.clearAllCanvasesNetwork()
end
if key == "f" then
drawing.fillCanvasNetwork("fg", drawing.cursor)
drawing.fillCanvasNetwork("fg", drawing.cursorHash)
end
if key == "b" then
drawing.fillCanvasNetwork("bg", drawing.cursor)
drawing.fillCanvasNetwork("bg", drawing.cursorHash)
end
end

View File

@ -103,7 +103,8 @@ function debugNetworkSync()
if message then print("<= " .. util.pprint(message)) end
if not message then
if errorString == "timeout" then return else
error(errorString)
menu.init()
return
end
end
local response = rpc.validate(message)
@ -163,6 +164,11 @@ function errorhandler(msg)
end
function gameloop.mousepressed(mousex, mousey)
ui.mousepressed(mousex, mousey)
end
function gameloop.init(server, nickname)
love.errorhandler = errorhandler
assert(server, "Gameloop called without server to connect to?")
@ -194,14 +200,14 @@ function gameloop.init(server, nickname)
gameloop.client = socket.udp()
gameloop.client:setpeername(server.adress, server.port)
gameloop.client:settimeout(0)
print("Socketnname: " .. gameloop.client:getsockname())
print("Connecting to [" .. server.adress .."]:" .. server.port)
local request = "poppyV002" ..US.. "0" ..US.. unit("init", nickname)
gameloop.client:send(request)
if NETWORK_DEBUG then print("=> " .. util.pprint(request)) end
if not NETWORK_DEBUG then
gameloop.networkSend = normalNetworkSend
gameloop.networkSync = normalNetworkSync
@ -239,6 +245,22 @@ function gameloop.reducedVisible(dt)
end
function gameloop.keypressed(key, _)
physics.keypressed(key, _)
camera.keypressed(key, _)
end
function gameloop.keyreleased(key, _)
if key == "r" then
drawBackground = not drawBackground
end
ui.keyreleased(key, _)
camera.keyreleased(key, _)
drawing.keyreleased(key, _)
end
function gameloop.loadworld(world)
-- Game connected!
love.errorhandler = errorhandlerNetwork
@ -267,35 +289,16 @@ function gameloop.loadworld(world)
drawBackground = true
love.keyreleased = gameloop.keyreleased
love.keypressed = gameloop.keypressed
love.mousepressed = gameloop.mousepressed
if not PHYSICS_DEBUG then
love.draw = normalDraw
love.keyreleased = function(key, _)
if key == "r" then
drawBackground = not drawBackground
end
ui.keyreleased(key, _)
camera.keyreleased(key, _)
drawing.keyreleased(key, _)
end
else
love.draw = debugDraw
love.keyreleased = function(key, _)
physics.keyreleased_debug(key, _)
if key == "r" then
drawBackground = not drawBackground
end
ui.keyreleased(key, _)
camera.keyreleased(key, _)
drawing.keyreleased(key, _)
end
end
love.keypressed = function(key, _)
physics.keypressed(key, _)
camera.keypressed(key, _)
end
love.resize = function()
ui.resize()

View File

@ -12,7 +12,7 @@ NETWORK_DEBUG = true
constants = require("server.constants")
US = string.char(31)
local menu = require("lua.menuloop")
function love.load()
local server = { adress = "127.0.0.1", port = 11150 }
gameloop.init(server, "Username")
menu.init()
end

View File

@ -80,7 +80,7 @@ function layout.drawTexture(container, x, y, simulate)
local texture = container.texture
local scale = container.scale or 1
if not simulate then
love.graphics.draw(texture, x, y, scale, scale)
love.graphics.draw(texture, x, y, 0, scale, scale)
end
return x + texture:getWidth()* scale, y + texture:getHeight() * scale
end
@ -102,7 +102,7 @@ end
function layout.colorPicker(container, x, y, simulate)
assert(x and y)
local startx, starty = x, y
granularity= container.granularity or 0.2
granularity = container.granularity or 0.2
local points = {}
local myx, myy = x, y
local endx = 0

128
lua/menuloop.lua Normal file
View File

@ -0,0 +1,128 @@
menu = {}
menu.serverlist = {
{description = "A localhost server [ipv4]", host = "127.0.0.1", port = "11150"},
{description = "A localhost server [ipv6]", host = "::1", port = "11150"}
}
local altPressed, enterPressed = false, false
function menu.keyreleased(key, _)
if key == "lalt" then
altPressed = false
end
if key == "return" then
enterPressed = false
end
end
function menu.keypressed(key, _)
if key == "return" then enterPressed = true end
if key == "lalt" then altPressed = true end
if key == "f11" or (altPressed and key == "return") or (enterPressed and key == "lalt") then
fullscreen = not fullscreen
love.window.setFullscreen(fullscreen, "desktop")
end
end
function menu.update(dt)
love.timer.sleep((1/60) -dt)
end
function menu.resize()
menu.width, menu.height = love.window.getMode()
menu.Canvas = love.graphics.newCanvas(width, height)
love.graphics.setCanvas(menu.Canvas)
love.graphics.clear()
drawMenu(w, h)
love.graphics.setCanvas()
end
function menu.mousepressed(mousex, mousey)
local textures = gameloop.textures
for i, v in ipairs(uiState) do
if mousex >= v.x and mousex <= v.x2 then
if mousey >= v.y and mousey <= v.y2 then
if v.kind == "server" then
local names = { "Herbert", "Thorben", "Martin", "Heinrich", "Dietrich", "Markus", "Florian", "Helmut", "Willhelm", "Fritz", "Gustav", "Konrad", "Berta", "Charlotte", "Hildegard", "Lieselotte", "Gudrun", "Giesela", "Margarete", "Antonia", "Friederike", "Clotilde", "Marlies", "Hedwig" }
local lastNames = { "Müller", "Schmidt", "Meier", "Bauer", "Werner", "Schumacher", "Bergmann", "Eisenhauer", "Heisenberg" }
local fullName = names[love.math.random(1, #names)] .. " " .. lastNames[love.math.random(1, #lastNames)]
local serverID = v.identifier
local serverEntry = menu.serverlist[serverID]
gameloop.init({ adress = serverEntry.host, port = serverEntry.port }, fullName)
uiState = {}
end
end
end
end
end
menu.serverentry = function(id, description, host, port)
return {name = "horizontal",
{name = "label", text = description },
{name = "spacer", width = 20 },
{name = "label", text = "[".. host .."]"},
{name = "label", text = ":".. port },
{name = "spacer", width = 25 },
{name = "cursorSelect", kind = "server", identifier = id,
{name = "drawTexture", texture = love.graphics.newImage("textures/menu/serverPlay.png")}}}
end
menu.layoutServerList = function()
local list = {name = "vertical"}
for i, v in ipairs(menu.serverlist) do
table.insert(list, menu.serverentry(i, v.description, v.host, v.port))
end
return list
end
menu.layout = {name ="vertical",
{name = "spacer", height = 20},
{name = "horizontal",
{name = "spacer", width = 20},
{name = "drawTexture", texture = love.graphics.newImage("ressources/Poppy.png")},
{name = "label", text = "Welcome to poppy!"},
},
{name = "horizontal",
{name = "spacer", width = 60},
{name = "vertical",
{name = "spacer", height = 60},
{name = "label", text = "Pick a server to join!"},
{name = "spacer", height = 20},
menu.layoutServerList()
}
}
}
function drawMenu()
color_push()
love.graphics.setCanvas(menu.Canvas)
uiState = {}
love.graphics.clear( )
layout.handle(menu.layout, 0, 0)
love.graphics.setCanvas()
color_pop()
end
function menu.draw(w, h)
love.graphics.draw(menu.Canvas)
end
function menu.init()
menu.width, menu.height = love.window.getMode()
menu.Canvas = love.graphics.newCanvas(menu.width, menu.height)
drawMenu()
love.draw = menu.draw
love.keyreleased = menu.keyreleased
love.keypressed = menu.keypressed
love.mousepressed = menu.mousepressed
end
return menu

View File

@ -117,9 +117,9 @@ v2_message.deleteTexture = function(clientID, args)
local width, args = util.nextIntRecord(args)
local height, layer = util.nextIntRecord(args)
if layer == "fg" then
love.graphics.setCanvas(buffer.pixel.fg)
love.graphics.setCanvas(gameloop.buffer.pixel.fg)
elseif layer == "bg" then
love.graphics.setCanvas(gameloopbuffer.pixel.bg)
love.graphics.setCanvas(gameloop.buffer.pixel.bg)
end
love.graphics.setBlendMode("replace")
color_push()

View File

@ -10,24 +10,9 @@ else
ui.bigFont = love.graphics.getFont(45)
end
function ui.update_framenum(p_framenum)
ui.framenum = nil
ui.framenum = love.graphics.newText(ui.font,"framenum: " .. p_framenum)
love.graphics.setCanvas(ui.buffer)
love.graphics.clear()
love.graphics.setCanvas()
ui.draw(window.x, window.y)
end
function ui.update_scale(p_scale)
scale = p_scale
ui.scale = nil
ui.scale = love.graphics.newText(ui.bigFont, "scale: " .. p_scale)
love.graphics.setCanvas(ui.buffer)
love.graphics.clear()
love.graphics.setCanvas()
ui.draw(window.x, window.y)
scale = p_scale
end
@ -49,8 +34,6 @@ ui.helptext = [[[P] toggle fly
local textEnabled = false
local textEntry = ""
local normalPressed = love.keypressed
local normalReleased = love.keyreleased
function ui.keyreleased(key, _)
if key == "return" and not love.keyboard.isDown("lalt") then
textEnabled = true
@ -83,8 +66,8 @@ function ui.keyreleased(key, _)
end
ui.draw(window.x, window.y)
love.keyboard.setTextInput(false)
love.keyreleased = normalReleased
love.keypressed = normalPressed
love.keyreleased = gameloop.keyreleased
love.keypressed = gameloop.keypressed
love.update = gameloop.normalVisible
elseif key == "backspace" then
textEntry = string.sub(textEntry, 0, #textEntry -1)
@ -93,8 +76,8 @@ function ui.keyreleased(key, _)
end
love.keypressed = function(key, _) return end
else
love.keyreleased = normalReleased
love.keypressed = normalPressed
love.keyreleased = gameloop.keyreleased
love.keypressed = gameloop.keypressed
end
end
@ -359,7 +342,7 @@ function ui.draw(w, h)
end
function love.mousepressed(mousex, mousey)
function ui.mousepressed(mousex, mousey)
local textures = gameloop.textures
for i, v in ipairs(uiState) do
if mousex >= v.x and mousex <= v.x2 then
@ -401,8 +384,8 @@ ui.init = function()
ui.buffer = love.graphics.newCanvas(w, h)
love.graphics.setCanvas(ui.buffer)
love.graphics.clear()
ui.draw(w, h)
love.graphics.setCanvas()
ui.draw(w, h)
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 543 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 543 B

After

Width:  |  Height:  |  Size: 543 B

View File

Before

Width:  |  Height:  |  Size: 543 B

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 543 B

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 543 B

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 491 B

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 956 B

After

Width:  |  Height:  |  Size: 956 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 949 B

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 956 B

After

Width:  |  Height:  |  Size: 949 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 952 B

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 956 B

View File

Before

Width:  |  Height:  |  Size: 956 B

After

Width:  |  Height:  |  Size: 956 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 943 B

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 948 B

After

Width:  |  Height:  |  Size: 944 B

View File

Before

Width:  |  Height:  |  Size: 934 B

After

Width:  |  Height:  |  Size: 934 B

View File

Before

Width:  |  Height:  |  Size: 922 B

After

Width:  |  Height:  |  Size: 922 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 923 B

After

Width:  |  Height:  |  Size: 912 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 944 B

After

Width:  |  Height:  |  Size: 948 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 912 B

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 920 B

After

Width:  |  Height:  |  Size: 943 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 920 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 843 B

After

Width:  |  Height:  |  Size: 845 B

View File

Before

Width:  |  Height:  |  Size: 854 B

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 845 B

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 851 B

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 846 B

After

Width:  |  Height:  |  Size: 839 B

View File

Before

Width:  |  Height:  |  Size: 852 B

After

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 426 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
textures/menu/serverPlay Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB