| @@ -0,0 +1 @@ | |||||
| /target | |||||
| @@ -0,0 +1,10 @@ | |||||
| [package] | |||||
| name = "shipyard" | |||||
| version = "0.1.0" | |||||
| authors = ["Isabelle Lesko <me@izzabelle.dev>"] | |||||
| edition = "2018" | |||||
| [dependencies] | |||||
| amethyst = { version = "0.15.3", features = ["vulkan"] } | |||||
| rand = "0.8.4" | |||||
| rand_pcg = "0.3.1" | |||||
| @@ -0,0 +1,4 @@ | |||||
| ( | |||||
| title: "Shipyard", | |||||
| dimensions: Some((1280, 720)), | |||||
| ) | |||||
| @@ -0,0 +1 @@ | |||||
| 1.47 | |||||
| @@ -0,0 +1,20 @@ | |||||
| use amethyst::ecs::{Component, DenseVecStorage}; | |||||
| // a struct to represent an object in space which has mass and follows | |||||
| // orbital mechanics | |||||
| pub struct CelestialBody { | |||||
| pub mass: u128, | |||||
| pub x: i128, | |||||
| pub y: i128, | |||||
| } | |||||
| impl CelestialBody { | |||||
| // create a new celestial body | |||||
| pub fn new(mass: u128, x: i128, y: i128) -> Self { | |||||
| Self { mass, x, y } | |||||
| } | |||||
| } | |||||
| impl Component for CelestialBody { | |||||
| type Storage = DenseVecStorage<Self>; | |||||
| } | |||||
| @@ -0,0 +1 @@ | |||||
| pub mod celestial_body; | |||||
| @@ -0,0 +1,36 @@ | |||||
| mod components; | |||||
| mod states; | |||||
| mod utils; | |||||
| // namespacing | |||||
| use amethyst::{ | |||||
| prelude::*, | |||||
| renderer::{ | |||||
| plugins::{RenderFlat2D, RenderToWindow}, | |||||
| types::DefaultBackend, | |||||
| RenderingBundle, | |||||
| }, | |||||
| utils::application_root_dir, | |||||
| }; | |||||
| use states::TestingState; | |||||
| fn main() -> amethyst::Result<()> { | |||||
| amethyst::start_logger(Default::default()); | |||||
| let app_root = application_root_dir()?; | |||||
| let assets_dir = app_root.join("assets"); | |||||
| let display_conf = app_root.join("config").join("display.ron"); | |||||
| let game_data = GameDataBuilder::default().with_bundle( | |||||
| RenderingBundle::<DefaultBackend>::new() | |||||
| .with_plugin( | |||||
| RenderToWindow::from_config_path(display_conf)?.with_clear([0.0, 0.0, 0.0, 1.0]), | |||||
| ) | |||||
| .with_plugin(RenderFlat2D::default()), | |||||
| )?; | |||||
| let mut shipyard = Application::new(assets_dir, TestingState, game_data)?; | |||||
| shipyard.run(); | |||||
| Ok(()) | |||||
| } | |||||
| @@ -0,0 +1,2 @@ | |||||
| mod testing_state; | |||||
| pub use testing_state::TestingState; | |||||
| @@ -0,0 +1,36 @@ | |||||
| use amethyst::prelude::*; | |||||
| use amethyst::winit::{Event, KeyboardInput, VirtualKeyCode, WindowEvent}; | |||||
| pub struct TestingState; | |||||
| impl SimpleState for TestingState { | |||||
| fn on_start(&mut self, _data: StateData<'_, GameData<'_, '_>>) { | |||||
| use super::super::utils::asteroid::AsteroidGenerator; | |||||
| let mut asteroid = AsteroidGenerator::init(None); | |||||
| for _ in 0..16 { | |||||
| asteroid.random(); | |||||
| } | |||||
| } | |||||
| fn handle_event( | |||||
| &mut self, | |||||
| _: StateData<'_, GameData<'_, '_>>, | |||||
| event: StateEvent, | |||||
| ) -> SimpleTrans { | |||||
| if let StateEvent::Window(event) = &event { | |||||
| match event { | |||||
| Event::WindowEvent { event, .. } => match event { | |||||
| WindowEvent::KeyboardInput { | |||||
| input: KeyboardInput { virtual_keycode: Some(VirtualKeyCode::Escape), .. }, | |||||
| .. | |||||
| } | |||||
| | WindowEvent::CloseRequested => Trans::Quit, | |||||
| _ => Trans::None, | |||||
| }, | |||||
| _ => Trans::None, | |||||
| } | |||||
| } else { | |||||
| Trans::None | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,38 @@ | |||||
| use std::io::Write; | |||||
| use amethyst::prelude::*; | |||||
| use rand::prelude::*; | |||||
| use rand_pcg::Pcg64; | |||||
| const NAME_CHARSET: &[u8] = b"012345679ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |||||
| pub struct AsteroidGenerator { | |||||
| rng: Pcg64, | |||||
| names: Vec<String>, | |||||
| } | |||||
| impl AsteroidGenerator { | |||||
| pub fn init(seed: Option<u64>) -> Self { | |||||
| let rng = Pcg64::seed_from_u64(if let Some(seed) = seed { seed } else { 0 }); | |||||
| AsteroidGenerator { rng, names: Vec::new() } | |||||
| } | |||||
| pub fn random(&mut self /*, world: &mut World*/) { | |||||
| self.generate_name(); | |||||
| } | |||||
| fn generate_name(&mut self) -> String { | |||||
| String::from_utf8( | |||||
| (0..=6) | |||||
| .map(|i| match i { | |||||
| 0..=2 => NAME_CHARSET[self.rng.gen_range(10..NAME_CHARSET.len())], | |||||
| 3 => b'-', | |||||
| 4..=6 => NAME_CHARSET[self.rng.gen_range(0..10)], | |||||
| _ => panic!("nope"), | |||||
| }) | |||||
| .collect(), | |||||
| ) | |||||
| .unwrap() | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1 @@ | |||||
| pub mod asteroid; | |||||