Skip to content

Commit

Permalink
Add basic argument processing
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-thompson committed Jan 13, 2024
1 parent a812639 commit 1f194a9
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 5 deletions.
107 changes: 107 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tiled = "0.11.2"
thiserror = "1.0.52"
itertools = "0.12.0"
slicetools = "0.3.0"
clap = { version = "4.4.16", features = ["derive"] }

[features]
editor = ["dep:bevy_editor_pls"]
Expand Down
45 changes: 40 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bevy::{
window,
};
use bevy_ecs_tilemap::prelude::*;
use clap::Parser;
use itertools::Itertools;
use slicetools::*;
use std::f32::consts::PI;
Expand All @@ -17,15 +18,33 @@ mod helpers;
mod util;
use util::IteratorToArrayExt;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Enable windowed mode (for debugging try: -wdd)
#[arg(short, long)]
window: bool,

/// Turn debugging visualizations on
#[arg(short, long, action = clap::ArgAction::Count)]
debug: u8,
}

fn main() {
let args = Args::parse();

App::new()
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "TRD2024 - Orcombe Point edition".to_string(),
resolution: (1920.0, 1080.0).into(),
title: "TDR2024 - Orcombe Point edition".to_string(),
resolution: (1280.0, 720.0).into(),
present_mode: window::PresentMode::AutoVsync,
mode: window::WindowMode::BorderlessFullscreen,
mode: if args.window {
window::WindowMode::default()
} else {
window::WindowMode::BorderlessFullscreen
},
cursor: window::Cursor {
visible: false,
..default()
Expand All @@ -42,6 +61,7 @@ fn main() {
.register_type::<Angle>()
.register_type::<Velocity>()
.insert_resource(ClearColor(Color::rgb(0.053, 0.782, 0.276)))
.insert_resource(DebugLevel(args.debug))
.add_systems(
Startup,
(load_maps, spawn_camera, spawn_player, spawn_ai_players),
Expand All @@ -64,6 +84,19 @@ fn main() {
.run();
}

#[derive(Resource)]
struct DebugLevel(u8);

impl DebugLevel {
fn low(&self) -> bool {
self.0 >= 1
}

fn high(&self) -> bool {
self.0 >= 2
}
}

#[derive(Component, Debug)]
struct Player;

Expand Down Expand Up @@ -386,6 +419,7 @@ impl CollisionBox {
fn collision_detection(
mut query: Query<(&mut Transform, &Handle<TextureAtlas>, &mut Velocity)>,
texture_atlases: Res<Assets<TextureAtlas>>,
debug: Res<DebugLevel>,
mut gizmos: Gizmos,
) {
let mut colliders = query.iter_mut().collect::<Vec<_>>();
Expand All @@ -402,7 +436,7 @@ fn collision_detection(

let mut abox = CollisionBox::from_transform(&a.0, &atx.size);
let mut bbox = CollisionBox::from_transform(&b.0, &btx.size);
if false {
if debug.low() {
abox.draw(&mut gizmos);
bbox.draw(&mut gizmos);
}
Expand Down Expand Up @@ -456,6 +490,7 @@ fn handle_ai_players(
)>,
time: Res<Time>,
guide: Option<Res<GuidanceField>>,
debug: Res<DebugLevel>,
mut gizmos: Gizmos,
) {
if guide.is_none() {
Expand All @@ -481,7 +516,7 @@ fn handle_ai_players(
let front_whisker = pos + (425.0 * Vec2::from_angle(a.0));
let front_pixel = guide.get(&front_whisker);

if false {
if debug.high() {
for v in [
left_whisker,
right_whisker,
Expand Down

0 comments on commit 1f194a9

Please sign in to comment.