浏览代码

initial commit

master
Isabelle L. 4 年前
当前提交
493f8c803f
共有 12 个文件被更改,包括 4143 次插入0 次删除
  1. +1
    -0
      .gitignore
  2. +3993
    -0
      Cargo.lock
  3. +10
    -0
      Cargo.toml
  4. +4
    -0
      config/display.ron
  5. +1
    -0
      rust-toolchain
  6. +20
    -0
      src/components/celestial_body.rs
  7. +1
    -0
      src/components/mod.rs
  8. +36
    -0
      src/main.rs
  9. +2
    -0
      src/states/mod.rs
  10. +36
    -0
      src/states/testing_state.rs
  11. +38
    -0
      src/utils/asteroid.rs
  12. +1
    -0
      src/utils/mod.rs

+ 1
- 0
.gitignore 查看文件

@@ -0,0 +1 @@
/target

+ 3993
- 0
Cargo.lock
文件差异内容过多而无法显示
查看文件


+ 10
- 0
Cargo.toml 查看文件

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

+ 4
- 0
config/display.ron 查看文件

@@ -0,0 +1,4 @@
(
title: "Shipyard",
dimensions: Some((1280, 720)),
)

+ 1
- 0
rust-toolchain 查看文件

@@ -0,0 +1 @@
1.47

+ 20
- 0
src/components/celestial_body.rs 查看文件

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

+ 1
- 0
src/components/mod.rs 查看文件

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

+ 36
- 0
src/main.rs 查看文件

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

+ 2
- 0
src/states/mod.rs 查看文件

@@ -0,0 +1,2 @@
mod testing_state;
pub use testing_state::TestingState;

+ 36
- 0
src/states/testing_state.rs 查看文件

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

+ 38
- 0
src/utils/asteroid.rs 查看文件

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

+ 1
- 0
src/utils/mod.rs 查看文件

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

正在加载...
取消
保存