Compare commits
14 Commits
main
...
Developmen
Author | SHA1 | Date |
---|---|---|
Johannes Hendrik Gerard van der Weide | 0505eaea8b | |
Johannes Hendrik Gerard van der Weide | 9f49fb4acc | |
Johannes Hendrik Gerard van der Weide | 3eae9f5896 | |
Johannes Hendrik Gerard van der Weide | 4ea9cdf612 | |
Johannes Hendrik Gerard van der Weide | d1d0eac44d | |
Johannes Hendrik Gerard van der Weide | 16ac1444ce | |
Johannes Hendrik Gerard van der Weide | 07e05ab805 | |
Johannes Hendrik Gerard van der Weide | a415a32012 | |
Johannes Hendrik Gerard van der Weide | 92d37cbfcf | |
Johannes Hendrik Gerard van der Weide | 5f72edba96 | |
Johannes Hendrik Gerard van der Weide | af00347fa5 | |
Johannes Hendrik Gerard van der Weide | adc11ec654 | |
Johannes Hendrik Gerard van der Weide | 2720215da7 | |
Johannes Hendrik Gerard van der Weide | b8e067f4e4 |
|
@ -6,6 +6,7 @@ description = "A W.I.P. bevy-engine game "
|
||||||
authors = ["Johannes Hendrik Gerard van der Weide"]
|
authors = ["Johannes Hendrik Gerard van der Weide"]
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
rust-version = "1.70"
|
||||||
license-file = "LICENSE"
|
license-file = "LICENSE"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
|
|
20
README.md
20
README.md
|
@ -1,19 +1,5 @@
|
||||||
# RustThingy
|
# RustThingy
|
||||||
|
|
||||||
This place is a message... and part of a system of messages... pay attention to it!
|
Welcome to the development branch!
|
||||||
|
Expect it to be broken as any progress will be pushed.
|
||||||
Sending this message was important to us. We considered ourselves to be a powerful culture.
|
If you need a gauranty of it compiling propperly use main.
|
||||||
|
|
||||||
This place is not a place of honor... no highly esteemed deed is commemorated here... nothing valued is here.
|
|
||||||
|
|
||||||
What is here was dangerous and repulsive to us. This message is a warning about danger.
|
|
||||||
|
|
||||||
The danger is in a particular location... it increases towards a center... the center of danger is here... of a particular size and shape, and below us.
|
|
||||||
|
|
||||||
The danger is still present, in your time, as it was in ours.
|
|
||||||
|
|
||||||
The danger is to the body, and it can kill.
|
|
||||||
|
|
||||||
The form of the danger is an emanation of energy.
|
|
||||||
|
|
||||||
The danger is unleashed only if you substantially disturb this place physically. This place is best shunned and left uninhabited.
|
|
Binary file not shown.
After Width: | Height: | Size: 146 B |
Binary file not shown.
After Width: | Height: | Size: 136 B |
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
# Enemies can only be set if they exist in data/enemies/
|
||||||
|
# for example data/enemies/grunt.yml
|
||||||
|
enemies: [
|
||||||
|
grunt
|
||||||
|
]
|
||||||
|
# 0 means no enemies
|
||||||
|
waves: 0
|
||||||
|
# 0 is no treasure
|
||||||
|
treasure: 0
|
||||||
|
doors: [
|
||||||
|
true, # North
|
||||||
|
true, # East
|
||||||
|
true, # South
|
||||||
|
true, # West
|
||||||
|
]
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
down: S
|
down: S
|
||||||
left: A
|
left: A
|
||||||
right: D
|
right: D
|
||||||
input_sprite_path: neocat.png
|
input_lower_sprite_path: circle_empty.png
|
||||||
|
input_upper_sprite_path: circle_full.png
|
||||||
input_sprite_size: [
|
input_sprite_size: [
|
||||||
30.0,
|
30.0,
|
||||||
30.0
|
30.0
|
50
flake.nix
50
flake.nix
|
@ -39,51 +39,11 @@
|
||||||
{
|
{
|
||||||
# Development environment output
|
# Development environment output
|
||||||
devShells = forAllSystems ({ pkgs }: {
|
devShells = forAllSystems ({ pkgs }: {
|
||||||
default = pkgs.mkShell {
|
default = import ./nix/shell.nix { inherit pkgs; };
|
||||||
# The Nix packages provided in the environment
|
});
|
||||||
packages = (with pkgs; [
|
# Builder
|
||||||
# Fluff
|
packages = forAllSystems ({ pkgs }: {
|
||||||
cargo-mommy
|
default = import ./nix/default.nix { inherit pkgs; };
|
||||||
onefetch
|
|
||||||
# Bevy
|
|
||||||
pkg-config
|
|
||||||
alsa-lib
|
|
||||||
vulkan-tools
|
|
||||||
vulkan-headers
|
|
||||||
vulkan-loader
|
|
||||||
vulkan-validation-layers
|
|
||||||
udev
|
|
||||||
clang
|
|
||||||
lld
|
|
||||||
# If using an intel GPU
|
|
||||||
pkgs.nixgl.nixVulkanIntel
|
|
||||||
# If on x11
|
|
||||||
xorg.libX11
|
|
||||||
xorg.libX11
|
|
||||||
xorg.libXcursor
|
|
||||||
xorg.libXi
|
|
||||||
xorg.libXrandr
|
|
||||||
# If on wayland
|
|
||||||
libxkbcommon
|
|
||||||
wayland
|
|
||||||
# Rust
|
|
||||||
rustup
|
|
||||||
rustToolchain
|
|
||||||
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
|
|
||||||
shellHook = ''
|
|
||||||
# Required
|
|
||||||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [
|
|
||||||
pkgs.alsaLib
|
|
||||||
pkgs.udev
|
|
||||||
pkgs.vulkan-loader
|
|
||||||
]}"
|
|
||||||
# Aliases and other fluff/ease of use
|
|
||||||
alias runIntel="nixVulkanIntel cargo run"
|
|
||||||
alias runMommyIntel="nixVulkanIntel cargo mommy run"
|
|
||||||
onefetch
|
|
||||||
echo "Welcome to nix-hell uh nix-shell!"
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
|
||||||
|
pkgs.rustPlatform.buildRustPackage {
|
||||||
|
pname = "hertog-game";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
|
src = ../.;
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = ../Cargo.lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
rust-bin.stable."1.70.0".default
|
||||||
|
makeWrapper
|
||||||
|
pkg-config
|
||||||
|
] ++ lib.optionals stdenv.isLinux [
|
||||||
|
vulkan-loader
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
] ++ lib.optionals stdenv.isLinux [
|
||||||
|
alsa-lib
|
||||||
|
libxkbcommon
|
||||||
|
udev
|
||||||
|
vulkan-loader
|
||||||
|
wayland
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libXcursor
|
||||||
|
xorg.libXi
|
||||||
|
xorg.libXrandr
|
||||||
|
] ++ lib.optionals stdenv.isDarwin [
|
||||||
|
darwin.apple_sdk_11_0.frameworks.Cocoa
|
||||||
|
rustPlatform.bindgenHook
|
||||||
|
];
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
mkdir $out/bin/assets
|
||||||
|
mkdir $out/bin/data
|
||||||
|
cp -r assets $out/bin/
|
||||||
|
cp -r data $out/bin/
|
||||||
|
'';
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
pkgs.mkShell {
|
||||||
|
# The Nix packages provided in the environment
|
||||||
|
packages = (with pkgs; [
|
||||||
|
rust-bin.stable."1.70.0".default
|
||||||
|
# Fluff
|
||||||
|
cargo-mommy
|
||||||
|
onefetch
|
||||||
|
# Bevy
|
||||||
|
pkg-config
|
||||||
|
alsa-lib
|
||||||
|
vulkan-tools
|
||||||
|
vulkan-headers
|
||||||
|
vulkan-loader
|
||||||
|
vulkan-validation-layers
|
||||||
|
udev
|
||||||
|
clang
|
||||||
|
lld
|
||||||
|
# If using an intel GPU
|
||||||
|
pkgs.nixgl.nixVulkanIntel
|
||||||
|
# If on x11
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libXcursor
|
||||||
|
xorg.libXi
|
||||||
|
xorg.libXrandr
|
||||||
|
# If on wayland
|
||||||
|
libxkbcommon
|
||||||
|
wayland
|
||||||
|
# Rust
|
||||||
|
rustup
|
||||||
|
rustToolchain
|
||||||
|
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
|
||||||
|
shellHook = ''
|
||||||
|
# Required
|
||||||
|
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [
|
||||||
|
pkgs.alsaLib
|
||||||
|
pkgs.udev
|
||||||
|
pkgs.vulkan-loader
|
||||||
|
]}"
|
||||||
|
# Aliases and other fluff/ease of use
|
||||||
|
alias runIntel="nixVulkanIntel cargo run"
|
||||||
|
alias runMommyIntel="nixVulkanIntel cargo mommy run"
|
||||||
|
onefetch
|
||||||
|
echo "Welcome to nix-hell uh nix-shell!"
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use crate::load_yaml_folder;
|
||||||
|
|
||||||
|
pub struct LevelgenPlugin;
|
||||||
|
|
||||||
|
impl Plugin for LevelgenPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(Startup, setup_levels)
|
||||||
|
.add_systems(Update, level_generation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
|
pub struct Level {
|
||||||
|
doors: Vec<bool>,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct LevelGenerator {
|
||||||
|
levels_north: Vec<Level>,
|
||||||
|
levels_east: Vec<Level>,
|
||||||
|
levels_south: Vec<Level>,
|
||||||
|
levels_west: Vec<Level>,
|
||||||
|
path: Vec<Level>,
|
||||||
|
current_enemies: Vec<u32>,
|
||||||
|
current_waves: u32,
|
||||||
|
current_treasure: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn setup_levels(mut commands: Commands) {
|
||||||
|
let default_level: String = "
|
||||||
|
doors: [
|
||||||
|
true, # North
|
||||||
|
true, # East
|
||||||
|
true, # South
|
||||||
|
true, # West
|
||||||
|
]
|
||||||
|
".to_string();
|
||||||
|
|
||||||
|
let level_yaml: Vec<String> = load_yaml_folder(default_level, Path::new("./data/levels"));
|
||||||
|
|
||||||
|
let starting_level = serde_yaml::from_str::<Level>(&fs::read_to_string("./data/levels/default.yml").expect("Error reading data/levels/default.yml")).unwrap();
|
||||||
|
|
||||||
|
let mut levels_north_loaded: Vec<Level> = vec![];
|
||||||
|
let mut levels_east_loaded: Vec<Level> = vec![];
|
||||||
|
let mut levels_south_loaded: Vec<Level> = vec![];
|
||||||
|
let mut levels_west_loaded: Vec<Level> = vec![];
|
||||||
|
|
||||||
|
for level_data in level_yaml {
|
||||||
|
let level: Level = serde_yaml::from_str::<Level>(&level_data).expect("Error reading level");
|
||||||
|
|
||||||
|
if level.doors[0] == true {
|
||||||
|
levels_north_loaded.push(level.clone());
|
||||||
|
}
|
||||||
|
if level.doors[1] == true {
|
||||||
|
levels_east_loaded.push(level.clone());
|
||||||
|
}
|
||||||
|
if level.doors[2] == true {
|
||||||
|
levels_south_loaded.push(level.clone());
|
||||||
|
}
|
||||||
|
if level.doors[3] == true {
|
||||||
|
levels_west_loaded.push(level.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
LevelGenerator {
|
||||||
|
levels_north: levels_north_loaded,
|
||||||
|
levels_east: levels_east_loaded,
|
||||||
|
levels_south: levels_south_loaded,
|
||||||
|
levels_west: levels_west_loaded,
|
||||||
|
path: vec![starting_level.clone()],
|
||||||
|
current_enemies: Vec::new(),
|
||||||
|
current_waves: 1,
|
||||||
|
current_treasure: 1,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn level_generation() {
|
||||||
|
|
||||||
|
}
|
97
src/main.rs
97
src/main.rs
|
@ -1,28 +1,14 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use player::PlayerPlugin;
|
use crate::objects::player::Player;
|
||||||
use serde::{Deserialize, Serialize};
|
use crate::objects::player::PlayerPlugin;
|
||||||
use std::fs;
|
use crate::levelgen::LevelgenPlugin;
|
||||||
use std::path::Path;
|
use crate::setup::config_loader::load_yaml_folder;
|
||||||
use crate::player::Player;
|
use crate::user_interface::input_visual::InputVisualPlugin;
|
||||||
|
|
||||||
#[derive(Component, Serialize, Deserialize)]
|
pub mod objects;
|
||||||
pub struct Settings {
|
pub mod setup;
|
||||||
pub up: String,
|
mod levelgen;
|
||||||
pub down: String,
|
mod user_interface;
|
||||||
pub left: String,
|
|
||||||
pub right: String,
|
|
||||||
pub input_sprite_path: String,
|
|
||||||
pub input_sprite_size: Vec2,
|
|
||||||
pub input_sprite_location: Vec2,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct InputVisual {
|
|
||||||
pub location: Vec2,
|
|
||||||
pub input_direction: Vec2,
|
|
||||||
}
|
|
||||||
|
|
||||||
mod player;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -41,63 +27,15 @@ fn main() {
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.add_plugins(PlayerPlugin)
|
.add_plugins(PlayerPlugin)
|
||||||
|
.add_plugins(InputVisualPlugin)
|
||||||
|
.add_plugins(LevelgenPlugin)
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, get_input)
|
.add_systems(Update, get_input)
|
||||||
.add_systems(Update, draw_input)
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn setup(mut commands: Commands) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
|
||||||
let mut settings_yaml: String = "
|
|
||||||
# Change these to whatever you want
|
|
||||||
up: W
|
|
||||||
down: S
|
|
||||||
left: A
|
|
||||||
right: D
|
|
||||||
input_sprite_path: neocat.png
|
|
||||||
input_sprite_size: [
|
|
||||||
30.0,
|
|
||||||
30.0
|
|
||||||
]
|
|
||||||
input_sprite_location: [
|
|
||||||
-200.0,
|
|
||||||
-200.0
|
|
||||||
]
|
|
||||||
"
|
|
||||||
.to_string();
|
|
||||||
let settings_file = Path::new("./data/settings.yml");
|
|
||||||
if settings_file.exists() {
|
|
||||||
settings_yaml =
|
|
||||||
fs::read_to_string("./data/settings.yml").expect("Error reading data/settings.yml");
|
|
||||||
} else {
|
|
||||||
fs::write("./data/settings.yml", settings_yaml.clone())
|
|
||||||
.expect("Error writing data/settings.yml");
|
|
||||||
}
|
|
||||||
let settings_data =
|
|
||||||
serde_yaml::from_str::<Settings>(&settings_yaml).expect("Error serializing to YAML");
|
|
||||||
|
|
||||||
commands.spawn((
|
|
||||||
SpriteBundle {
|
|
||||||
sprite: Sprite {
|
|
||||||
custom_size: Some(Vec2::new(
|
|
||||||
settings_data.input_sprite_size.x,
|
|
||||||
settings_data.input_sprite_size.y,
|
|
||||||
)),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
texture: asset_server.load(settings_data.input_sprite_path),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
InputVisual {
|
|
||||||
location: Vec2::new(
|
|
||||||
settings_data.input_sprite_location.x,
|
|
||||||
settings_data.input_sprite_location.y,
|
|
||||||
),
|
|
||||||
input_direction: Vec2::new(0.0, 0.0),
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: make it so keycodes can be changed (maby through JSON at first and later make a UI menu to edit said JSON)
|
//TODO: make it so keycodes can be changed (maby through JSON at first and later make a UI menu to edit said JSON)
|
||||||
|
@ -139,14 +77,3 @@ fn get_input(mut input_recievers: Query<&mut Player>, input: Res<Input<KeyCode>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_input(mut visuals: Query<(&mut Transform, &mut InputVisual)>, input: Query<&mut Player>) {
|
|
||||||
for player in &input {
|
|
||||||
for (mut transform, mut visual) in &mut visuals {
|
|
||||||
visual.input_direction.x = player.direction.x;
|
|
||||||
visual.input_direction.y = player.direction.y;
|
|
||||||
transform.translation.x = visual.location.x + (visual.input_direction.x * 10.0);
|
|
||||||
transform.translation.y = visual.location.y + (visual.input_direction.y * 10.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod player;
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use crate::setup::config_loader::load_yaml_folder;
|
||||||
|
|
||||||
pub struct PlayerPlugin;
|
pub struct PlayerPlugin;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ pub struct Player {
|
||||||
|
|
||||||
fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
//Default player_data
|
//Default player_data
|
||||||
let mut player_data_yaml: String = "
|
let player_data_default: String = "
|
||||||
#These values you can just go edit no problem
|
#These values you can just go edit no problem
|
||||||
sprite_path: blobcat_hertog.png
|
sprite_path: blobcat_hertog.png
|
||||||
speed: 75.0
|
speed: 75.0
|
||||||
|
@ -50,16 +50,11 @@ fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
dash_modifier: 0.3
|
dash_modifier: 0.3
|
||||||
"
|
"
|
||||||
.to_string();
|
.to_string();
|
||||||
let player_data_file = Path::new("./data/player_data.yml");
|
|
||||||
if player_data_file.exists() {
|
let player_data_yaml: Vec<String> = load_yaml_folder(player_data_default, Path::new("./data/player"));
|
||||||
player_data_yaml = fs::read_to_string("./data/player_data.yml")
|
|
||||||
.expect("Error reading data/player_data.yml");
|
|
||||||
} else {
|
|
||||||
fs::write("./data/player_data.yml", player_data_yaml.clone())
|
|
||||||
.expect("Error writing data/player_data.yml");
|
|
||||||
}
|
|
||||||
let player_data =
|
let player_data =
|
||||||
serde_yaml::from_str::<PlayerYAML>(&player_data_yaml).expect("Error serializing to YAML");
|
serde_yaml::from_str::<PlayerYAML>(&player_data_yaml[0]).expect("Error serializing to YAML");
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
SpriteBundle {
|
SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
|
@ -134,5 +129,19 @@ fn player_movement(mut characters: Query<(&mut Transform, &mut Player)>, time: R
|
||||||
|
|
||||||
transform.translation.x += player.movement.x * time.delta_seconds();
|
transform.translation.x += player.movement.x * time.delta_seconds();
|
||||||
transform.translation.y += player.movement.y * time.delta_seconds();
|
transform.translation.y += player.movement.y * time.delta_seconds();
|
||||||
|
|
||||||
|
if transform.translation.x > 250.0 {
|
||||||
|
transform.translation.x = 250.0;
|
||||||
|
}
|
||||||
|
if transform.translation.x < -250.0 {
|
||||||
|
transform.translation.x = -250.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if transform.translation.y > 250.0 {
|
||||||
|
transform.translation.y = 250.0;
|
||||||
|
}
|
||||||
|
if transform.translation.y < -250.0 {
|
||||||
|
transform.translation.y = -250.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod config_loader;
|
|
@ -0,0 +1,19 @@
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub fn load_yaml_folder(default: String, folder: &Path) -> Vec<String> {
|
||||||
|
let folder_path = fs::read_dir(folder).unwrap();
|
||||||
|
let mut return_yaml: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
for file in folder_path {
|
||||||
|
if file.as_ref().unwrap().path().with_extension("yml").exists() {
|
||||||
|
let yaml_file = fs::read_to_string(file.unwrap().path()).expect("Error reading config file");
|
||||||
|
return_yaml.push(yaml_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if return_yaml.capacity() < 1 {
|
||||||
|
return_yaml.push(default.clone());
|
||||||
|
fs::write(folder.join("default.yml"), default.clone()).expect("Error writing default");
|
||||||
|
}
|
||||||
|
return return_yaml;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
pub struct PlayAreaManagerPlugin;
|
||||||
|
|
||||||
|
impl Plugin for PlayAreaManagerPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod input_visual;
|
|
@ -0,0 +1,110 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use crate::setup::config_loader::load_yaml_folder;
|
||||||
|
use std::path::Path;
|
||||||
|
use crate::Player;
|
||||||
|
|
||||||
|
pub struct InputVisualPlugin;
|
||||||
|
|
||||||
|
#[derive(Component, Serialize, Deserialize)]
|
||||||
|
pub struct Settings {
|
||||||
|
pub up: String,
|
||||||
|
pub down: String,
|
||||||
|
pub left: String,
|
||||||
|
pub right: String,
|
||||||
|
pub input_lower_sprite_path: String,
|
||||||
|
pub input_upper_sprite_path: String,
|
||||||
|
pub input_sprite_size: Vec2,
|
||||||
|
pub input_sprite_location: Vec2,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct InputVisual {
|
||||||
|
pub location: Vec2,
|
||||||
|
pub input_direction: Vec2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Plugin for InputVisualPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(Startup, setup_visual)
|
||||||
|
.add_systems(Update, draw_input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_visual(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
let settings_yaml_default: String = "
|
||||||
|
# Change these to whatever you want
|
||||||
|
up: W
|
||||||
|
down: S
|
||||||
|
left: A
|
||||||
|
right: D
|
||||||
|
input_lower_sprite_path: circle_empty.png
|
||||||
|
input_upper_sprite_path: circle_full.png
|
||||||
|
input_sprite_size: [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
]
|
||||||
|
input_sprite_location: [
|
||||||
|
-200.0,
|
||||||
|
-200.0
|
||||||
|
]
|
||||||
|
"
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let settings_yaml = load_yaml_folder(settings_yaml_default, Path::new("./data/settings"));
|
||||||
|
|
||||||
|
let settings_data =
|
||||||
|
serde_yaml::from_str::<Settings>(&settings_yaml[0]).expect("Error serializing to YAML");
|
||||||
|
|
||||||
|
commands.spawn(
|
||||||
|
SpriteBundle {
|
||||||
|
sprite: Sprite {
|
||||||
|
custom_size: Some(Vec2::new(
|
||||||
|
settings_data.input_sprite_size.x,
|
||||||
|
settings_data.input_sprite_size.y,
|
||||||
|
)),
|
||||||
|
anchor:
|
||||||
|
bevy::sprite::Anchor::Custom(Vec2::new(
|
||||||
|
6.658,
|
||||||
|
6.658,
|
||||||
|
)),
|
||||||
|
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
texture: asset_server.load(settings_data.input_lower_sprite_path),
|
||||||
|
..default()
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
commands.spawn((
|
||||||
|
SpriteBundle {
|
||||||
|
sprite: Sprite {
|
||||||
|
custom_size: Some(Vec2::new(
|
||||||
|
settings_data.input_sprite_size.x,
|
||||||
|
settings_data.input_sprite_size.y,
|
||||||
|
)),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
texture: asset_server.load(settings_data.input_upper_sprite_path),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
InputVisual {
|
||||||
|
location: Vec2::new(
|
||||||
|
settings_data.input_sprite_location.x,
|
||||||
|
settings_data.input_sprite_location.y,
|
||||||
|
),
|
||||||
|
input_direction: Vec2::new(0.0, 0.0),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_input(mut visuals: Query<(&mut Transform, &mut InputVisual)>, input: Query<&mut Player>){
|
||||||
|
for player in &input {
|
||||||
|
for (mut transform, mut visual) in &mut visuals {
|
||||||
|
visual.input_direction.x = player.direction.x;
|
||||||
|
visual.input_direction.y = player.direction.y;
|
||||||
|
transform.translation.x = visual.location.x + (visual.input_direction.x * 10.0);
|
||||||
|
transform.translation.y = visual.location.y + (visual.input_direction.y * 10.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue