Hex  Falling Hexagon Game
A centered falling block game with hexagons. You must match the same colour together to clear rows and continue playing. If the blocks reach the centre then you are out. The player can select a ring of hexegons and spin it around to chnage their positions. For this project I used Rust with the SDL2 game library.
This was made in 48 hours for a game jam, as an opportunity to practice Rust and SDL2.
Linux and Windows x86_64 builds on Itch.io
The most interesting/frustrating part was working with a hexagonal grid. The grid is stored in an array, so indexing individual tiles for the hexagonal board took a while to get right. Rendering the grid properly also took some trial and error. The code works the same for arbitrarily large grids, but when the grid gets very big the hexagon rendering will no longer be correct.
This function that takes a function in it’s arguments is for the 4 different clear operations that re used to update the board state.
fn per_neighbour(&mut self, n: usize, x: usize, y: usize, t: Tile, f: fn(&mut Self, usize, usize, usize, Tile) > usize) > usize {
//check l/r
let mut n = n;
n = f(self, n, x + 1, y, t);
n = f(self, n, if x == 0 { get_y_size(y)  1} else {x  1}, y, t);
if y != BOARD_RADIUS  1 {
let outer = (x as f64) / (y as f64);
if outer.fract() < 0.1 {
let outer = outer as usize;
n = f(self, n, x + outer, y + 1, t);
n = f(self, n, x + outer + 1, y + 1, t);
let x = if outer == 0 && x == 0 {x + get_y_size(y + 1) } else { x };
n = f(self, n, x + outer  1, y + 1, t);
} else {
n = f(self, n, (x as f64 + outer).floor() as usize, y + 1, t);
n = f(self, n, (x as f64 + outer).ceil() as usize, y + 1, t);
}
}
if y > 1 {
let inner = (x as f64) / (y as f64);
if inner.fract() < 0.1 {
let outer = inner as usize;
n = f(self, n, x  outer, y  1, t);
} else {
n = f(self, n, (x as f64  inner).floor() as usize, y  1, t);
n = f(self, n, (x as f64  inner).ceil() as usize, y  1, t);
}
}
n
}
The game also has the ability to change it’s color palette. This is used to show the progress of difficulty.
rules

Hexagons spawn in 6’s if no blocks fell during the previous drop.

They move outward towards the edge of the board every drop cycle

One can select a ring of hexagons and spin them around

Match 5 Hexagons of the same colour to remove them from the board.

If the newly spawning hexagons spawn on top of other hexagons, then it’s game over.