Write Gameplay
Define Your Game State
Think about the game state that are permanante and you want to store on the blockchain.
Define those states in terms of u64
numbers inside definition.rs
For example, in the demo there're 2 states, total_steps
and current_position
Remember to update STATE_SIZE when number of state changes
Make sure to only use SpinGameStates to stored global states.
Define the Gameplay
Spin currently only supports game architecture by utilizing 3 functions.
These functions will interface with the ZK prover and frontend.
You can find the functions at
gameplay/provable_game_logic/src/gameplay.rs
Initialize the Game
Prepare the game to start, the input args is the SpinGameStates
you defined in form of a vector of u64
Process a Step in the Game
when the player performs an action and moves to the next step of the game. Step should be state mutating.
Read the Game State
A viewable function that gets the current state.
Advanced
Define Game States That Doesn't Go On-Chain
If you want to define any states that only exists within the game session and won't go on-chain. You can do this by adjusting your STATE_SIZE
variable and adjust the get_game_state
and initialize_game
accordingly.
The caveat here is the frontend won't have access to these states not returned through get_game_state
anymore. However, we have plan to add dedicated get_onchain_game_state
in the future to allow that.
Last updated