Skip to content

Commit

Permalink
Start a new Bevy Game
Browse files Browse the repository at this point in the history
We’ll start off by using cargo to scaffold a new project.

```rust
cargo new snake
cd snake
```

A `cargo run` now will give us the usual `"Hello World"` output we get from a new project.

We’ll add `bevy` as a dependency.

```rust
cargo add bevy
```

and replace the code in `src/main.rs` with some project scaffolding.

```rust
use bevy::prelude::*;

fn main() {
    App::new()
        .insert_resource(WindowDescriptor {
            title: "Snake!".to_string(),
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .insert_resource(ClearColor(Color::rgb(
            0.52, 0.73, 0.17,
        )))
        .add_startup_system(setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands
        .spawn_bundle(OrthographicCameraBundle::new_2d());
}
```

The scaffolding sets the name of the window that Bevy creates to `Snake!` and adds the default group of plugins from the bevy prelude.

We also set the default background to a green color and add a new system that will run once when our game starts up.

The `setup` system spawns in a new 2d camera, which we’ll need to be able to render any of the 2d sprites we want to use for the board or the snake or even the food.

Also take a moment to download the assets we’ll be using [from GitHub](TODO) and put them in the `assets` directory at the root of the project. We’ll use these for fonts, sprites, and sounds later in the project.

If we `cargo run` now, we’ll see a window.
  • Loading branch information
ChristopherBiscardi committed Apr 21, 2022
0 parents commit b5419ec
Show file tree
Hide file tree
Showing 4 changed files with 3,240 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/target

0 comments on commit b5419ec

Please sign in to comment.