From bef5a5e6c7099aa1a10c1d322aface8905bbc4b8 Mon Sep 17 00:00:00 2001 From: wan-may Date: Mon, 4 Sep 2023 15:20:02 -0300 Subject: [PATCH] Start menu, server, scenes, buttons. --- .gitignore | 1 + src/client/browser.lua | 18 ++++++++++++ src/client/button.lua | 0 src/client/game.lua | 0 src/client/menu.lua | 62 ++++++++++++++++++++++++++++++++++++++++++ src/client/strings.lua | 5 ++++ src/conf.lua | 51 ++++++++++++++++++++++++++++++++++ src/main.lua | 28 +++++++++++++++++-- src/server.lua | 56 ++++++++++++++++++++++++++++++++++++++ src/shared.lua | 30 ++++++++++++++++++++ src/strings.lua | 0 src/vision.bat | 2 ++ 12 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 src/client/browser.lua create mode 100644 src/client/button.lua create mode 100644 src/client/game.lua create mode 100644 src/client/menu.lua create mode 100644 src/client/strings.lua create mode 100644 src/conf.lua create mode 100644 src/server.lua create mode 100644 src/shared.lua create mode 100644 src/strings.lua create mode 100644 src/vision.bat diff --git a/.gitignore b/.gitignore index e69de29..5292519 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +logs/ \ No newline at end of file diff --git a/src/client/browser.lua b/src/client/browser.lua new file mode 100644 index 0000000..6413e9c --- /dev/null +++ b/src/client/browser.lua @@ -0,0 +1,18 @@ +local client = assert( client ) +local lg = assert( love.graphics ) +local browser = {} + +function browser.draw() + lg.rectangle( "fill", 50, 50, 50, 50 ) +end + +function browser.update( dt ) + +end + +function browser.onLoad( ) + lg.setColor( 1, 1, 1, 1 ) +end + +client.addScene( browser, "browser" ) +return browser \ No newline at end of file diff --git a/src/client/button.lua b/src/client/button.lua new file mode 100644 index 0000000..e69de29 diff --git a/src/client/game.lua b/src/client/game.lua new file mode 100644 index 0000000..e69de29 diff --git a/src/client/menu.lua b/src/client/menu.lua new file mode 100644 index 0000000..3a8b791 --- /dev/null +++ b/src/client/menu.lua @@ -0,0 +1,62 @@ +--Main menu for client. +local lg = assert( love.graphics ) +local client = assert( client ) +local strings = assert( require 'client.strings' ) +local menu = {} + +local t = 0 +local wWidth = 800 +local wHeight = 600 + +function menu.onLoad() + lg.setNewFont( 32 ) +end + +function menu.draw() + local x, y = 10, 10 + do + lg.setColor( 1, 0.8, 0.5, 1 ) + lg.rectangle( "fill", x, y, ( wWidth - 20 ) / 2, 50, 15 ) + lg.setColor( 1, 1, 1, 1 ) + lg.print( strings.newgame_button, x + 15, y + 5 ) + y = y + 100 + end + do + lg.setColor( 1, 0.8, 0.5, 1 ) + lg.rectangle( "fill", x, y, ( wWidth - 20 ) / 2, 50, 15 ) + lg.setColor( 1, 1, 1, 1 ) + lg.print( strings.join_button, x + 15, y + 5 ) + y = y + 100 + end + do + lg.setColor( 1, 0.8, 0.5, 1 ) + lg.rectangle( "fill", x, y, ( wWidth - 20 ) / 2, 50, 15 ) + lg.setColor( 1, 1, 1, 1 ) + lg.print( strings.quit_button, x + 15, y + 5 ) + y = y + 100 + end +end + +function menu.update( dt ) + t = t + dt +end + +function menu.resize( w, h ) + wWidth, wHeight = w, h +end + +function menu.mousemoved( x, y, dx, dy, istouch ) + +end + +function menu.mousepressed( x, y, button, istouch, presses ) + client.loadScene( "browser" ) +end + +function menu.keypressed( key, code, isrepeat ) + +end + +client.addScene( menu, "menu" ) + +return menu \ No newline at end of file diff --git a/src/client/strings.lua b/src/client/strings.lua new file mode 100644 index 0000000..9e238d4 --- /dev/null +++ b/src/client/strings.lua @@ -0,0 +1,5 @@ +return { + ["newgame_button"] = "New Game", + ["join_button"] = "Join Server", + ["quit_button"] = "Quit", +} \ No newline at end of file diff --git a/src/conf.lua b/src/conf.lua new file mode 100644 index 0000000..f972e67 --- /dev/null +++ b/src/conf.lua @@ -0,0 +1,51 @@ +function love.conf(t) + t.identity = "vision-dajjal" -- The name of the save directory (string) + t.appendidentity = false -- Search files in source directory before save directory (boolean) + t.version = "11.4" -- The LÖVE version this game was made for (string) + t.console = true -- Attach a console (boolean, Windows only) + t.accelerometerjoystick = true -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean) + t.externalstorage = false -- True to save files (and read from the save directory) in external storage on Android (boolean) + t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean) + + t.audio.mic = false -- Request and use microphone capabilities in Android (boolean) + t.audio.mixwithsystem = true -- Keep background music playing when opening LOVE (boolean, iOS and Android only) + + t.window.title = "vision-dajjal" -- The window title (string) + t.window.icon = nil -- Filepath to an image to use as the window's icon (string) + t.window.width = 800 -- The window width (number) + t.window.height = 600 -- The window height (number) + t.window.borderless = false -- Remove all border visuals from the window (boolean) + t.window.resizable = true -- Let the window be user-resizable (boolean) + t.window.minwidth = 400 -- Minimum window width if the window is resizable (number) + t.window.minheight = 400 -- Minimum window height if the window is resizable (number) + t.window.fullscreen = false -- Enable fullscreen (boolean) + t.window.fullscreentype = "desktop" -- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string) + t.window.vsync = 1 -- Vertical sync mode (number) + t.window.msaa = 3 -- The number of samples to use with multi-sampled antialiasing (number) + t.window.depth = nil -- The number of bits per sample in the depth buffer + t.window.stencil = nil -- The number of bits per sample in the stencil buffer + t.window.display = 1 -- Index of the monitor to show the window in (number) + t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean) + t.window.usedpiscale = true -- Enable automatic DPI scaling when highdpi is set to true as well (boolean) + t.window.x = nil -- The x-coordinate of the window's position in the specified display (number) + t.window.y = nil -- The y-coordinate of the window's position in the specified display (number) + + t.modules.audio = true -- Enable the audio module (boolean) + t.modules.data = true -- Enable the data module (boolean) + t.modules.event = true -- Enable the event module (boolean) + t.modules.font = true -- Enable the font module (boolean) + t.modules.graphics = true -- Enable the graphics module (boolean) + t.modules.image = true -- Enable the image module (boolean) + t.modules.joystick = false -- Enable the joystick module (boolean) + t.modules.keyboard = true -- Enable the keyboard module (boolean) + t.modules.math = true -- Enable the math module (boolean) + t.modules.mouse = true -- Enable the mouse module (boolean) + t.modules.physics = true -- Enable the physics module (boolean) + t.modules.sound = true -- Enable the sound module (boolean) + t.modules.system = true -- Enable the system module (boolean) + t.modules.thread = true -- Enable the thread module (boolean) + t.modules.timer = true -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update + t.modules.touch = false -- Enable the touch module (boolean) + t.modules.video = false -- Enable the video module (boolean) + t.modules.window = true -- Enable the window module (boolean) +end \ No newline at end of file diff --git a/src/main.lua b/src/main.lua index 2af6981..cfd39fc 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,4 +1,26 @@ -local lg = assert( love.graphics ) +--Client starts here! +client = { scenes = {} } +local client = client +local shared = assert( require 'shared' ) +local love = assert( love ) -function love.draw() end -function love.update() end \ No newline at end of file +function client.loadScene( name ) + print( "Loading Scene:", name ) + local scene = assert( client.scenes[name] ) + for k, v in pairs( scene ) do + love[k] = v + end + scene.onLoad() +end + +function client.addScene( t, name ) + print( "Adding Scene:", name ) + client.scenes[name] = t +end + +function love.load() +assert( require 'client.menu' ) +assert( require 'client.browser' ) + + client.loadScene( "menu" ) +end diff --git a/src/server.lua b/src/server.lua new file mode 100644 index 0000000..e4d3bec --- /dev/null +++ b/src/server.lua @@ -0,0 +1,56 @@ +local shared = assert( require 'shared' ) +local socket = assert( require 'socket' ) +local udp = socket.udp() +local io = assert( io ) +local server = { + tick = 0, + portNumber = 51312, + logFile = assert( io.open( "../logs/dajjal"..os.time()..".txt", "a" )), + serverName = "dajjal-server", +} + +do + local _print = print + function server.Print(...) + _print( ... ) + server.logFile:write( table.concat({os.date("!%Y-%m-%d %X"), ...}, "\t"), "\n" ) + server.logFile:flush() + end +end +local print = server.Print + + +--Developer convenience function: start the local client program. +function server.StartLocalClient() + os.execute( "start vision.bat" ) +end + +function server.Parse( packet, ip, port ) + if not packet then return end + print( packet ) +end + +function server.Start() + udp:settimeout(0) + udp:setsockname('*', server.portNumber) + print( "Starting Server" ) + server.StartLocalClient() + repeat + server.Parse( udp:receivefrom() ) + server.Advance() + until socket.sleep( 0.1 ) +end + +function server.Advance() + server.tick = server.tick + 1 +end + +function server.NewGame() + +end + +function server.Quit() + +end + +return server.Start() \ No newline at end of file diff --git a/src/shared.lua b/src/shared.lua new file mode 100644 index 0000000..3583780 --- /dev/null +++ b/src/shared.lua @@ -0,0 +1,30 @@ +local shared = {} + + +--World state. +local world = {} +function world:Advance() + +end + +function world:Reset() + +end + +function world:Load( map ) + +end + +function world:AddPlayer( playerID, x, y, stage ) + +end + +function world:RemovePlayer( playerID ) + +end + +function shared.NewWorld() + return setmetatable( {}, {__index = world } ) +end + +return shared \ No newline at end of file diff --git a/src/strings.lua b/src/strings.lua new file mode 100644 index 0000000..e69de29 diff --git a/src/vision.bat b/src/vision.bat new file mode 100644 index 0000000..d7798e3 --- /dev/null +++ b/src/vision.bat @@ -0,0 +1,2 @@ +D:/dev/love/love.exe D:\dev\vision\src +pause \ No newline at end of file