Rusty Gear Solid A simple snek game written in Rust using Piston as the graphics library.
- Fixed sized world on screen
- Has a small snek shaped like blocks.
- Starts as 3 blocks
- Small square shaped food spawns on the screen
- When the head of the snek is on the same block as the food the snek size increases by 1 block
- No scoring system
- Food reappears as soon as it is eaten.
- snek can move with arrows or WASD keys.
- If snek is vertical only left and right (A and D) work
- If snek is horizontal only Up and down (W and S) work.
- snek moves at a constant unchanging speed throughout the session.
- Box has walls; you cannot wrap around the screen like in some games.
- Before starting player can choose one of 3 difficulties which affect he speed of the snek. 1, 2, or 3 speed.
- 50 by 50 units playing field.
- Game will be only 2D
- Food locations are generated randomly
- Walls will have a thick visible border so it's clear we cannot go through them.
- When the head block of the snek collides with any other of it's blocks. The game ends.
- When the head block collides with the wall the game ends.
- Starting menu has 3 buttons for difficulty. As well as an exit button.
- Upon game over game the game freezes and displays "Game Over" at the top and "Press any Key to go to menu at the bottom. This allows player to take pictures of their achievement. When player presses a key it goes back to main menu.
- You cannot win the game because the snek is you and the game is life ๐ข
- snek starts at center of screen facing right
- Main Function
- Calls show_window()
- show_window() 2. Calls initialize_graphics() 3. Calls display_menu() 4. Calls start_game(listen_selction())
- initialize_graphics()
- (All graphics start as hidden)
- Setup 4 buttons on main menu
- Set up the playing field
- Setup the initial 3 blocks with head facing right.
- Setup first food position set to random_square()
- Draw thick border on the play field
- display_menu():
- Set the menu graphics to shown from hidden
- listen_selection()
- In: The window/play area Return: 1, 2, or 3
- while no clicks
- listen for click
- if the click is on exit
- Exit program
- if the click is on one of the difficulties
- return difficulty level (1, 2, 3)
- while no clicks
- In: The window/play area Return: 1, 2, or 3
- random_square()
- Return a random set of coordinates on the play field
- start_game(int difficulty)
- In: (1, 2, 3) Out: 0 or 1
- Calls hide_menu()
- Calls show_game()
- Call game_loop()
- In: (1, 2, 3) Out: 0 or 1
- hide_menu()
- Hide all the menu graphics
- show_game()
- Set all the game graphics to "visible"
- game_loop(int difficulty)
- while not game_over({head[0], head[1]}):
- Calls next_snek()
- while not game_over({head[0], head[1]}):
- game_over(immutable pair of numbers: head_pos, immutable array of immutable pairs of number: body_pos_array)
- if collide_edges(head_pos):
- return True
- for pair in body_pos_array:
- if pair == head:
- return True
- if pair == head:
- return False
- if collide_edges(head_pos):
- collide_edges(immutable pair of numbers: head_pos, direction)
- Return True or False. True if the head collides with the wall
- if any of these conditions are true
1. x >= 25
2. x <= -25
3. y >= 25
4. y <= -25
- return True
- else
- return False
- if any of these conditions are true
1. x >= 25
2. x <= -25
3. y >= 25
4. y <= -25
- Return True or False. True if the head collides with the wall