Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards playability #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added client/assets/audio/footsteps/footstep-01.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-02.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-03.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-04.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-05.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-06.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-07.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-08.wav
Binary file not shown.
Binary file added client/assets/audio/footsteps/footstep-09.wav
Binary file not shown.
Binary file added client/assets/audio/place.wav
Binary file not shown.
Binary file added client/assets/audio/snowball_throw.wav
Binary file not shown.
15 changes: 0 additions & 15 deletions client/assets/player.obj

This file was deleted.

15 changes: 0 additions & 15 deletions client/assets/quad.obj

This file was deleted.

Binary file added client/assets/snowball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 29 additions & 77 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,112 +1,64 @@
if arg[#arg] == "vsc_debug" then require("lldebugger").start() end
package.path = package.path .. ";?/init.lua"

lg = love.graphics
---@diagnostic disable-next-line: missing-parameter
lg.setDefaultFilter("nearest")
love.graphics.setDefaultFilter("nearest")

io.stdout:setvbuf("no")

CHANNEL_ONE = 0
CHANNEL_EVENTS = 1
CHANNEL_UPDATES = 2

g3d = require("lib/g3d")
scene = require("lib/scene")
enet = require("enet")

require("common")

require("scenes/gameworld")
require("physics")

packets = require("packets")
local nethandler = require("nethandler")

local focused = false
CHANNEL_ONE = 0
CHANNEL_EVENTS = 1
CHANNEL_UPDATES = 2

local socket
_G.master = nil
local game

function love.load(args)
if #args < 3 then
print("Usage: client [address] [port] [username]")
love.event.quit(-1)
return
end

local address = args[1] .. ":" .. args[2]
username = args[3]
local username = args[3]

socket = loex.socket.connect(address)
socket.onconnect:catch(onconnect)
socket.ondisconnect:catch(ondisconnect)
socket.onreceive:catch(onreceive)
local socket = loex.socket.connect(address)
assert(socket)

font = love.graphics.newFont(50)
local font = love.graphics.newFont(23)
love.graphics.setFont(font)

scene(require("scenes/joinscreen"))
end

function onconnect(peer)
print("Connected!")
game = {}
game.gravity = 42 -- TODO

master = peer
master:send(packets.join(username), CHANNEL_ONE)
end

function ondisconnect(_) scene(require("scenes/errorscreen"), "disconnected :(") end
game.socket = socket
game.username = username

function onreceive(_, packet)
print("Received " .. packet.type)
game.ondraw = loex.signal.new()
game.onupdate = loex.signal.new()
game.onmousemoved = loex.signal.new()
game.onmousepressed = loex.signal.new()
game.onkeypressed = loex.signal.new()
game.onresize = loex.signal.new()
game.onquit = loex.signal.new()

local handle = nethandler[packet.type]
if not handle then
error("Unknown packet type " .. packet.type)
else
handle(scene(), packet)
end
require("screens.joinscreen").init(game)
end

function love.update(dt)
socket:service()
function love.update(dt) game.onupdate:emit(game, dt) end

local scene = scene()
if scene and scene.update then scene:update(dt) end
end
function love.draw() game.ondraw:emit(game) end

function love.draw()
local scene = scene()
if scene and scene.draw then scene:draw() end
function love.mousepressed(x, y, button, istouch, presses)
game.onmousepressed:emit(game, x, y, button, istouch, presses)
end

function love.mousepressed()
if not focused then focused = true end
end
function love.mousemoved(x, y, dx, dy, istouch) game.onmousemoved:emit(game, x, y, dx, dy, istouch) end

function love.focus(hasFocus) focused = hasFocus end
function love.keypressed(k, scancode, isrepeat) game.onkeypressed:emit(game, k, scancode, isrepeat) end

function love.mousemoved(x, y, dx, dy)
local scene = scene()
if scene and focused and scene.mousemoved then scene:mousemoved(x, y, dx, dy) end
end
function love.resize(w, h) game.onresize:emit(game, w, h) end

function love.keypressed(k)
if k == "escape" then
love.mouse.setRelativeMode(false)
focused = false
end
end

function love.resize(w, h)
g3d.camera.aspectRatio = w / h
g3d.camera.updateProjectionMatrix()
end

function love.quit()
if socket then
print("Disconnecting ....")
socket:disconnect()
end
end
function love.quit() game.onquit:emit(game) end
9 changes: 5 additions & 4 deletions client/packets.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local packets = {}
local encode = loex.socket.encode

function packets.place(x, y, z, t) return ("[type=place;x=%d;y=%d;z=%d;t=%d;]"):format(x, y, z, t) end
function packets.place(x, y, z, t) return encode { type = "place", x = x, y = y, z = z, t = t } end

function packets.breaktile(x, y, z) return ("[type=breaktile;x=%d;y=%d;z=%d;]"):format(x, y, z) end
function packets.breaktile(x, y, z) return encode { type = "breaktile", x = x, y = y, z = z } end

function packets.join(username) return ("[type=join;username=%s;]"):format(username) end
function packets.join(username) return encode { type = "join", username = username } end

function packets.move(x, y, z) return ("[type=move;x=%f;y=%f;z=%f;]"):format(x, y, z) end
function packets.move(x, y, z) return encode { type = "move", x = x, y = y, z = z } end

return packets
13 changes: 13 additions & 0 deletions client/quad.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local a = -1.0
local b = 1.0
return function(texture)
return g3d.newModel({
{ 0, a, a, 1, 1 },
{ 0, b, b, 0, 0 },
{ 0, b, a, 0, 1 },

{ 0, a, a, 1, 1 },
{ 0, a, b, 1, 0 },
{ 0, b, b, 0, 0 },
}, texture)
end
16 changes: 0 additions & 16 deletions client/scenes/errorscreen.lua

This file was deleted.

Loading