Initial commit
This commit is contained in:
commit
3f762fde47
6 changed files with 280 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
Cargo.lock
|
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.background": "#412902",
|
||||
"titleBar.activeBackground": "#5B3903",
|
||||
"titleBar.activeForeground": "#FFF9F1"
|
||||
}
|
||||
}
|
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "mill_game"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
engine = { path = "../Gavania/engine", features = ["graphical"] }
|
||||
|
||||
anyhow = { version = "1.0.70", features = ["backtrace"] }
|
||||
|
189
src/board.rs
Normal file
189
src/board.rs
Normal file
|
@ -0,0 +1,189 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use engine::prelude::{
|
||||
cgmath::{vec3, Vector3},
|
||||
*,
|
||||
};
|
||||
|
||||
pub struct Board {
|
||||
board: Entity,
|
||||
}
|
||||
|
||||
impl Board {
|
||||
pub fn new(engine: Arc<Engine>, scene: &mut SceneHandle) -> Result<Arc<Self>> {
|
||||
let mut board_entity = engine.assets().empty_entity();
|
||||
|
||||
let meshes = vec![Self::create_board_base(&engine)?];
|
||||
|
||||
let draw = Draw::new(meshes);
|
||||
board_entity.insert_component(draw);
|
||||
|
||||
let location = Location::from_entity(&mut board_entity);
|
||||
board_entity.insert_component(location);
|
||||
|
||||
let mut board = None;
|
||||
scene.on_scene(|scene| {
|
||||
board = Some(scene.add_entity(board_entity)?);
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
Ok(Arc::new(Self {
|
||||
board: board.unwrap(),
|
||||
}))
|
||||
}
|
||||
|
||||
fn create_board_base(engine: &Arc<Engine>) -> Result<AssetMesh> {
|
||||
let mut board_base = AssetMesh::new(
|
||||
engine.device(),
|
||||
engine.settings().graphics_info()?.render_type,
|
||||
)?;
|
||||
|
||||
let vertex_buffer = Buffer::builder()
|
||||
.set_data(&Self::create_cuboid(
|
||||
vec3(-17.5, -20.0, -2.0),
|
||||
vec3(35.0, 40.0, 2.0),
|
||||
))
|
||||
.set_usage(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT)
|
||||
.set_memory_usage(MemoryUsage::CpuOnly)
|
||||
.build(engine.device().clone())?;
|
||||
|
||||
let color = Color::try_from("#b77b2b")?;
|
||||
let a: [f32; 3] = color.into();
|
||||
|
||||
board_base.add_primitive(
|
||||
vertex_buffer,
|
||||
None,
|
||||
None,
|
||||
PrimitiveMaterial {
|
||||
color: [a[0], a[1], a[2], 1.0],
|
||||
metallic_factor: 0.2,
|
||||
emissive_factor: [0.2, 0.2, 0.2],
|
||||
roughness_factor: 0.8,
|
||||
alpha_mode: AlphaMode::Opaque,
|
||||
alpha_cut_off: 0.5,
|
||||
},
|
||||
true,
|
||||
)?;
|
||||
|
||||
Ok(board_base)
|
||||
}
|
||||
|
||||
fn create_cuboid(offset: Vector3<f32>, extent: Vector3<f32>) -> Vec<PositionNormal> {
|
||||
vec![
|
||||
// near
|
||||
PositionNormal::new(
|
||||
vec3(offset.x, offset.y + extent.y, offset.z + extent.z),
|
||||
vec3(0.0, -1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(
|
||||
offset.x + extent.x,
|
||||
offset.y + extent.y,
|
||||
offset.z + extent.z,
|
||||
),
|
||||
vec3(0.0, -1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x, offset.y + extent.y, offset.z),
|
||||
vec3(0.0, -1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x, offset.y + extent.y, offset.z),
|
||||
vec3(0.0, -1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x, offset.y + extent.y, offset.z),
|
||||
vec3(0.0, -1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x, offset.y + extent.y, offset.z + extent.z),
|
||||
vec3(0.0, -1.0, 0.0),
|
||||
),
|
||||
// right
|
||||
PositionNormal::new(
|
||||
vec3(
|
||||
offset.x + extent.x,
|
||||
offset.y + extent.y,
|
||||
offset.z + extent.z,
|
||||
),
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x + extent.x, offset.y, offset.z + extent.z),
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x + extent.x, offset.y, offset.z),
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x + extent.x, offset.y, offset.z),
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x + extent.x, offset.y + extent.y, offset.z),
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(
|
||||
offset.x + extent.x,
|
||||
offset.y + extent.y,
|
||||
offset.z + extent.z,
|
||||
),
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
),
|
||||
// far
|
||||
PositionNormal::new(
|
||||
vec3(offset.x + extent.x, offset.y, offset.z + extent.z),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x, offset.y, offset.z + extent.z),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(vec3(offset.x, offset.y, offset.z), vec3(0.0, 1.0, 0.0)),
|
||||
PositionNormal::new(vec3(offset.x, offset.y, offset.z), vec3(0.0, 1.0, 0.0)),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x + extent.x, offset.y, offset.z),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
),
|
||||
PositionNormal::new(
|
||||
vec3(offset.x + extent.x, offset.y, offset.z + extent.z),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl Map for Board {
|
||||
fn name(&self) -> &str {
|
||||
"MillBoard"
|
||||
}
|
||||
|
||||
fn check_walkability(
|
||||
&self,
|
||||
_position: cgmath::Vector2<f32>,
|
||||
_direction: cgmath::Vector2<f32>,
|
||||
_radius: f32,
|
||||
) -> Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn get_height(&self, _x: f32, _y: f32) -> Result<f32> {
|
||||
Ok(0.0)
|
||||
}
|
||||
|
||||
fn spawn_positions(&self) -> Result<Vec<cgmath::Vector3<f32>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
fn leave_markers(&self) -> Result<Vec<Entity>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
fn disable(&self, scene: &mut Scene) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
53
src/game.rs
Normal file
53
src/game.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use engine::prelude::*;
|
||||
|
||||
use crate::board::Board;
|
||||
|
||||
pub struct MillGame {
|
||||
board: Arc<Board>,
|
||||
scene: SceneHandle,
|
||||
}
|
||||
|
||||
impl MillGame {
|
||||
pub fn new(engine: Arc<Engine>) -> Result<Arc<Self>> {
|
||||
let mut scene = SceneHandle::new(&engine)?;
|
||||
|
||||
scene.activate()?;
|
||||
|
||||
Ok(Arc::new(Self {
|
||||
board: Board::new(engine, &mut scene)?,
|
||||
scene,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl EngineObject for MillGame {
|
||||
fn name(&self) -> &str {
|
||||
"MillGame"
|
||||
}
|
||||
|
||||
fn update(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn event(&self, event: EngineEvent) -> Result<()> {
|
||||
match event {
|
||||
EngineEvent::MouseMotion(_, _) => todo!(),
|
||||
EngineEvent::MouseButtonDown(_) => todo!(),
|
||||
EngineEvent::MouseButtonUp(_) => todo!(),
|
||||
EngineEvent::MouseWheel(_, _, _) => todo!(),
|
||||
EngineEvent::KeyDown(_) => todo!(),
|
||||
EngineEvent::KeyUp(_) => todo!(),
|
||||
EngineEvent::ButtonDown(_) => todo!(),
|
||||
EngineEvent::ButtonUp(_) => todo!(),
|
||||
EngineEvent::ControllerAxis(_) => todo!(),
|
||||
EngineEvent::ControllerAdded(_) => todo!(),
|
||||
EngineEvent::ControllerRemoved(_) => todo!(),
|
||||
EngineEvent::FileDrop(_) => todo!(),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
17
src/main.rs
Normal file
17
src/main.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
mod board;
|
||||
mod game;
|
||||
|
||||
use anyhow::Result;
|
||||
use engine::prelude::*;
|
||||
use game::MillGame;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut create_info = EngineCreateInfo::default();
|
||||
create_info.resource_base_path = "".to_string();
|
||||
|
||||
let engine = Engine::new(create_info)?;
|
||||
|
||||
engine.set_game_object(Some(MillGame::new(engine.clone())?))?;
|
||||
|
||||
engine.run()
|
||||
}
|
Loading…
Reference in a new issue