summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cell.rs6
-rw-r--r--src/main.rs141
2 files changed, 72 insertions, 75 deletions
diff --git a/src/cell.rs b/src/cell.rs
index 51b68e8..b697076 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -76,10 +76,12 @@ pub fn insert(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) {
}
}
-pub fn start_explosion(commands: &mut Commands, mut q: Query<(Entity, &Cell), Without<Timer>>) {
+pub fn start_explosion(mut commands: Commands, mut q: Query<(Entity, &Cell), Without<Timer>>) {
for (entity, cell) in q.iter_mut() {
if cell.occupant == Occupant::Explosion {
- commands.insert(entity, (Timer::from_seconds(0.1, true),));
+ commands
+ .entity(entity)
+ .insert(Timer::from_seconds(0.1, true));
}
}
}
diff --git a/src/main.rs b/src/main.rs
index 79c0f2b..1c1d49a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,36 +3,38 @@ use bevy::prelude::*;
use gems::cell::{self, Cell, Occupant};
use gems::constants;
use rand::{thread_rng, Rng};
+use std::time::Duration;
-fn star_spawning_system(commands: &mut Commands, time: Res<Time>, mut q: Query<&mut Timer>) {
+fn star_spawning_system(mut commands: Commands, time: Res<Time>, mut q: Query<&mut Timer>) {
for mut timer in q.iter_mut() {
if !timer.repeating() {
- timer.tick(time.delta_seconds());
+ timer.tick(time.delta());
if timer.just_finished() {
- timer.set_duration(thread_rng().gen_range(2..5) as f32);
+ timer.set_duration(Duration::new(thread_rng().gen_range(2..5), 0));
timer.reset();
- commands
- .spawn(SpriteSheetBundle {
+ commands.spawn_bundle((
+ SpriteSheetBundle {
sprite: TextureAtlasSprite::new(constants::TILESHEET_STAR1),
transform: Transform {
- translation: Vec3 {
- x: thread_rng().gen_range(-300..300) as f32,
- y: thread_rng().gen_range(-200..300) as f32,
- z: 0.0,
- },
+ translation: Vec3::new(
+ thread_rng().gen_range(-300..300) as f32,
+ thread_rng().gen_range(-200..300) as f32,
+ 0.0,
+ ),
scale: Vec3::splat(thread_rng().gen_range(1..3) as f32),
..Default::default()
},
..Default::default()
- })
- .with(Timer::from_seconds(0.25, true));
+ },
+ Timer::from_seconds(0.25, true),
+ ));
}
}
}
}
pub fn setup(
- commands: &mut Commands,
+ mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
@@ -48,75 +50,67 @@ pub fn setup(
);
let atlas_handle = texture_atlases.add(atlas);
- commands
- .spawn(Camera2dBundle::default())
- .spawn(SpriteBundle {
- material: materials.add(background.into()),
- transform: Transform {
- translation: Vec3 {
- x: 50.0,
- y: 0.0,
- z: 0.0,
- },
- scale: Vec3::splat(constants::TILE_SCALE),
- ..Default::default()
- },
+ commands.spawn_bundle(OrthographicCameraBundle::new_2d());
+ commands.spawn_bundle(SpriteBundle {
+ material: materials.add(background.into()),
+ transform: Transform {
+ translation: Vec3::new(50.0, 0.0, 0.0),
+ scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
- })
- .spawn(SpriteSheetBundle {
- sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT1),
- texture_atlas: atlas_handle.clone(),
- transform: Transform {
- translation: Vec3 {
- x: 225.0,
- y: -200.0,
- z: 0.0,
- },
- scale: Vec3::splat(constants::TILE_SCALE),
- ..Default::default()
- },
+ },
+ ..Default::default()
+ });
+ commands.spawn_bundle(SpriteSheetBundle {
+ sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT1),
+ texture_atlas: atlas_handle.clone(),
+ transform: Transform {
+ translation: Vec3::new(225.0, -200.0, 0.0),
+ scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
- })
- .spawn((Timer::from_seconds(1.0, false),))
- .spawn(SpriteSheetBundle {
- sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT2),
- texture_atlas: atlas_handle.clone(),
- transform: Transform {
- translation: Vec3 {
- x: 225.0,
- y: -200.0 + (-constants::TILE_SIZE) * constants::TILE_SCALE,
- z: 0.0,
- },
- scale: Vec3::splat(constants::TILE_SCALE),
- ..Default::default()
- },
+ },
+ ..Default::default()
+ });
+ commands.spawn_bundle((Timer::from_seconds(1.0, false),));
+ commands.spawn_bundle(SpriteSheetBundle {
+ sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT2),
+ texture_atlas: atlas_handle.clone(),
+ transform: Transform {
+ translation: Vec3::new(
+ 225.0,
+ -200.0 + (-constants::TILE_SIZE) * constants::TILE_SCALE,
+ 0.0,
+ ),
+ scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
- });
+ },
+ ..Default::default()
+ });
for i in 0..constants::GRID_SIZE {
for j in 0..constants::GRID_SIZE {
- commands
- .spawn(SpriteSheetBundle {
+ commands.spawn_bundle((
+ SpriteSheetBundle {
texture_atlas: atlas_handle.clone(),
sprite: TextureAtlasSprite::new(constants::TILESHEET_NONE1),
transform: Transform {
- translation: Vec3 {
- x: ((i as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 320.0,
- y: ((j as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 160.0,
- z: 1.0,
- },
+ translation: Vec3::new(
+ ((i as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 320.0,
+ ((j as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 160.0,
+ 1.0,
+ ),
scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
},
..Default::default()
- })
- .with(Cell::new(i, j));
+ },
+ Cell::new(i, j),
+ ));
}
}
}
fn animation_system(
- commands: &mut Commands,
+ mut commands: Commands,
time: Res<Time>,
mut q: Query<(
Entity,
@@ -126,7 +120,7 @@ fn animation_system(
)>,
) {
for (entity, cell, mut timer, mut sprite) in q.iter_mut() {
- timer.tick(time.delta_seconds());
+ timer.tick(time.delta());
if timer.finished() {
let index = match sprite.index {
constants::TILESHEET_EXPLOSION1 => constants::TILESHEET_EXPLOSION2,
@@ -148,9 +142,9 @@ fn animation_system(
if let Some(mut cell) = cell {
cell.occupant = Occupant::None;
sprite.index = cell.occupant.to_index();
- commands.remove_one::<Timer>(entity);
+ commands.entity(entity).remove::<Timer>();
} else {
- commands.despawn(entity);
+ commands.entity(entity).despawn();
}
}
}
@@ -158,7 +152,7 @@ fn animation_system(
}
fn cosmonaut_detect_system(
- commands: &mut Commands,
+ mut commands: Commands,
windows: Res<Windows>,
mut q: Query<(&Transform, &TextureAtlasSprite)>,
) {
@@ -179,13 +173,14 @@ fn cosmonaut_detect_system(
> cursor_position.y
&& sprite.index == constants::TILESHEET_COSMONAUT1
{
- commands
- .spawn(SpriteSheetBundle {
+ commands.spawn_bundle((
+ SpriteSheetBundle {
sprite: TextureAtlasSprite::new(constants::TILESHEET_VISOR1),
transform: *transform,
..Default::default()
- })
- .with(Timer::from_seconds(0.1, true));
+ },
+ Timer::from_seconds(0.1, true),
+ ));
}
}
}
@@ -283,7 +278,7 @@ impl Plugin for GemsPlugin {
pub fn main() {
App::build()
- .add_resource(WindowDescriptor {
+ .insert_resource(WindowDescriptor {
title: "gems".to_string(),
width: constants::WINDOW_WIDTH,
height: constants::WINDOW_HEIGHT,