Skip to content

Commit

Permalink
bevy -> 0.14.1, buggy faster projectiles
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonBurke committed Aug 28, 2024
1 parent 319c107 commit dec7b4c
Show file tree
Hide file tree
Showing 13 changed files with 2,096 additions and 506 deletions.
2,400 changes: 2,006 additions & 394 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "propietary"

[dependencies]
bevy = { version = "0.13.0", default-features = true, features = [
bevy = { version = "0.14.1", default-features = true, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
Expand All @@ -21,8 +21,8 @@ bevy-inspector-egui = "0.23.0"
log = { version = "0.4.2", features = ["max_level_debug", "release_max_level_warn"] }
# bevy_rapier2d = "0.25.0"
lazy_static = "1.5.0"
hexx = "0.17.0"
bevy_magic_light_2d = { git = "https://github.com/zaycev/bevy-magic-light-2d.git" } # "0.7.0"
hexx = { git = "https://github.com/ManevilleF/hexx" }# version = "0.17.0" }
bevy_magic_light_2d = "0.8.0" # { git = "https://github.com/zaycev/bevy-magic-light-2d.git" }
libnoise = "1.1"
enum-map = "2.7.3"

Expand Down
2 changes: 1 addition & 1 deletion rustchannel.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
# channel = "nightly"
85 changes: 20 additions & 65 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::RefCell};
use std::cell::RefCell;

use bevy::utils::hashbrown::HashSet;
use enum_map::{enum_map, EnumMap};
Expand Down Expand Up @@ -36,34 +36,19 @@ pub mod resource_node {

pub const ASSET_PATH: &str = "grass.png";
pub const Z_POS: f32 = 1.;
pub const COLOR: Color = Color::Rgba {
red: 240. / 255.,
green: 240. / 255.,
blue: 60. / 255.,
alpha: 1.,
};
pub const COLOR: Color = Color::srgba(240. / 255., 240. / 255., 60. / 255., 1.);
}

pub mod coal_node {
use bevy::prelude::*;

pub const COLOR: Color = Color::Rgba {
red: 20. / 255.,
green: 20. / 255.,
blue: 20. / 255.,
alpha: 1.,
};
pub const COLOR: Color = Color::srgba(20. / 255., 20. / 255., 20. / 255., 1.);
}

pub mod mineral_node {
use bevy::prelude::*;

pub const COLOR: Color = Color::Rgba {
red: 120. / 255.,
green: 240. / 255.,
blue: 120. / 255.,
alpha: 1.,
};
pub const COLOR: Color = Color::srgba(120. / 255., 240. / 255., 120. / 255., 1.);
}

pub mod scrap {
Expand All @@ -73,12 +58,7 @@ pub mod scrap {
pub const LIFETIME_PER_METAL: u32 = 3;
pub const LIFETIME_OFFSET: u32 = 50;
pub const Z_POS: f32 = 1.;
pub const COLOR: Color = Color::Rgba {
red: 100. / 255.,
green: 100. / 255.,
blue: 100. / 255.,
alpha: 1.,
};
pub const COLOR: Color = Color::srgba(100. / 255., 100. / 255., 100. / 255., 1.);
}

/* pub const VAR: Simplex<2> = Source::simplex(42); */
Expand Down Expand Up @@ -134,43 +114,27 @@ pub mod distributor {

pub const ASSET_PATH: &str = "dist.png";
pub const STORE_CAPACITY: u32 = 1000;
pub const COLOR: Color = Color::Rgba {
red: 241. / 255.,
green: 240. / 255.,
blue: 110. / 255.,
alpha: 1.,
};
pub const COLOR: Color = Color::srgba(241. / 255., 240. / 255., 110. / 255., 1.);
pub const RANGE: u32 = 3;
}

pub mod wall {
use bevy::prelude::*;

pub const COLOR: Color = Color::Rgba {
red: 0. / 255.,
green: 0. / 255.,
blue: 0. / 255.,
alpha: 1.,
};
pub const COLOR: Color = Color::srgba(0. / 255., 0. / 255., 0. / 255., 1.);
}

pub mod metal {
use bevy::prelude::*;

pub const COLOR: Color = Color::Rgba {
red: 200. / 255.,
green: 200. / 255.,
blue: 200. / 255.,
alpha: 1.,
};
pub const COLOR: Color = Color::srgba(200. / 255., 200. / 255., 200. / 255., 1.);
}

pub mod z_order {
pub const PROJECTILE: f32 = 100.;
}

pub mod resource_blob {
}
pub mod resource_blob {}

pub const SECONDS_PER_TICK: f32 = 2.;
pub const PROJECTILE_MOVE_END_TICK_PORTION: f32 = 0.75;
Expand All @@ -187,18 +151,14 @@ pub mod unit {
pub const MAX_PARTS: u32 = 100;
pub const MAX_HEALTH: u32 = 100;
pub const MAX_AGE: u32 = 100;
pub const COLOR: Color = Color::Rgba {
red: 150. / 255.,
green: 150. / 255.,
blue: 150. / 255.,
alpha: 1.,
};
pub const LIGHT_COLOR: Color = Color::Rgba {
red: 241. / 255.,
green: 240. / 255.,
blue: 110. / 255.,
alpha: 1.,
};
pub const COLOR: Color = /* Color::Srgba {
red: 150. / 255.,
green: 150. / 255.,
blue: 150. / 255.,
alpha: 1.,
}; */
Color::srgba(150. / 255., 150. / 255., 150. / 255., 1.);
pub const LIGHT_COLOR: Color = Color::srgba(241. / 255., 240. / 255., 110. / 255., 1.);
}

#[derive(enum_map::Enum)]
Expand All @@ -208,15 +168,10 @@ pub enum UnitPart {
Generate,
Work,
Battery,
}
}

pub mod laser {
use bevy::prelude::*;

pub const COLOR: Color = Color::Rgba {
red: 240. / 255.,
green: 0. / 255.,
blue: 0. / 255.,
alpha: 1.,
};
}
pub const COLOR: Color = Color::srgba(240. / 255., 0. / 255., 0. / 255., 1.);
}
5 changes: 3 additions & 2 deletions src/debug/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy::{
prelude::*,
render::view::RenderLayers,
};
use bevy_magic_light_2d::gi::render_layer::ALL_LAYERS;

use crate::components::FpsText;

Expand Down Expand Up @@ -34,12 +35,12 @@ fn create_fps_text(mut commands: Commands, asset_server: Res<AssetServer>) {
TextStyle {
font: asset_server.load("fonts/outfit.ttf"),
font_size: 60.0,
color: Color::GOLD,
color: Color::WHITE,
},
),
]),
FpsText,
RenderLayers::all(),
RenderLayers::from_layers(ALL_LAYERS),
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Plugin for EnginePlugin {
fn tick_event(mut event_writer: EventWriter<TickEvent>, mut projectile_timer: ResMut<ProjectileMoveEndTimer>) {
event_writer.send(TickEvent);

projectile_timer.0 = Timer::from_seconds(SECONDS_PER_TICK, TimerMode::Once);
projectile_timer.0 = Timer::from_seconds(SECONDS_PER_TICK * PROJECTILE_MOVE_END_TICK_PORTION, TimerMode::Once);
}

fn projectile_move_end_event(mut event_writer: EventWriter<ProjectileMoveEndEvent>, mut projectile_timer: ResMut<ProjectileMoveEndTimer>, time: Res<Time>) {
Expand Down
4 changes: 2 additions & 2 deletions src/engine/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy::{
prelude::*,
render::view::RenderLayers,
};
use bevy_magic_light_2d::prelude::{LightOccluder2D, OmniLightSource2D, CAMERA_LAYER_OBJECTS, CAMERA_LAYER_WALLS};
use bevy_magic_light_2d::{gi::render_layer::ALL_LAYERS, prelude::{LightOccluder2D, OmniLightSource2D, CAMERA_LAYER_OBJECTS, CAMERA_LAYER_WALLS}};
use hexx::{hex, shapes};
use libnoise::Generator;

Expand Down Expand Up @@ -156,5 +156,5 @@ fn resource_node_light(world_pos: Vec2, commands: &mut Commands, color: Color) {
},
..default()
})
.insert(RenderLayers::all());
.insert(RenderLayers::from_layers(ALL_LAYERS));
}
21 changes: 3 additions & 18 deletions src/engine/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,9 @@ pub const HEX_SIZE: Vec2 = Vec2::splat(64.0);
pub const CHUNK_SIZE: u32 = 5;
const COLORS: [Color; 3] = [
/* Color::BLUE, Color::WHITE, Color::RED, */
Color::Rgba {
red: 60. / 255.,
green: 60. / 255.,
blue: 60. / 255.,
alpha: 1.,
},
Color::Rgba {
red: 65. / 255.,
green: 65. / 255.,
blue: 65. / 255.,
alpha: 1.,
},
Color::Rgba {
red: 55. / 255.,
green: 55. / 255.,
blue: 55. / 255.,
alpha: 1.,
},
Color::srgba(60. / 255., 60. / 255., 60. / 255., 1.),
Color::srgba(65. / 255., 65. / 255., 65. / 255., 1.),
Color::srgba(55. / 255., 55. / 255., 55. / 255., 1.),
];

pub const HEX_LAYOUT: HexLayout = HexLayout {
Expand Down
22 changes: 16 additions & 6 deletions src/player_script/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use std::time::Duration;

use bevy::{
app::{App, Plugin, Update},
prelude::IntoSystemConfigs,
prelude::{on_event, IntoSystemConfigs},
time::common_conditions::on_timer,
};

use crate::constants;
use crate::{components::ProjectileMoveEndEvent, constants};

use super::{
assembler::{assembler_ai, assemblers_produce},
distributor::distributor_ai, unit::{units_move, units_attack},
distributor::distributor_ai,
unit::{units_attack, units_move, units_stop_move},
};

pub struct PlayerScriptPlugin;
Expand All @@ -19,9 +20,18 @@ impl Plugin for PlayerScriptPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(distributor_ai, (assemblers_produce, assembler_ai).chain(), (units_move, units_attack).chain()).run_if(on_timer(
Duration::from_secs_f32(constants::SECONDS_PER_TICK),
)),
(
distributor_ai,
(assemblers_produce, assembler_ai).chain(),
(units_move, units_attack).chain(),
)
.run_if(on_timer(Duration::from_secs_f32(
constants::SECONDS_PER_TICK,
))),
)
.add_systems(
Update,
units_stop_move.run_if(on_event::<ProjectileMoveEndEvent>()),
);
}
}
14 changes: 12 additions & 2 deletions src/player_script/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ use crate::{
utils::pick,
};

pub fn units_stop_move(mut units: Query<(&mut Unit, &mut Transform)>) {
for (mut unit, mut unit_transform) in units.iter_mut() {
if let Some(moving) = &unit.moving {
unit_transform.translation.x = moving.target_pos.x;
unit_transform.translation.y = moving.target_pos.y;
unit.moving = None;
};
}
}

pub fn units_move(
mut units: Query<(&mut Unit, &mut Transform)>,
occupiers: Query<&Transform, (With<OccupiesTile>, Without<Unit>)>,
Expand All @@ -34,11 +44,11 @@ pub fn units_move(
let t_offsets = [-1, 0, 1];

for (mut unit, mut unit_transform) in units.iter_mut() {
if let Some(moving) = &unit.moving {
/* if let Some(moving) = &unit.moving {
unit_transform.translation.x = moving.target_pos.x;
unit_transform.translation.y = moving.target_pos.y;
unit.moving = None;
};
}; */

if unit_move_cost(&unit) > unit.energy {
continue;
Expand Down
6 changes: 3 additions & 3 deletions src/projectile/laser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rand::{thread_rng, Rng};

use crate::{
components::{Laser, ResourceBlob},
constants::{self, coal_node, laser, z_order, Resource, SECONDS_PER_TICK},
constants::{self, coal_node, laser, z_order, Resource, PROJECTILE_MOVE_END_TICK_PORTION, SECONDS_PER_TICK},
utils::{find_angle, find_angle_coords, signed_distance},
};

Expand Down Expand Up @@ -68,8 +68,8 @@ pub fn update_lasers(

// use trig to apply evenly for diagonal vs straight movement

let x_delta = (laser.target_pos.x - laser.start_pos.x) / SECONDS_PER_TICK * time.delta_seconds() /* * angle.cos().abs() */;
let y_delta = (laser.target_pos.y - laser.start_pos.y) / SECONDS_PER_TICK * time.delta_seconds() /* * angle.sin().abs() */;
let x_delta = (laser.target_pos.x - laser.start_pos.x) / SECONDS_PER_TICK / PROJECTILE_MOVE_END_TICK_PORTION * time.delta_seconds() /* * angle.cos().abs() */;
let y_delta = (laser.target_pos.y - laser.start_pos.y) / SECONDS_PER_TICK / PROJECTILE_MOVE_END_TICK_PORTION * time.delta_seconds() /* * angle.sin().abs() */;

laser_transform.translation.x += x_delta;
laser_transform.translation.y += y_delta;
Expand Down
29 changes: 23 additions & 6 deletions src/projectile/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
use std::time::Duration;

use bevy::{app::{App, Plugin, Update}, prelude::*, time::common_conditions::on_timer};
use bevy::{
app::{App, Plugin, Update},
prelude::*,
time::common_conditions::on_timer,
};

use crate::{components::ProjectileMoveEndEvent, constants};

use super::{laser::{kill_lasers, update_lasers}, resource_blob::{kill_resource_blobs, update_resource_blobs}, unit::{update_units}};
use super::{
laser::{kill_lasers, update_lasers},
resource_blob::{kill_resource_blobs, update_resource_blobs},
unit::update_units,
};

pub struct ProjectilePlugin;

impl Plugin for ProjectilePlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, (update_lasers, update_units, (kill_lasers, kill_resource_blobs).run_if(on_timer(Duration::from_secs_f32(
constants::SECONDS_PER_TICK,
)))))/* .add_systems(Update, (update_resource_blobs).run_if(ProjectileMoveEndEvent)) */;
app.add_systems(
Update,
(
update_lasers,
update_units,
update_resource_blobs,
),
)
.add_systems(
Update,
(kill_lasers, kill_resource_blobs).run_if(on_event::<ProjectileMoveEndEvent>()),
);
}
}
}
Loading

0 comments on commit dec7b4c

Please sign in to comment.