OS in Rust
“Snake” is an ambitious bare-metal snake game implementation using interrupts, memory allocation, graphics, I/O, and more in unified human-centered effort.
For those of you not familiar with snake, here is a much cuter version available from Google.
WASDsrc/interrupts.rssrc/snake.rs file.W - for “up”A - for “left”S - for “right”D - for “down”Q for QEMU quit.Display is perhaps the most intensive part of this project as it requires maintaining internal state and responding to user input
│ (0xB3) on the leftmost and rightmost column.─ (0xC4) on the topmost and bottommost row.┌┐└┘Bounding elements are statically maintained in the highest and lowest indexed locations of both rows and columns, and are unalterable through gameplay. Food item and snake elements may not occupy any space wherein a bounding element is present. Food item elements, placed by the executing code, must be restricted not to be placed in the same grid location as a bounding element or snake elements. Snake elements, as they are directed by user input, may be directed into grid locations in which bounding elements are present, but doing so results in the executable terminating - regarded as a gameplay loss for the player.
ó:Food item elements are placed arbitrarily at any point within the grid unoccupied by another gameplay element, whether a bounding elements or a snake element.
█:If a snake element is moved onto the grid location of a food element, the gameplay state is updated in the following way: a new snake element is created at the location of the food element, and all other snake elements are maintained in their current location.
Snake elements placed initially by the gameplay server in either a fixed or randomized starting location at from that point on set according to user input and then translate through the space in accordance with the user input direction. While moving, the snake may move through grid spaces with food items in order for the snake to grow larger (by adding a single snake element) but may not move through spaces already occupied by snake or boundary elements.
static mut to maintain the food item element’s location.VecDeque to maintain the locations of an unbounded number of snake elements.static mut SNEK: alloc::collections::vec_deque::VecDeque<[usize; 2]> = alloc::collections::vec_deque::VecDeque::new();VecDeque appears to implement the “queue” abstract data type within the alloc crate.A new snake element should be created relative to the most recently added snake element, either in the same row and an adjacent column, or the same column and an adjacent row, according to whether the snake is directed to move up, down, left, or right
If the new snake element would be created in a currently empty grid space, the least recently placed snake element is removed from the game state.
If the new snake element would be created in a grid space already occupied by an existing bounding or snake element, the executable terminates in what is regarded as a gameplay loss for the player.
If the new snake element would be created in a grid space occupied by a food item element, the food item element is set to a new, abritrary location and the game state update concludes.
If there are no available locations for a new food item, the executable terminates in what is regarded as a gameplay victory for the player.
static mut.