Giter Club home page Giter Club logo

test_raylib_simple's Introduction

Rust Simple Game Raylib

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).

Code Overview

Entity Struct

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),
}

Entity Methods

The Entity struct has several methods:

  • new: This method is used to create a new Entity 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.

Main Function

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.

ArrowKey Enum

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,
}

Running the Game

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.

Contributing

Contributions are welcome. Please feel free to submit a pull request or open an issue.

Example

example.mp4

Special Thanks

This project was inspired by the Twitch channel of:
Prof. Andrea PolliniProf. Andrea Pollini
and the supportive Twitch community. Thanks to their encouragement and feedback!

License

This project is licensed under the MIT License - see the LICENSE for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.