forked from corpsmoderne/bevy-laser
initial commit
This commit is contained in:
commit
a679914fa0
3928
Cargo.lock
generated
Normal file
3928
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "bevy_laser"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.12.1"
|
||||
rand = "0.8.5"
|
80
src/main.rs
Normal file
80
src/main.rs
Normal file
@ -0,0 +1,80 @@
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
#[derive(Component,Debug)]
|
||||
struct Pos(Vec2);
|
||||
#[derive(Component,Debug)]
|
||||
struct Ray(Vec2);
|
||||
#[derive(Component,Debug)]
|
||||
struct Col(Color);
|
||||
#[derive(Component,Debug)]
|
||||
struct Size(f32);
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, (animate, rand_color, gizmos))
|
||||
.run()
|
||||
}
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
) {
|
||||
commands.spawn(Camera2dBundle {
|
||||
transform: Transform::from_xyz(250.0, 0.0, 0.0),
|
||||
..default()
|
||||
});
|
||||
|
||||
commands.spawn((
|
||||
Pos(Vec2::new(0.0, 0.0)),
|
||||
Ray(Vec2::new(100.0, 5.0)),
|
||||
Col(Color::rgba(1.0, 0.0, 1.0, 1.0)),
|
||||
Size(10.0)
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Pos(Vec2::new(0.0, 0.0)),
|
||||
Ray(Vec2::new(200.0, 1.0)),
|
||||
Col(Color::rgba(1.0, 1.0, 0.0, 1.0)),
|
||||
Size(20.0)
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
fn animate(
|
||||
time: Res<Time>,
|
||||
mut query: Query<(&mut Pos, &Ray)>
|
||||
) {
|
||||
let t = time.elapsed_seconds();
|
||||
for (mut pos, ray) in &mut query {
|
||||
pos.0.x = (ray.0.y*t).cos() * ray.0.x;
|
||||
pos.0.y = (ray.0.y*t).sin() * ray.0.x;
|
||||
}
|
||||
}
|
||||
|
||||
fn rand_color(
|
||||
time: Res<Time>,
|
||||
mut query: Query<&mut Col>
|
||||
) {
|
||||
let t = time.delta_seconds();
|
||||
for mut col in &mut query {
|
||||
if let Color::Rgba{ ref mut red, .. } = col.0 {
|
||||
*red += t;
|
||||
if *red > 1.0 {
|
||||
*red = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn gizmos(
|
||||
mut gizmos: Gizmos,
|
||||
query: Query<(&Pos,&Col,&Size)>
|
||||
) {
|
||||
for (Pos(pos), Col(color), Size(size)) in &query {
|
||||
gizmos.circle_2d(*pos, *size, *color);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user