[−][src]Crate crystal_engine
This is a prototype game engine, focussed on abstracting away all rendering logic and focussing purely on the game logic.
Example
use cgmath::{Matrix4, Point3, Rad, Vector3}; use crystal_engine::{GameState, ModelHandle, Window, event::VirtualKeyCode}; fn main() { // Create a new instance of your game and run it let window = Window::<Game>::new(800., 600.); window.run(); } pub struct Game { // Your game state is stored here model: ModelHandle, } impl crystal_engine::Game for Game { fn init(state: &mut GameState) -> Self { // Load an object. This will automatically be rendered every frame // as long as the returned ModelHandle is not dropped. // Note that "new_obj_model" is only available when using the "format-obj" feature // for more information and different model formats, see the documentation of "GameState" let model = state.new_obj_model("assets/some_object.obj") .with_position((0.0, -3.0, 0.0)) .with_scale(0.3) .build(); // Update the camera by manipulating the state's field state.camera = Matrix4::look_at( Point3::new(0.3, 0.3, 1.0), Point3::new(0.0, 0.0, 0.0), Vector3::new(0.0, -1.0, 0.0), ); Self { model } } fn keydown(&mut self, state: &mut GameState, key: VirtualKeyCode) { // Exit the game when the user hits escape if key == VirtualKeyCode::Escape { state.terminate_game(); } } fn update(&mut self, state: &mut GameState) { self.model.modify(|data| { // Rotate either left or right, based on what the user has pressed if state.keyboard.is_pressed(VirtualKeyCode::A) { data.rotation.y -= Rad(0.05); } if state.keyboard.is_pressed(VirtualKeyCode::D) { data.rotation.y += Rad(0.05); } }); } }
Modules
event | Re-exported module of |
state | Contains the states that are used in GameState. These are in a seperate module so we don't pollute the base module documentation. |
Structs
DirectionalLight | A direction lightsource in the world. |
GameState | Contains the game state. This struct is passed to Game::init and Game::update. |
LightColor | The color of the light. This is divided in 3 fields: ambient, diffuse and specular. See each field for the definition. |
ModelData | Data of a model. This is behind an |
ModelHandle | A handle to the model that was loaded. This can be used to move the model around in the world. |
PointLight | A pointlight in the world. |
PointLightAttenuation | The attenuation of the pointlight, or how much the light impacts objects based on their distance. |
Window | A handle to the window and the game state. This will be your main entrypoint of the game. |
Traits
Game | The entry point of the game implementation. |