Skip to content

Commit

Permalink
add npc goose, release 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeder committed Jun 14, 2023
1 parent ad7493e commit 2b711f1
Show file tree
Hide file tree
Showing 18 changed files with 435 additions and 106 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "turtle_time"
version = "0.7.3"
version = "0.8.0"
publish = false
authors = ["Mike Eder <[email protected]>"] # ToDo: you are the author
authors = ["Mike Eder <[email protected]>"]
edition = "2021"
exclude = ["dist", "build", "assets", "credits"]

Expand Down
Binary file added assets/textures/goose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/debug/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ pub struct ConsoleReady(pub bool);

pub struct PeerInfo(pub String);

#[derive(Resource)]

pub struct EdibleCount(pub usize);

#[derive(Resource)]
pub struct ConsoleUpdateTimer(pub Timer);
47 changes: 26 additions & 21 deletions src/debug/console.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::components::{ConsoleReady, ConsoleText, ConsoleUI, ConsoleUpdateTimer, PeerInfo};
use super::components::{
ConsoleReady, ConsoleText, ConsoleUI, ConsoleUpdateTimer, EdibleCount, PeerInfo,
};
use crate::loading::FontAssets;
use bevy::prelude::*;

Expand Down Expand Up @@ -58,7 +60,12 @@ pub fn setup_ui(mut commands: Commands, font_assets: Res<FontAssets>) {
..Default::default()
},
visibility: Visibility::Hidden,
background_color: BackgroundColor(Color::BLACK),
background_color: BackgroundColor(Color::Rgba {
red: 0.,
green: 0.,
blue: 0.,
alpha: 0.7,
}),
..Default::default()
})
.with_children(|parent| {
Expand All @@ -71,24 +78,14 @@ pub fn setup_ui(mut commands: Commands, font_assets: Res<FontAssets>) {
..Default::default()
},
text: Text {
sections: vec![
TextSection {
value: "Peer Info: ".to_owned(),
style: TextStyle {
font: font_assets.fira_sans.clone(),
font_size: 15.0,
color: Color::GREEN,
},
sections: vec![TextSection {
value: "".to_owned(),
style: TextStyle {
font: font_assets.fira_sans.clone(),
font_size: 15.0,
color: Color::GREEN,
},
TextSection {
value: "".to_owned(),
style: TextStyle {
font: font_assets.fira_sans.clone(),
font_size: 15.0,
color: Color::GREEN,
},
},
],
}],
..Default::default()
},
..Default::default()
Expand All @@ -100,14 +97,22 @@ pub fn setup_ui(mut commands: Commands, font_assets: Res<FontAssets>) {
.insert(ConsoleUI);

commands.insert_resource(PeerInfo("".to_string()));
commands.insert_resource(EdibleCount(0));
commands.insert_resource(ConsoleUpdateTimer(Timer::from_seconds(
1.0,
TimerMode::Repeating,
)))
}

pub fn set_peer_info(peer_info: ResMut<PeerInfo>, mut query: Query<&mut Text, With<ConsoleText>>) {
pub fn update_console_text(
edible_count: ResMut<EdibleCount>,
peer_info: ResMut<PeerInfo>,
mut query: Query<&mut Text, With<ConsoleText>>,
) {
for mut text in query.iter_mut() {
text.sections[1].value = peer_info.0.to_string();
text.sections[0].value = format!(
"Edible count: {}\nPeer Info: \n{}",
edible_count.0, peer_info.0
);
}
}
14 changes: 11 additions & 3 deletions src/debug/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use bevy_inspector_egui::quick::WorldInspectorPlugin;

use crate::{
menu::connect::LocalHandle,
npc::components::EdibleTarget,
player::input::GGRSConfig,
player::{
checksum::Checksum,
components::{EdibleSpawnTimer, Player, PlayerHealth},
components::{Edible, EdibleSpawnTimer, Player, PlayerHealth},
},
AppState, GameState,
};

use super::components::{ConsoleReady, ConsoleUpdateTimer, PeerInfo};
use super::components::{ConsoleReady, ConsoleUpdateTimer, EdibleCount, PeerInfo};
use super::console::*;

pub struct DebugPlugin;
Expand All @@ -25,6 +26,8 @@ impl Plugin for DebugPlugin {
.register_type::<Checksum>()
.register_type::<ConsoleReady>()
.register_type::<LocalHandle>()
.register_type::<EdibleTarget>()
.register_type::<Edible>()
.register_type::<EdibleSpawnTimer>()
.register_type::<Player>()
.register_type::<PlayerHealth>();
Expand All @@ -39,12 +42,17 @@ impl Plugin for ConsolePlugin {
app.add_system(setup_ui.in_schedule(OnExit(AppState::Loading)))
.add_system(log_ggrs_events.in_set(OnUpdate(GameState::Playing)))
.add_system(open_console)
.add_system(set_peer_info.run_if(resource_exists::<PeerInfo>()))
.add_system(count_edibles.run_if(resource_exists::<EdibleCount>()))
.add_system(update_console_text.run_if(resource_exists::<PeerInfo>()))
.add_system(reset_console_ready.run_if(resource_exists::<PeerInfo>()))
.add_system(update_peer_info.run_if(resource_exists::<Session<GGRSConfig>>()));
}
}

pub fn count_edibles(mut edible_count: ResMut<EdibleCount>, edible_query: Query<&Edible>) {
edible_count.0 = edible_query.iter().collect::<Vec<_>>().len();
}

pub fn update_peer_info(
session: Res<Session<GGRSConfig>>,
time: Res<Time>,
Expand Down
21 changes: 18 additions & 3 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ pub struct GraphicsPlugin;

#[derive(Resource)]
pub struct CharacterSheet {
pub handle: Handle<TextureAtlas>,
pub turtle_handle: Handle<TextureAtlas>,
pub goose_handle: Handle<TextureAtlas>,
pub turtle_frames: [usize; 4],
pub goose_frames: [usize; 4],
}

#[derive(Component)]
Expand All @@ -32,6 +34,7 @@ impl GraphicsPlugin {
mut commands: Commands,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {
// load turtle atlas sheet
let turtle_atlas = TextureAtlas::from_grid(
assets.texture_turtle_cheeks_frame_party_hat.clone(),
Vec2::splat(TILE_SIZE),
Expand All @@ -40,11 +43,23 @@ impl GraphicsPlugin {
Some(Vec2 { x: 2.0, y: 0. }),
Some(Vec2 { x: 0.0, y: 0. }),
);
let atlas_handle = texture_atlases.add(turtle_atlas);

// load goose atlas sheet
let goose_atlas = TextureAtlas::from_grid(
assets.texture_goose.clone(),
Vec2::splat(TILE_SIZE),
4,
1,
Some(Vec2 { x: 1.0, y: 0. }),
Some(Vec2 { x: 0.0, y: 0. }),
);

// add character sheet with atlas and frame instructions
commands.insert_resource(CharacterSheet {
handle: atlas_handle,
turtle_handle: texture_atlases.add(turtle_atlas),
turtle_frames: [0, 1, 2, 3],
goose_handle: texture_atlases.add(goose_atlas),
goose_frames: [0, 1, 2, 3],
});
}

Expand Down
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ mod graphics;
mod loading;
mod map;
mod menu;
pub mod npc;
pub mod player;

use crate::actions::ActionsPlugin;
use crate::audio::InternalAudioPlugin;
use crate::loading::LoadingPlugin;
use ascii::AsciiPlugin;
use bevy::app::App;
use bevy::prelude::*;
use bevy::{app::App, diagnostic::FrameTimeDiagnosticsPlugin};
use debug::plugin::{ConsolePlugin, DebugPlugin};
use graphics::GraphicsPlugin;
use map::tilemap::TileMapPlugin;
use menu::plugin::MenuPlugin;
use npc::plugin::GoosePlugin;
use player::plugin::PlayerPlugin;

#[cfg(debug_assertions)]
Expand Down Expand Up @@ -85,18 +87,19 @@ impl Plugin for GamePlugin {
.add_plugin(ActionsPlugin)
.add_plugin(InternalAudioPlugin)
.add_plugin(PlayerPlugin)
.add_plugin(GoosePlugin)
.add_plugin(ConsolePlugin);

#[cfg(debug_assertions)]
{
// With FPS
// app.add_plugin(FrameTimeDiagnosticsPlugin::default())
// .add_plugin(DebugPlugin)
// .add_plugin(LogDiagnosticsPlugin::default());
app.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(DebugPlugin)
.add_plugin(LogDiagnosticsPlugin::default());

// Without FPS
app.add_plugin(DebugPlugin)
.add_plugin(LogDiagnosticsPlugin::default());
// app.add_plugin(DebugPlugin)
// .add_plugin(LogDiagnosticsPlugin::default());
}
}
}
2 changes: 2 additions & 0 deletions src/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub struct TextureAssets {
pub texture_fireball: Handle<Image>,
#[asset(path = "textures/lettuce.png")]
pub texture_lettuce: Handle<Image>,
#[asset(path = "textures/goose.png")]
pub texture_goose: Handle<Image>,
// map textures
#[asset(path = "textures/dirt.png")]
pub texture_dirt: Handle<Image>,
Expand Down
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use bevy::winit::WinitWindows;
use bevy::DefaultPlugins;
use bevy_ggrs::GGRSPlugin;
use std::io::Cursor;
use turtle_time::npc::components::{EdibleTarget, Goose, HasTarget};
use turtle_time::player::checksum::Checksum;
use turtle_time::player::components::{
ChiliPepper, EdibleSpawnTimer, Fireball, FireballAmmo, FireballMovement, FireballReady,
Lettuce, Player, PlayerHealth, PlayerPoop, PlayerSpeed, PlayerSpeedBoost, Strawberry,
Edible, EdibleSpawnTimer, Expired, Fireball, FireballAmmo, FireballMovement, FireballReady,
FireballTimer, Player, PlayerHealth, PlayerPoop, PlayerPoopTimer, PlayerSpeed,
PlayerSpeedBoost, RoundComponent,
};
use turtle_time::player::input::{input, GGRSConfig, PlayerControls};
use turtle_time::{GamePlugin, ASPECT_RATIO, FPS, MAP_HEIGHT};
Expand All @@ -23,19 +25,24 @@ fn main() {
.with_update_frequency(FPS)
.with_input_system(input)
.register_rollback_component::<Checksum>()
.register_rollback_component::<ChiliPepper>()
.register_rollback_component::<Edible>()
.register_rollback_component::<EdibleTarget>()
.register_rollback_component::<Expired>()
.register_rollback_component::<Fireball>()
.register_rollback_component::<FireballAmmo>()
.register_rollback_component::<FireballReady>()
.register_rollback_component::<FireballMovement>()
.register_rollback_component::<Lettuce>()
.register_rollback_component::<FireballTimer>()
.register_rollback_component::<Goose>()
.register_rollback_component::<HasTarget>()
.register_rollback_component::<Player>()
.register_rollback_component::<PlayerHealth>()
.register_rollback_component::<PlayerSpeed>()
.register_rollback_component::<PlayerSpeedBoost>()
.register_rollback_component::<PlayerControls>()
.register_rollback_component::<PlayerPoop>()
.register_rollback_component::<Strawberry>()
.register_rollback_component::<PlayerPoopTimer>()
.register_rollback_component::<RoundComponent>()
.register_rollback_component::<Transform>()
.register_rollback_resource::<EdibleSpawnTimer>()
.build(&mut app);
Expand Down
15 changes: 15 additions & 0 deletions src/npc/components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use bevy::prelude::*;

pub const GOOSE_SPEED: i32 = 105;

#[derive(Component, Default, Hash, Reflect)]
#[reflect(Component, Hash)]
pub struct Goose;

#[derive(Component, Default, Hash, Reflect)]
#[reflect(Component, Hash)]
pub struct HasTarget;

#[derive(Component, Default, Hash, Reflect)]
#[reflect(Component, Hash)]
pub struct EdibleTarget;
3 changes: 3 additions & 0 deletions src/npc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod components;
pub mod plugin;
pub mod systems;
38 changes: 38 additions & 0 deletions src/npc/plugin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use bevy::prelude::*;
use bevy_ggrs::GGRSSchedule;

use crate::{
player::plugin::{EdibleSystemSet, PlayerSystemSet, SpawnSystemSet},
GameState,
};

use super::systems::{
geese_target_closest_edible, goose_ate_edible, move_geese_toward_target, spawn_geese,
};

pub struct GoosePlugin;

#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub struct NpcSystemSet;

/// This plugin handles player related stuff like movement
/// Player logic is only active during the State `GameState::Playing`
impl Plugin for GoosePlugin {
fn build(&self, app: &mut App) {
app.add_system(spawn_geese.in_schedule(OnEnter(GameState::Playing)))
.add_systems(
(
geese_target_closest_edible,
move_geese_toward_target,
goose_ate_edible,
)
.chain()
.in_set(NpcSystemSet)
.after(EdibleSystemSet)
.after(SpawnSystemSet)
.after(PlayerSystemSet)
.distributive_run_if(in_state(GameState::Playing))
.in_schedule(GGRSSchedule),
);
}
}
Loading

0 comments on commit 2b711f1

Please sign in to comment.