This repository implements a smart contract (a game) for Starknet in cairo language (cairo 0.2.2).
The goal of this repository is to test the dojoengine
framework combined with a math library (cubit
for computations in the smart contract) and react
, pixi
on front side.
This boat game is a prototype of a boat regatta. The boat moves forward depending on the wind and the direction of the boat (the sail is considered always at optimum !).
This smart contract defines a map of 8 * 8 cells , each cell have specific wind information (wind speed, direction (as a vector)). Each cell represents a square of 100 by 100, For example, the tile (0; 0) corresponds to coordinates (0; 0) to (100; 100).
Each cell has a specific wind information (speed and direction). The wind is displayed as an arrow oriented relative to the direction and scaled depending on the wind speed.
The boat next position is computed with a boat polar table and takes only the wind and the boat direction into account.
The smart contract computes very precisely the position of the boat (using Fixed type of the cubit library).
The graphical representation approximates the position displayed. For example, coordinates (91.352487; 93.65454) will be rounded to (91; 93).
The polar of a boat is a table that gives the effective speed of a boat depending on the wind incidence with the boat direction. For exemple, for a wind speed of 8 knot and 52 degrees the boat will move at a speed of 6.77 knot
For the moment this prototype allows the user to
- create a map.
- spawn a boat at location (90, 90).
- change the boat position with a "step" button.
- change the boat direction with a "turn" button. (45 degrees clock-wise)
Dive into this straightforward example to understand how to meld React with Dojo.
This integration taps into the powerful libraries designed by Lattice:
Prerequisites: First and foremost, ensure that Dojo is installed on your system. If it isn't, you can easily get it set up with:
curl -L https://install.dojoengine.org | bash
Followed by:
dojoup
For an in-depth setup guide, consult the Dojo book.
After cloning the project, execute the following:
- init submodule
TO REMOVE
git submodule update --init --recursive
- Terminal 1 - Katana:
cd contracts && katana --disable-fee
- Terminal 2 - Contracts:
cd contracts && sozo build && sozo migrate
// Basic Auth - This will allow burner Accounts to interact with the contracts
sh ./contracts/scripts/default_auth.sh
- Terminal 3 - Client:
cd client && yarn && yarn dev
- Terminal 4 - Torii:
Uncomment the 'world_address' parameter in contracts/Scarb.toml
then:
cd contracts && torii --world {world_address}
-
Game interface: Launch your browser and navigate to http://localhost:5173/.
-
for debug: Once torii is running , one can check the SQL-lite database via a graphQL interface accessible at http://0.0.0.0:8080/graphql