option_1 := () {
active_menu = .{void};
state = .Playing;
+ reset_game();
};
["Quit"]
Lost_Options :: struct {
["Play again"]
option_1 := () {
-
+ active_menu = .{void};
+ state = .Playing;
+ reset_game();
};
["Main menu"]
option_2 := () {
state = .MainMenu;
active_menu = .{ Main_Menu_Options };
-
- the_snake = snake_make(.{ 0, 0 });
- the_food = .{ 10, 10 };
};
}
load :: () {
random.set_seed(clock.time());
- hb.window.setTitle("Snake 🐍");
+ hb.window.setTitle("Snake 🐍");
hb.utils.load_assets(^assets);
- the_snake = snake_make(.{ 0, 0 });
- the_food = .{ 10, 10 };
-
active_menu = .{ Main_Menu_Options };
}
+reset_game :: () {
+ if the_snake.body.data != null {
+ array.free(^the_snake.body);
+ }
+
+ the_snake = snake_make(.{ 0, 0 });
+ the_food = .{ random.between(0, 15), random.between(0, 10) };
+}
+
cell_contains_snake_body :: (p: Vec2i) => {
for ^it: the_snake.body {
if *it == p do return true;