diff --git a/.gitignore b/.gitignore index 3f4c5cd..e120e7b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ target/ Cargo.lock +*.dll + diff --git a/Cargo.toml b/Cargo.toml index 6e234de..5d10895 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,16 @@ authors = ["Gnarwhal "] edition = "2018" [dependencies] -amethyst = "0.15.0" +amethyst_window = "0.5.0" +winit = "0.22.2" + +[dependencies.serde] +version = "1" +features = ["derive"] + +[dependencies.amethyst] +version = "0.15.0" +features = ["no-slow-safety-checks", "sdl_controller"] [features] default = ["vulkan"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..70988e3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +Mit License + +Copyright (c) 2020 Gnarly Narwhal + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the Software), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/config/bindings.ron b/config/bindings.ron deleted file mode 100644 index 093c4d2..0000000 --- a/config/bindings.ron +++ /dev/null @@ -1,4 +0,0 @@ -( - axes: {}, - actions: {} -) \ No newline at end of file diff --git a/config/display.ron b/config/display.ron deleted file mode 100644 index 3831bfa..0000000 --- a/config/display.ron +++ /dev/null @@ -1,4 +0,0 @@ -( - title: "DJam 4!", - dimensions: Some((500, 500)) -) \ No newline at end of file diff --git a/resources/bindings.ron b/resources/bindings.ron new file mode 100644 index 0000000..e50aae4 --- /dev/null +++ b/resources/bindings.ron @@ -0,0 +1,34 @@ +( + // YES! I KNOW THIS IS A BAD WAY TO SUPPORT CONTROLLERS! + // --- The Unnecessary Defense --- + // I'm new to the engine and it's a almost half way through a game jam and I have a black window to show for it, so please(!) give me a break 🥺? + axes: { + Horizontal(-1): Emulated(pos: ScanCode(32), neg: ScanCode(30)), + Horizontal( 0): Controller(controller_id: 0, axis: LeftX, invert: false, dead_zone: 0.1), + Horizontal( 1): Controller(controller_id: 1, axis: LeftX, invert: false, dead_zone: 0.1), + Horizontal( 2): Controller(controller_id: 2, axis: LeftX, invert: false, dead_zone: 0.1), + Horizontal( 3): Controller(controller_id: 3, axis: LeftX, invert: false, dead_zone: 0.1), + Horizontal( 4): Controller(controller_id: 4, axis: LeftX, invert: false, dead_zone: 0.1), + Horizontal( 5): Controller(controller_id: 5, axis: LeftX, invert: false, dead_zone: 0.1), + }, + actions: { + ShortHop: [ + [Controller(0, X)], + [Controller(1, X)], + [Controller(2, X)], + [Controller(3, X)], + [Controller(4, X)], + [Controller(5, X)], + ], + FullHop: [ + [ScanCode(17)], + [ScanCode(57)], + [Controller(0, A)], + [Controller(1, A)], + [Controller(2, A)], + [Controller(3, A)], + [Controller(4, A)], + [Controller(5, A)], + ], + } +) \ No newline at end of file diff --git a/resources/display_config.ron b/resources/display_config.ron new file mode 100644 index 0000000..524a494 --- /dev/null +++ b/resources/display_config.ron @@ -0,0 +1,5 @@ +( + title: "DJam 4", + resizable: true, + dimensions: Some((1280, 720)), +) \ No newline at end of file diff --git a/resources/icon.png b/resources/icon.png new file mode 100644 index 0000000..9e4ee16 Binary files /dev/null and b/resources/icon.png differ diff --git a/src/components/mod.rs b/src/components/mod.rs new file mode 100644 index 0000000..40fd931 --- /dev/null +++ b/src/components/mod.rs @@ -0,0 +1,31 @@ +/******************************************************************************* + * + * Copyright (c) 2020 Gnarwhal + * + * ----------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files(the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + *******************************************************************************/ + +pub use self::{ + player::Player +}; + +mod player; \ No newline at end of file diff --git a/src/components/player.rs b/src/components/player.rs new file mode 100644 index 0000000..8f7e05f --- /dev/null +++ b/src/components/player.rs @@ -0,0 +1,45 @@ +/******************************************************************************* + * + * Copyright (c) 2020 Gnarwhal + * + * ----------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files(the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + *******************************************************************************/ + +use amethyst::{ + ecs::prelude::{Component, DenseVecStorage}, +}; + +pub struct Player { + pub id: u32, +} + +impl Player { + pub fn new(id: u32) -> Player { + return Player{ + id + }; + } +} + +impl Component for Player { + type Storage = DenseVecStorage; +} diff --git a/src/main.rs b/src/main.rs index abf6662..81d2a48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,9 +24,14 @@ * *******************************************************************************/ +mod components; +mod states; +mod systems; + use amethyst::{ + core::TransformBundle, prelude::*, - input::{InputBundle, StringBindings}, + input::{InputBundle}, renderer::{ RenderingBundle, types::DefaultBackend, @@ -34,34 +39,38 @@ use amethyst::{ }, utils::application_root_dir, }; - -pub struct DJam; - -impl SimpleState for DJam {} +use amethyst_window::{DisplayConfig, Icon}; +use std::path::PathBuf; fn main() -> amethyst::Result<()> { amethyst::start_logger(Default::default()); let app_root = application_root_dir()?; - let assets_dir = app_root.join("assets"); - let display_config_path = app_root.join("config").join("display.ron"); - let binding_path = app_root.join("config").join("bindings.ron"); + let resources_dir = app_root.join("resources"); + let display_config_path = resources_dir.join("display_config.ron"); + let binding_path = resources_dir.join("bindings.ron"); - let input_bundle = InputBundle::::new().with_bindings_from_file(binding_path)?; + let mut display_config = DisplayConfig::load(display_config_path)?; + display_config.icon = Some(PathBuf::from("resources/icon.png")); + + let input_bundle = InputBundle::::new() + .with_bindings_from_file(binding_path)?; let game_data = GameDataBuilder::default() + .with_bundle(TransformBundle::new())? .with_bundle(input_bundle)? .with_bundle( RenderingBundle::::new() .with_plugin( - RenderToWindow::from_config_path(display_config_path)? + RenderToWindow::from_config(display_config) .with_clear([0.0, 0.0, 0.0, 1.0]), ) .with_plugin(RenderFlat2D::default()) - )?; + )? + .with(systems::PlayerSystem, "player_system", &["input_system"]); - let mut game = Application::new(assets_dir, DJam,game_data)?; + let mut game = Application::new(resources_dir, states::LevelState, game_data)?; game.run(); Ok(()) diff --git a/src/states/level.rs b/src/states/level.rs new file mode 100644 index 0000000..df06ebf --- /dev/null +++ b/src/states/level.rs @@ -0,0 +1,67 @@ +/******************************************************************************* + * + * Copyright (c) 2020 Gnarwhal + * + * ----------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files(the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + *******************************************************************************/ + +use amethyst::{ + assets::{AssetStorage, Loader, Handle}, + core::transform::Transform, + ecs::prelude::{Component, DenseVecStorage}, + prelude::*, + renderer::{Camera, ImageFormat, SpriteRender, SpriteSheet, SpriteSheetFormat, Texture} +}; +use crate::components::Player; + +pub const CAMERA_WIDTH: f32 = 1920.0; +pub const CAMERA_HEIGHT: f32 = 1080.0; + +fn initialize_camera(world: &mut World) { + let mut transform = Transform::default(); + transform.set_translation_xyz(CAMERA_WIDTH * 0.5, CAMERA_HEIGHT * 0.5, 1.0); + + world + .create_entity() + .with(Camera::standard_2d(CAMERA_WIDTH, CAMERA_HEIGHT)) + .with(transform) + .build(); +} + +fn initialize_player(world: &mut World) { + world + .create_entity() + .with(Player::new(0)) + .with(Transform::default()) + .build(); +} + +pub struct LevelState; + +impl SimpleState for LevelState { + fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { + let world = data.world; + + initialize_camera(world); + initialize_player(world); + } +} \ No newline at end of file diff --git a/src/states/mod.rs b/src/states/mod.rs new file mode 100644 index 0000000..c100959 --- /dev/null +++ b/src/states/mod.rs @@ -0,0 +1,31 @@ +/******************************************************************************* + * + * Copyright (c) 2020 Gnarwhal + * + * ----------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files(the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + *******************************************************************************/ + +pub use self::{ + level::LevelState +}; + +mod level; \ No newline at end of file diff --git a/src/systems/mod.rs b/src/systems/mod.rs new file mode 100644 index 0000000..6c962ae --- /dev/null +++ b/src/systems/mod.rs @@ -0,0 +1,32 @@ +/******************************************************************************* + * + * Copyright (c) 2020 Gnarwhal + * + * ----------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files(the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + *******************************************************************************/ + +pub use self::{ + player::PlayerSystem, + player::PlayerBindings, +}; + +mod player; \ No newline at end of file diff --git a/src/systems/player.rs b/src/systems/player.rs new file mode 100644 index 0000000..1b8a58f --- /dev/null +++ b/src/systems/player.rs @@ -0,0 +1,97 @@ +/******************************************************************************* + * + * Copyright (c) 2020 Gnarwhal + * + * ----------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files(the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + *******************************************************************************/ + +use std::fmt::{self, Display}; + +use amethyst::{ + core::{Transform, SystemDesc}, + derive::SystemDesc, + ecs::{Join, Read, ReadStorage, System, SystemData, World, WriteStorage}, + input::{InputHandler, BindingTypes, Bindings}, +}; +use serde::{Serialize, Deserialize}; +use crate::components::Player; + +#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] +pub enum MovementBindings { + Horizontal(i8), +} + +#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] +pub enum ActionBindings { + ShortHop, + FullHop, +} + +impl Display for MovementBindings { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +impl Display for ActionBindings { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + + +#[derive(Debug)] +pub struct PlayerBindings; + +impl BindingTypes for PlayerBindings { + type Axis = MovementBindings; + type Action = ActionBindings; +} + +#[derive(SystemDesc)] +pub struct PlayerSystem; + +impl <'s> System<'s> for PlayerSystem { + type SystemData = ( + WriteStorage<'s, Transform>, + ReadStorage<'s, Player>, + Read<'s, InputHandler>, + ); + + fn run(&mut self, (mut transforms, players, input): Self::SystemData) { + for (transform, _) in (&mut transforms, &players).join() { + let mut movement = 0.0f32; + for input_id in -1..6 { + movement += input + .axis_value(&MovementBindings::Horizontal(input_id)) + .unwrap_or(0.0); + } + + if movement != 0.0 { + println!("Movement: {}", movement); + } + if input.action_is_down(&ActionBindings::FullHop).unwrap_or(false) { + println!("Yump yump!"); + } + } + } +} \ No newline at end of file