Skip to content

Commit

Permalink
It be what it be
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonWebster committed Dec 11, 2023
1 parent 6f95a8f commit 393291c
Show file tree
Hide file tree
Showing 14 changed files with 455 additions and 199 deletions.
Binary file removed assets/textures/ground/flowers1.png
Binary file not shown.
Binary file removed assets/textures/ground/flowers2.png
Binary file not shown.
Binary file modified assets/textures/ground/grass1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/textures/ground/grass2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/textures/ground/ground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 52 additions & 19 deletions src/bees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{

use crate::interactions::{MousePosition, Highlightable};
use bevy::prelude::*;
use crate::tilemap::FogTile;
// use bevy::window::PrimaryWindow;

pub struct BeesPlugin;
Expand All @@ -27,6 +28,7 @@ impl Plugin for BeesPlugin {
.add_systems(Update, create_boid_group.run_if(in_state(GameState::Playing)))
.add_systems(Update, place_bee.run_if(in_state(GameState::Playing)))
.add_systems(Update, animate_wings.run_if(in_state(GameState::Playing)))
// .add_systems(Update, clear_fog.run_if(in_state(GameState::Playing)))
.add_systems(
Update,
(build_or_update_quadtree, update_boids, move_system).run_if(
Expand Down Expand Up @@ -78,10 +80,10 @@ pub struct Bee;

#[derive(Component)]
pub enum BeeBehavior {
Traveling(Vec2), // Destination coordinates
Wondering(Vec2), // Point of origin coordinates
Exploring(Vec2), // Point of origin coordinates
Interacting(Vec2), // Coordinates of interactable object
// Traveling(Vec2), // Destination coordinates
Destination(Vec2), // Point of origin coordinates
// Exploring(Vec2), // Point of origin coordinates
// Interacting(Vec2), // Coordinates of interactable object
}

// Separate out these types of data???
Expand Down Expand Up @@ -125,11 +127,11 @@ impl BoidGroup {
graph: QuadTree::new(region::Region::new(min, max)),
id: team.0,
count: 0,
separation: 0.3,
alignment: 0.4,
cohesion: 0.8,
speed: 40.0,
vision: 50.0,
separation: 0.5,
alignment: 0.3,
cohesion: 0.3,
speed: 240.0,
vision: 600.0,
}
}
}
Expand All @@ -156,12 +158,12 @@ fn setup(mut _commands: Commands) {
}

#[derive(Component)]
struct AnimationIndices {
first: usize,
last: usize,
pub struct AnimationIndices {
pub first: usize,
pub last: usize,
}
#[derive(Component, Deref, DerefMut)]
struct AnimationTimer(Timer);
pub struct AnimationTimer(pub Timer);

fn animate_wings(
time: Res<Time>,
Expand Down Expand Up @@ -189,10 +191,16 @@ fn place_bee(
textures: Res<TextureAssets>,
mouse_input: Res<Input<MouseButton>>,
) {
let mut rng = rand::thread_rng();
let bee_body= if rng.gen::<bool>() {
textures.beebody1.clone()
} else {
textures.beebody2.clone()
};
if mouse_input.just_pressed(MouseButton::Right) {
let bee_entity = commands.spawn((
SpriteBundle {
texture: textures.beebody1.clone(),
texture: bee_body,
transform: Transform::from_xyz(
mouse_position.0.x,
mouse_position.0.y,
Expand All @@ -201,20 +209,22 @@ fn place_bee(
..default()
},
Bee,
BeeBehavior::Wondering(Vec2::new(mouse_position.0.x, mouse_position.0.y)),
BeeBehavior::Destination(Vec2::new(mouse_position.0.x, mouse_position.0.y)),
Boid,
Highlightable,
Collider::new(5.0),
Velocity::default(),
)).id();

// Create the wings
let texture_atlas_handle = textures.bee1wingmap.clone();

// Spawn the wings as a child of the bee body
let bee_wings= if rng.gen::<bool>() {
textures.bee1wingmap.clone()
} else {
textures.bee2wingmap.clone()
};
commands.entity(bee_entity).with_children(|parent| {
parent.spawn(SpriteSheetBundle {
texture_atlas: textures.bee1wingmap.clone(),
texture_atlas: bee_wings,
sprite: TextureAtlasSprite::new(0), // Set the initial sprite index
transform: Transform::from_xyz(0.0, 0.0, 1.0), // Adjust the position of the wings relative to the bee body
..Default::default()
Expand All @@ -226,3 +236,26 @@ fn place_bee(
info!("Bee spawned");
}
}

fn _clear_fog(
mut commands: Commands,
bee_query: Query<&Transform, With<Bee>>,
mut fog_tile_query: Query<(Entity, &Transform), With<FogTile>>,
) {
for bee_transform in bee_query.iter() {
// info!("Bee transform {:?}", bee_transform);
for (fog_tile_entity, fog_transform) in fog_tile_query.iter_mut() {
// info!("Fogtile transform {:?}", fog_transform);
let distance = bee_transform.translation.distance(fog_transform.translation);
info!("Distance {:?}", distance);
// Define a range where the fog tile should despawn (adjust this range as needed)
let despawn_range = 30000.0; // Modify this value to suit your needs

if distance < despawn_range {
// Despawn fog tile if it's within the despawn range of the bee
info!("Collision detected: Distance between bee and fog tile: {}", distance);
commands.entity(fog_tile_entity).despawn_recursive();
}
}
}
}
1 change: 1 addition & 0 deletions src/boids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn create_boid_group(
}
let height = level_data.level_height;
let width = level_data.level_width;
info!("Maximum width {}, height {}", width, height);
comms.spawn(BoidGroup::new(
Vec2::new(0., 0.),
Vec2::new(width, height),
Expand Down
16 changes: 8 additions & 8 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn setup_camera_controls(
mut q_camera: Query<&mut OrthographicProjection, With<Camera2d>>,
) {
let mut projection = q_camera.single_mut();
projection.scale = 0.6;
projection.scale = 4.0;
}

fn panning_controls
Expand All @@ -30,13 +30,13 @@ fn panning_controls
level_data: Res<LevelData>
)
{
let pan_speed = 2.0;
let pan_speed = 10.0;
let mut cam_transform = q_cam.single_mut();
// info!("Cam Translation {:?}", cam_transform.translation);
if keys.pressed(KeyCode::W) || keys.pressed(KeyCode::Up) {
cam_transform.translation.y += pan_speed;
if cam_transform.translation.y > level_data.level_height as f32 {
cam_transform.translation.y = level_data.level_height as f32;
if cam_transform.translation.y > level_data.level_height {
cam_transform.translation.y = level_data.level_height;
}
}
if keys.pressed(KeyCode::A) || keys.pressed(KeyCode::Left) {
Expand All @@ -53,8 +53,8 @@ fn panning_controls
}
if keys.pressed(KeyCode::D) || keys.pressed(KeyCode::Right) {
cam_transform.translation.x += pan_speed;
if cam_transform.translation.x > level_data.level_width as f32 {
cam_transform.translation.x = level_data.level_width as f32;
if cam_transform.translation.x > level_data.level_width {
cam_transform.translation.x = level_data.level_width;
}
}
}
Expand All @@ -67,8 +67,8 @@ fn zooming_controls

) {
let zoom_speed = 0.2;
let max_scale = 5.0;
let min_scale = 0.2;
let max_scale = 10.0;
let min_scale = 1.0;
for ev in scroll_evr.read() {
use bevy::input::mouse::MouseScrollUnit;
let mut projection = q_camera.single_mut();
Expand Down
81 changes: 43 additions & 38 deletions src/debug/debug.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use bevy::prelude::*;
use rand::Rng;
// use rand::Rng;

use crate::{
bees::{Bee, BoidGroup, Collider, Velocity, BeeBehavior},
// bees::{Bee, BoidGroup, Collider, Velocity, BeeBehavior},
bees::BoidGroup,
boids::Boid,
loading::TextureAssets,
// loading::TextureAssets,
GameState,
};
use crate::interactions::Highlightable;
// use crate::interactions::Highlightable;

pub struct DebugPlugin;

Expand All @@ -22,7 +23,7 @@ impl Plugin for DebugPlugin {
(
visualize_quadtree,
visualize_boid_radius,
spawn_random_boids,
// spawn_random_boids,
)
.run_if(in_state(GameState::Playing)),
);
Expand All @@ -37,7 +38,11 @@ pub struct Visualizer {
pub boid_cone: bool,
}

pub fn visualize_quadtree(mut gizmos: Gizmos, vis: Res<Visualizer>, groups: Query<&BoidGroup>) {
pub fn visualize_quadtree(mut gizmos: Gizmos, mut vis: ResMut<Visualizer>, groups: Query<&BoidGroup>, input: Res<Input<KeyCode>>) {
if input.just_pressed(KeyCode::Space) {
vis.quadtree = !vis.quadtree;
info!("Toggling quadtree to {:?}", vis.quadtree);
}
if !vis.quadtree {
return;
}
Expand Down Expand Up @@ -80,38 +85,38 @@ pub fn visualize_boid_radius(
}
}

fn spawn_random_boids(
mut commands: Commands,
input: Res<Input<KeyCode>>,
textures: Res<TextureAssets>,
) {
// spawn in 1000 boids randomly in the field on press of some key
if input.just_pressed(KeyCode::Space) {
(0..1000).for_each(|_| {
let mut rng = rand::thread_rng();
let spawn_x = rng.gen_range(20.0..3820.0);
let spawn_y = rng.gen_range(20.0..2140.0);
commands.spawn((
SpriteSheetBundle {
texture_atlas: textures.planes.clone(),
sprite: TextureAtlasSprite::new(11),
transform: Transform::from_xyz(
spawn_x,
spawn_y,
5.0,
),
..default()
},
Bee,
Boid,
BeeBehavior::Wondering(Vec2::new(spawn_x, spawn_y)),
Highlightable,
Collider::new(5.0),
Velocity::default(),
));
});
}
}
// fn spawn_random_boids(
// mut commands: Commands,
// input: Res<Input<KeyCode>>,
// textures: Res<TextureAssets>,
// ) {
// // spawn in 1000 boids randomly in the field on press of some key
// if input.just_pressed(KeyCode::Space) {
// (0..1000).for_each(|_| {
// let mut rng = rand::thread_rng();
// let spawn_x = rng.gen_range(20.0..3820.0);
// let spawn_y = rng.gen_range(20.0..2140.0);
// commands.spawn((
// SpriteSheetBundle {
// texture_atlas: textures.planes.clone(),
// sprite: TextureAtlasSprite::new(11),
// transform: Transform::from_xyz(
// spawn_x,
// spawn_y,
// 5.0,
// ),
// ..default()
// },
// Bee,
// Boid,
// BeeBehavior::Wondering(Vec2::new(spawn_x, spawn_y)),
// Highlightable,
// Collider::new(5.0),
// Velocity::default(),
// ));
// });
// }
// }

// this should create a window with a dropdown of all boidgroups and allow editing of all the values within
// fn edit_boid_groups(groups: Query<&BoidGroup>) {
Expand Down
Loading

0 comments on commit 393291c

Please sign in to comment.