2023-12-05 13:51:40 +00:00
|
|
|
use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*, window::*};
|
2023-12-02 14:22:05 +00:00
|
|
|
|
2023-12-04 21:23:27 +00:00
|
|
|
use bevy_egui::EguiPlugin;
|
2023-12-02 14:22:05 +00:00
|
|
|
|
2023-11-27 10:45:07 +00:00
|
|
|
use lazy_static::lazy_static;
|
2023-12-02 14:22:05 +00:00
|
|
|
use std::collections::HashMap;
|
2023-11-27 10:45:07 +00:00
|
|
|
|
2023-12-04 21:23:27 +00:00
|
|
|
// Load modules from other files
|
2023-11-29 22:40:30 +00:00
|
|
|
mod helpers;
|
|
|
|
use crate::helpers::*;
|
2023-12-04 21:17:34 +00:00
|
|
|
mod player;
|
|
|
|
use crate::player::*;
|
2023-12-04 21:23:27 +00:00
|
|
|
mod ui;
|
|
|
|
use crate::ui::*;
|
2023-12-04 21:17:34 +00:00
|
|
|
|
2023-12-04 21:23:27 +00:00
|
|
|
// Version information
|
2023-11-28 14:18:26 +00:00
|
|
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
|
|
const PKGNAME: &str = env!("CARGO_PKG_NAME");
|
|
|
|
|
2023-11-27 10:45:07 +00:00
|
|
|
// Create a map of the Hypernova colorscheme
|
2023-12-02 14:22:05 +00:00
|
|
|
lazy_static! {
|
|
|
|
static ref HYPERNOVA: HashMap<&'static str, (u8, u8, u8)> = vec![
|
|
|
|
("BLACK", (13, 13, 15)),
|
|
|
|
("DARK_GRAY", (21, 21, 23)),
|
|
|
|
("GRAY", (39, 39, 43)),
|
|
|
|
("LIGHT_GRAY", (69, 68, 73)),
|
|
|
|
("SUBTEXT", (217, 208, 215)),
|
|
|
|
("WHITE", (236, 229, 234)),
|
|
|
|
("RED", (240, 105, 105)),
|
|
|
|
("MAGENTA", (232, 135, 187)),
|
|
|
|
("PURPLE", (162, 146, 232)),
|
|
|
|
("BLUE", (120, 175, 196)),
|
2023-12-04 13:44:28 +00:00
|
|
|
("CYAN", (127, 230, 174)),
|
2023-12-02 14:22:05 +00:00
|
|
|
("GREEN", (145, 214, 92)),
|
|
|
|
("YELLOW", (217, 213, 100)),
|
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.copied()
|
|
|
|
.collect();
|
2023-11-27 10:45:07 +00:00
|
|
|
}
|
2023-11-26 23:03:29 +00:00
|
|
|
|
2023-11-26 21:32:11 +00:00
|
|
|
fn main() {
|
2023-11-26 23:03:29 +00:00
|
|
|
App::new()
|
2023-12-02 14:22:05 +00:00
|
|
|
.add_plugins((
|
2023-11-28 14:18:26 +00:00
|
|
|
DefaultPlugins.set(WindowPlugin {
|
|
|
|
primary_window: Some(Window {
|
2023-12-02 14:42:30 +00:00
|
|
|
title: format!("{} {}", titlecase(PKGNAME), VERSION),
|
2023-11-28 14:18:26 +00:00
|
|
|
mode: WindowMode::Fullscreen,
|
|
|
|
..default()
|
|
|
|
}),
|
|
|
|
..default()
|
2023-12-02 14:22:05 +00:00
|
|
|
}),
|
|
|
|
EguiPlugin,
|
|
|
|
))
|
2023-12-03 12:37:07 +00:00
|
|
|
.init_resource::<UiState>()
|
2023-12-04 13:44:28 +00:00
|
|
|
.init_resource::<OpenWindows>()
|
2023-12-02 14:22:05 +00:00
|
|
|
.add_systems(Startup, (setup, setup_ui))
|
2023-12-04 21:02:59 +00:00
|
|
|
.add_systems(Update, (render_ui, movement))
|
2023-11-26 23:03:29 +00:00
|
|
|
.run();
|
2023-11-26 21:32:11 +00:00
|
|
|
}
|
2023-11-26 23:03:29 +00:00
|
|
|
|
2023-12-02 14:22:05 +00:00
|
|
|
// Bevy engine setup
|
2023-12-04 13:44:28 +00:00
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
2023-12-02 14:22:05 +00:00
|
|
|
commands.spawn(Camera2dBundle {
|
|
|
|
camera: Camera {
|
|
|
|
hdr: true,
|
2023-11-26 23:03:29 +00:00
|
|
|
..default()
|
2023-12-02 14:22:05 +00:00
|
|
|
},
|
|
|
|
tonemapping: Tonemapping::TonyMcMapface,
|
|
|
|
..default()
|
|
|
|
});
|
2023-12-04 13:44:28 +00:00
|
|
|
commands.spawn((
|
|
|
|
SpriteBundle {
|
2023-12-05 13:51:40 +00:00
|
|
|
texture: asset_server.load("player/player-4x.png"),
|
|
|
|
transform: Transform {
|
|
|
|
scale: Vec3::splat(0.2),
|
|
|
|
..default()
|
|
|
|
},
|
2023-12-04 13:44:28 +00:00
|
|
|
..default()
|
2023-12-04 21:02:59 +00:00
|
|
|
},
|
|
|
|
Player {
|
2023-12-05 13:51:40 +00:00
|
|
|
movement_speed: 512.,
|
2023-12-04 21:02:59 +00:00
|
|
|
rotation_speed: f32::to_radians(360.),
|
2023-12-05 13:51:40 +00:00
|
|
|
|
2023-12-05 18:49:03 +00:00
|
|
|
health: 10.,
|
2023-12-05 13:51:40 +00:00
|
|
|
health_max: 10.,
|
2023-12-05 18:49:03 +00:00
|
|
|
stamina: 10.,
|
2023-12-05 13:51:40 +00:00
|
|
|
stamina_max: 10.,
|
|
|
|
|
|
|
|
defence: 40.,
|
2023-12-04 21:02:59 +00:00
|
|
|
},
|
2023-12-04 13:44:28 +00:00
|
|
|
));
|
2023-12-02 14:22:05 +00:00
|
|
|
}
|