Compare commits

...

14 Commits

Author SHA1 Message Date
Johannes Hendrik Gerard van der Weide 0505eaea8b Update 2024-04-09 15:19:00 +02:00
Johannes Hendrik Gerard van der Weide 9f49fb4acc Input visual moved to it's own lil file :3 2024-01-31 14:58:25 +01:00
Johannes Hendrik Gerard van der Weide 3eae9f5896 Specified Rust version in Cargo.toml nix shell and builder 2024-01-22 14:04:39 +01:00
Johannes Hendrik Gerard van der Weide 4ea9cdf612 Orginisation for building later 2024-01-16 13:31:18 +01:00
Johannes Hendrik Gerard van der Weide d1d0eac44d Joystick sprite done 2024-01-11 19:35:22 +01:00
Johannes Hendrik Gerard van der Weide 16ac1444ce Player is now sorted into the objects folder 2024-01-11 14:00:23 +01:00
Johannes Hendrik Gerard van der Weide 07e05ab805 Added temp bounds will ty this into camera script later 2023-12-13 16:46:42 +01:00
Johannes Hendrik Gerard van der Weide a415a32012 Spawn LevelGenerator and fill it 2023-12-13 16:32:49 +01:00
Johannes Hendrik Gerard van der Weide 92d37cbfcf Added the still empty level gen plugin 2023-12-12 19:58:54 +01:00
Johannes Hendrik Gerard van der Weide 5f72edba96 main.rs cleanup 2023-12-12 17:41:34 +01:00
Johannes Hendrik Gerard van der Weide af00347fa5 Writing is now also back! 2023-12-12 17:35:51 +01:00
Johannes Hendrik Gerard van der Weide adc11ec654 Unfinished levelgen script 2023-12-12 16:59:37 +01:00
Johannes Hendrik Gerard van der Weide 2720215da7 Updated README.md to inform about dev branch 2023-12-12 16:59:12 +01:00
Johannes Hendrik Gerard van der Weide b8e067f4e4 Loading in YAML files is now per folder and from one function 2023-12-12 16:49:54 +01:00
19 changed files with 383 additions and 161 deletions

View File

@ -6,6 +6,7 @@ description = "A W.I.P. bevy-engine game "
authors = ["Johannes Hendrik Gerard van der Weide"]
version = "0.1.0"
edition = "2021"
rust-version = "1.70"
license-file = "LICENSE"
readme = "README.md"

View File

@ -1,19 +1,5 @@
# RustThingy
This place is a message... and part of a system of messages... pay attention to it!
Sending this message was important to us. We considered ourselves to be a powerful culture.
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.
Welcome to the development branch!
Expect it to be broken as any progress will be pushed.
If you need a gauranty of it compiling propperly use main.

BIN
assets/circle_empty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
assets/circle_full.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

17
data/levels/default.yml Normal file
View File

@ -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
]

View File

@ -4,7 +4,8 @@
down: S
left: A
right: D
input_sprite_path: neocat.png
input_lower_sprite_path: circle_empty.png
input_upper_sprite_path: circle_full.png
input_sprite_size: [
30.0,
30.0

View File

@ -39,51 +39,11 @@
{
# Development environment output
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = (with pkgs; [
# 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!"
'';
};
default = import ./nix/shell.nix { inherit pkgs; };
});
# Builder
packages = forAllSystems ({ pkgs }: {
default = import ./nix/default.nix { inherit pkgs; };
});
};
}

43
nix/default.nix Normal file
View File

@ -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/
'';
}

48
nix/shell.nix Normal file
View File

@ -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!"
'';
}

87
src/levelgen.rs Normal file
View File

@ -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() {
}

View File

@ -1,28 +1,14 @@
use bevy::prelude::*;
use player::PlayerPlugin;
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::Path;
use crate::player::Player;
use crate::objects::player::Player;
use crate::objects::player::PlayerPlugin;
use crate::levelgen::LevelgenPlugin;
use crate::setup::config_loader::load_yaml_folder;
use crate::user_interface::input_visual::InputVisualPlugin;
#[derive(Component, Serialize, Deserialize)]
pub struct Settings {
pub up: String,
pub down: String,
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;
pub mod objects;
pub mod setup;
mod levelgen;
mod user_interface;
fn main() {
App::new()
@ -41,63 +27,15 @@ fn main() {
.build(),
)
.add_plugins(PlayerPlugin)
.add_plugins(InputVisualPlugin)
.add_plugins(LevelgenPlugin)
.add_systems(Startup, setup)
.add_systems(Update, get_input)
.add_systems(Update, draw_input)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
fn setup(mut commands: Commands) {
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)
@ -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);
}
}
}

1
src/objects.rs Normal file
View File

@ -0,0 +1 @@
pub mod player;

View File

@ -1,7 +1,7 @@
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
use std::fs;
use serde::{Serialize, Deserialize};
use std::path::Path;
use crate::setup::config_loader::load_yaml_folder;
pub struct PlayerPlugin;
@ -33,7 +33,7 @@ pub struct Player {
fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
//Default player_data
let mut player_data_yaml: String = "
let player_data_default: String = "
#These values you can just go edit no problem
sprite_path: blobcat_hertog.png
speed: 75.0
@ -50,16 +50,11 @@ fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
dash_modifier: 0.3
"
.to_string();
let player_data_file = Path::new("./data/player_data.yml");
if player_data_file.exists() {
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_yaml: Vec<String> = load_yaml_folder(player_data_default, Path::new("./data/player"));
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((
SpriteBundle {
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.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;
}
}
}

1
src/setup.rs Normal file
View File

@ -0,0 +1 @@
pub mod config_loader;

View File

@ -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;
}

View File

@ -0,0 +1,11 @@
use bevy::prelude::*;
pub struct PlayAreaManagerPlugin;
impl Plugin for PlayAreaManagerPlugin {
fn build(&self, app: &mut App) {
app.add_systems();
}
}

1
src/user_interface.rs Normal file
View File

@ -0,0 +1 @@
pub mod input_visual;

View File

@ -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);
}
}
}