[][src]Crate amethyst

Amethyst is a free and open source game engine written in idiomatic Rust for building video games and interactive multimedia applications. The source code is available for download on GitHub. See the online book for a complete guide to using Amethyst.

This project is a work in progress and is very incomplete. Pardon the dust!

Example

use amethyst::prelude::*;
use amethyst::winit::{Event, KeyboardInput, VirtualKeyCode, WindowEvent};

struct GameState;

impl SimpleState for GameState {
    fn on_start(&mut self, _: StateData<'_, GameData<'_, '_>>) {
        println!("Starting game!");
    }

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

    fn update(&mut self, _: &mut StateData<'_, GameData<'_, '_>>) -> SimpleTrans {
        println!("Computing some more whoop-ass...");
        Trans::Quit
    }
}

fn main() {
    let mut game = Application::new("assets/", GameState, GameDataBuilder::default())
        .expect("Fatal error");
    game.run();
}

Re-exports

pub use amethyst_animation as animation;
pub use amethyst_assets as assets;
pub use amethyst_audio as audio;
pub use amethyst_config as config;
pub use amethyst_controls as controls;
pub use amethyst_core as core;
pub use amethyst_derive as derive;
pub use amethyst_error as error;
pub use amethyst_gltf as gltf;
pub use amethyst_input as input;
pub use amethyst_locale as locale;
pub use amethyst_network as network;
pub use amethyst_rendy as renderer;
pub use amethyst_ui as ui;
pub use amethyst_utils as utils;
pub use amethyst_window as window;
pub use winit;
pub use crate::core::ecs;
pub use crate::core::shred;
pub use crate::core::shrev;

Modules

prelude

Contains common types that can be glob-imported (*) for convenience.

Structs

ApplicationBuilder

ApplicationBuilder is an interface that allows for creation of an Application using a custom set of configuration. This is the normal way an Application object is created.

CallbackQueue

A simple Callback queue. Using the Sender you can get using the send_handle method, you can add functions modifying World from an asynchronous context. Those callbacks will be ran sequentially without preserving ordering.

CoreApplication

CoreApplication is the application implementation for the game engine. This is fully generic over the state type and event type.

Error

The error type used by Amethyst.

GameData

Default game data.

GameDataBuilder

Builder for default game data

Logger

Allows the creation of a logger with a set of custom configurations. If no custom configuration is required start_logger can be used instead.

LoggerConfig

Logger configuration object.

StateData

State data encapsulates the data sent to all state functions from the application main loop.

StateEventReader
StateMachine

A simple stack-based state machine (pushdown automaton).

Enums

LogLevelFilter

An enum representing the available verbosity level filters of the logger.

StateEvent

The enum holding the different types of event that can be received in a State in the handle_event method.

StdoutLog

An enum that contains options for logging to the terminal.

Trans

Types of state transitions. T is the type of shared data between states. E is the type of events

Traits

DataDispose

Allow disposing game data with access to world.

DataInit

Initialise trait for game data

EmptyState

An empty State trait. It contains no StateData or custom StateEvent.

SimpleState

A simple State trait. It contains GameData as its StateData and no custom StateEvent.

State

A trait which defines game states that can be used by the state machine.

Functions

start_logger

Starts a basic logger outputting to stdout with color on supported platforms, and/or to file.

Type Definitions

Application

An Application is the root object of the game engine. It binds the OS event loop, state machines, timers and other core components in a central place.

Callback

The type of a callback. This is meant to be created from within asynchonous functions (Future for example). See CallbackQueue for more details.

EmptyTrans

An empty Trans. Made to be used with EmptyState.

Result

Convenience alias for use in main functions that uses Amethyst.

SimpleTrans

A simple default Trans. Made to be used with SimpleState. By default it contains a GameData as its StateData and doesn't have a custom event type.

TransEvent

Event queue to trigger state Trans from other places than a State's methods.