This is a simple game built in Rust using the Raylib game development library. The game involves an entity (red circle) that moves around a canvas and interacts with a target (blue circle).
The Entity
struct represents a circle with properties like position (x, y), radius, color, and the size of the canvas it's on. It has methods to get and set its position, and to draw itself on the canvas.
struct Entity {
x: f32,
y: f32,
radius: i32,
color: Color,
canvas: (i32, i32),
}
The Entity
struct has several methods:
new
: This method is used to create a newEntity
instance.get_x
&get_y
: These methods are used to get the x and y coordinates of the entity.set_x
&set_y
: These methods are used to set the x and y coordinates of the entity. They also handle the logic for wrapping the entity around the canvas.draw
: This method is used to draw the entity on the canvas.
The main
function initializes the game, creates the entity and target, and enters the main game loop. In each iteration of the loop, it checks if any arrow keys are pressed and moves the entity accordingly. It also checks if the entity has collided with the target. If a collision is detected, the target is moved to a new random position.
The ArrowKey
enum and its associated methods are used to handle the arrow key inputs from the user.
With a transcode to raylib keys.
enum ArrowKey {
Up,
Down,
Left,
Right,
}
To run the game, you need to have Rust installed on your machine. You can then use the cargo run
command in the terminal from the root directory of the project.
Contributions are welcome. Please feel free to submit a pull request or open an issue.
example.mp4
This project was inspired by the Twitch channel of:
Prof. Andrea Pollini
and the supportive Twitch community. Thanks to their encouragement and feedback!
This project is licensed under the MIT License - see the LICENSE for details.