generated from trubusoft/bevy-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ep 1 - 6: Component, System, Resource, Event (#1)
* fix tests * Update package name * Add bevy-ball assets * Update readme.md * Remove template code * Move assets to root * episode 2 * Add WindowHelper * trivial reorder * ep3: player movement + helper * ep3: player confinement * Add RandomHelper * ep3: spawn enemies * ep4: enemy movement * ep4: update enemy direction * ep4: confine enemy * ep4: play sound on enemy bounce * ep4: player despawn when hit * ep 5: spawn star * ep 5: collect star * ep 5: score, score default, and on change printing * ep 5: star spawn timer and spawn star overtime * ep 6: spawn enemy overtime * ep 6: example event * Custom Despawn component * ep 6: custom event and passing value to an event * ep 6: high scores - demonstrating that single event can be read by many systems
- Loading branch information
1 parent
f508558
commit 737e89f
Showing
19 changed files
with
559 additions
and
223 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
[package] | ||
name = "bevy-skeleton" | ||
name = "bevy-ball" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bevy = "0.13.2" | ||
rand = "0.8.5" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,2 @@ | ||
Collection of useful docs to quickly start developing with bevy using RustRover on Ubuntu. | ||
|
||
# Setup | ||
|
||
- Install dependencies | ||
|
||
For ubuntu: | ||
|
||
``` | ||
sudo apt update | ||
sudo apt install g++ pkg-config libx11-dev libasound2-dev libudev-dev libxkbcommon-x11-0 | ||
``` | ||
|
||
> More on this: https://github.com/bevyengine/bevy/blob/main/docs/linux_dependencies.md | ||
- Add bevy dependency to `Cargo.toml` | ||
|
||
- Run `cargo build` and check if compilation succeed | ||
|
||
- Enable Query support for RustRover | ||
- `org.rust.cargo.evaluate.build.scripts` | ||
- `org.rust.macros.proc` | ||
|
||
> More on this: https://bevy-cheatbook.github.io/setup/editor/jetbrains.html | ||
- Enable Reformat Code & Optimize Import on Save | ||
|
||
Open Setting > Tools > Action on Save and check `Reformat Code` and `Optimize Import` | ||
|
||
- Enable dynamic linking for faster compile in development | ||
- On Run configuration, append `--features bevy/dynamic_linking` inside the command | ||
- On Settings > Rust > External Linters, add `--features bevy/dynamic_linking` on Additional arguments | ||
|
||
> More on this: https://bevyengine.org/learn/quick-start/getting-started/setup/#dynamic-linking | ||
# Testing | ||
|
||
See [test.rs](src/people/tests.rs) for examples. | ||
|
||
> More on this: https://bevy-cheatbook.github.io/patterns/system-tests.html | ||
# References | ||
|
||
- [Bevy opinionated best practices](https://github.com/tbillington/bevy_best_practices) | ||
Practicing bevy ball game coding | ||
from [a tutorial by Jacques](https://www.youtube.com/playlist?list=PLVnntJRoP85JHGX7rGDu6LaF3fmDDbqyd). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use bevy::prelude::Component; | ||
|
||
#[derive(Component)] | ||
pub struct Despawn {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod components; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use bevy::input::ButtonInput; | ||
use bevy::math::Vec3; | ||
use bevy::prelude::{KeyCode, Res, Transform, Window}; | ||
use rand::random; | ||
|
||
pub mod commons; | ||
|
||
pub struct WindowHelper {} | ||
|
||
impl WindowHelper { | ||
/// Given a &Window, return its center of the screen as Transform | ||
pub fn center(window: &Window) -> Transform { | ||
let middle_x = window.width() / 2.0; | ||
let middle_y = window.height() / 2.0; | ||
Transform::from_xyz(middle_x, middle_y, 0.0) | ||
} | ||
} | ||
|
||
pub struct MovementHelper {} | ||
|
||
impl MovementHelper { | ||
/// Given a keyboard_input, return the final normalized direction as Vec3 | ||
pub fn handle_input(keyboard_input: Res<ButtonInput<KeyCode>>) -> Vec3 { | ||
let mut direction = Vec3::ZERO; | ||
|
||
if keyboard_input.pressed(KeyCode::ArrowLeft) || keyboard_input.pressed(KeyCode::KeyA) { | ||
direction += Vec3::new(-1.0, 0.0, 0.0) | ||
} | ||
if keyboard_input.pressed(KeyCode::ArrowRight) || keyboard_input.pressed(KeyCode::KeyD) { | ||
direction += Vec3::new(1.0, 0.0, 0.0) | ||
} | ||
if keyboard_input.pressed(KeyCode::ArrowUp) || keyboard_input.pressed(KeyCode::KeyW) { | ||
direction += Vec3::new(0.0, 1.0, 0.0) | ||
} | ||
if keyboard_input.pressed(KeyCode::ArrowDown) || keyboard_input.pressed(KeyCode::KeyS) { | ||
direction += Vec3::new(0.0, -1.0, 0.0) | ||
} | ||
|
||
if direction.length() > 0.0 { | ||
direction = direction.normalize(); | ||
} | ||
|
||
return direction; | ||
} | ||
|
||
pub fn confine(window: &Window, unit_translation: Vec3, unit_size: f32) -> Vec3 { | ||
let half_unit_size = unit_size / 2.0; | ||
let x_min = 0.0 + half_unit_size; | ||
let x_max = window.width() - half_unit_size; | ||
let y_min = 0.0 + half_unit_size; | ||
let y_max = window.height() - half_unit_size; | ||
|
||
let mut new_translation = unit_translation; | ||
|
||
// bound x | ||
if new_translation.x < x_min { | ||
new_translation.x = x_min; | ||
} else if new_translation.x > x_max { | ||
new_translation.x = x_max; | ||
} | ||
|
||
// bound y | ||
if new_translation.y < y_min { | ||
new_translation.y = y_min; | ||
} else if new_translation.y > y_max { | ||
new_translation.y = y_max; | ||
} | ||
|
||
new_translation | ||
} | ||
} | ||
|
||
pub struct RandomHelper {} | ||
|
||
impl RandomHelper { | ||
pub fn random_f32() -> f32 { | ||
random::<f32>() | ||
} | ||
} | ||
|
||
pub struct SoundHelper {} | ||
|
||
impl SoundHelper { | ||
pub fn bounce_sound() -> String { | ||
return if RandomHelper::random_f32() < 0.5 { | ||
"audio/pluck_001.ogg".to_string() | ||
} else { | ||
"audio/pluck_002.ogg".to_string() | ||
}; | ||
} | ||
|
||
pub fn obtain_star_sound() -> String { | ||
"audio/laserLarge_000.ogg".to_string() | ||
} | ||
|
||
pub fn game_over_sound() -> String { | ||
"audio/explosionCrunch_000.ogg".to_string() | ||
} | ||
} |
Oops, something went wrong.