Last active
May 8, 2021 15:14
-
-
Save wolf81/9b89f37f83f875cf902fcf3685553534 to your computer and use it in GitHub Desktop.
Simplified version of Gamestate with ticks, used by both client and server - every tick the server sends new Gamestate to connected clients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local state = Class {} | |
function state:init() | |
self.tick = 0 -- this tick is used by jitter buffer to figure out which state is newer | |
self.entities = {} | |
end | |
function state:paddleAttack(paddleId) | |
-- server calls this method when player performs an attack with laser | |
end | |
function state:paddleMove(paddleId, direction) | |
-- server calls this method when player moves up or down | |
end | |
function state:update(dt) | |
self.tick = self.tick + 1 -- every update call increase tick value | |
-- process entity list, update state of all entities (simplified) | |
for _, entity in ipairs(entities) do entity:update(dt) end | |
end | |
return state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment