Skip to content
Snippets Groups Projects
Verified Commit d747cba9 authored by Louis's avatar Louis :fire:
Browse files

Fix readme formatting

parent 078ba9e0
No related branches found
No related tags found
No related merge requests found
...@@ -40,34 +40,36 @@ index in some theoretical sprite sheet. ...@@ -40,34 +40,36 @@ index in some theoretical sprite sheet.
1. Create one or more rules that define a pattern to match, a value to output, and optionally a percentage 1. Create one or more rules that define a pattern to match, a value to output, and optionally a percentage
chance for that rule to be chosen. chance for that rule to be chosen.
* ```rust ```rust
use micro_autotile::AutoTileRule; use micro_autotile::AutoTileRule;
const GROUND: usize = 0; const GROUND: usize = 0;
const WALL: usize = 1; const WALL: usize = 1;
let alt_ground_rule = AutoTileRule::single_any_chance(GROUND, vec![123, 124, 125], 0.2); let alt_ground_rule = AutoTileRule::single_any_chance(GROUND, vec![123, 124, 125], 0.2);
let fallback_ground_rule = AutoTileRule::exact(GROUND, 126); let fallback_ground_rule = AutoTileRule::exact(GROUND, 126);
``` ```
2. (Optional) Put together your rules in a rule set. This can be skipped and the rule structs used directly 2. (Optional) Put together your rules in a rule set. This can be skipped and the rule structs used directly
* ```rust ```rust
use micro_autotile::{AutoRuleSet, AutoTileRule}; use micro_autotile::{AutoRuleSet, AutoTileRule};
let ground_rules = AutoRuleSet::new(vec![alt_ground_rule, fallback_ground_rule]); let ground_rules = AutoRuleSet::new(vec![alt_ground_rule, fallback_ground_rule]);
let wall_rules = AutoTileRule::exact(WALL, 35).into(); let wall_rules = AutoTileRule::exact(WALL, 35).into();
let combined_rules = wall_rules + ground_rules; let combined_rules = wall_rules + ground_rules;
``` ```
3. Elsewhere, generate a slice of level data wrapped in a `TileLayout` struct. This represents a single tile 3. Elsewhere, generate a slice of level data wrapped in a `TileLayout` struct. This represents a single tile
(the central element) and its surrounding neighbors. The order of the neighbors is important, and is laid (the central element) and its surrounding neighbors. The order of the neighbors is important, and is laid
out as though in a flattened grid. out as though in a flattened grid.
* ```rust ```rust
use micro_autotile::TileLayout; use micro_autotile::TileLayout;
let layout = TileLayout::filled([ let layout = TileLayout::filled([
GROUND, GROUND, GROUND, GROUND, GROUND, GROUND,
GROUND, WALL, GROUND, GROUND, WALL, GROUND,
GROUND, GROUND, GROUND, GROUND, GROUND, GROUND,
]); ]);
``` ```
4. Produce an output using either the rule set or the rule directly (the same methods exist for both) 4. Produce an output using either the rule set or the rule directly (the same methods exist for both)
* ```rust ```rust
let output = combined_rules.resolve_match(&layout); let output = combined_rules.resolve_match(&layout);
assert_eq!(output, Some(35)); assert_eq!(output, Some(35));
``` ```
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment