Start menu, server, scenes, buttons.

This commit is contained in:
wan-may 2023-09-04 15:20:02 -03:00
parent eae71e4a76
commit bef5a5e6c7
12 changed files with 250 additions and 3 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
logs/

18
src/client/browser.lua Normal file
View File

@ -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

0
src/client/button.lua Normal file
View File

0
src/client/game.lua Normal file
View File

62
src/client/menu.lua Normal file
View File

@ -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

5
src/client/strings.lua Normal file
View File

@ -0,0 +1,5 @@
return {
["newgame_button"] = "New Game",
["join_button"] = "Join Server",
["quit_button"] = "Quit",
}

51
src/conf.lua Normal file
View File

@ -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

View File

@ -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
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

56
src/server.lua Normal file
View File

@ -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()

30
src/shared.lua Normal file
View File

@ -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

0
src/strings.lua Normal file
View File

2
src/vision.bat Normal file
View File

@ -0,0 +1,2 @@
D:/dev/love/love.exe D:\dev\vision\src
pause