117 lines
3.0 KiB
Rust

use crate::content;
use cgmath::{Deg, Point2, Point3, Vector2};
/// Instructions to create a new particle
pub struct ParticleBuilder {
/// The sprite to use for this particle
pub sprite: content::SpriteHandle,
/// This object's center, in world coordinates.
pub pos: Point2<f32>,
/// This particle's velocity, in world coordinates
pub velocity: Vector2<f32>,
/// This particle's angle, in world coordinates
pub angle: Deg<f32>,
/// This particle's lifetime, in seconds
pub lifetime: f32,
/// The size of this particle,
/// given as height in world units.
pub size: f32,
}
/// The location of a UI element, in one of a few
/// possible coordinate systems.
///
/// Positive Y always points up,
/// positive X always points right.
#[derive(Debug, Clone)]
pub enum AnchoredUiPosition {
/// Position of this sprite's center,
/// relative to the nw corner of the window.
NwC(Point2<f32>),
/// Position of this sprite's nw corner,
/// relative to the nw corner of the window.
NwNw(Point2<f32>),
/// Position of this sprite's ne corner,
/// relative to the nw corner of the window.
NwNe(Point2<f32>),
/// Position of this sprite's sw corner,
/// relative to the nw corner of the window.
NwSw(Point2<f32>),
/// Position of this sprite's se corner,
/// relative to the nw corner of the window.
NwSe(Point2<f32>),
}
/// A sprite that represents a ui element
#[derive(Debug, Clone)]
pub struct UiSprite {
/// The sprite to draw
pub sprite: content::SpriteHandle,
/// This object's position, in logical (dpi-adjusted) pixels
pub pos: AnchoredUiPosition,
/// This sprite's color will be multiplied by this value.
/// If this is None, color will not be changed.
pub color: Option<[f32; 4]>,
/// The size of this sprite, in logical (dpi-adjusted) pixels
pub dimensions: Point2<f32>,
/// This sprite's rotation, measured ccw
pub angle: Deg<f32>,
}
/// A sprite that represents a world object:
/// Ships, planets, debris, etc
#[derive(Debug, Clone)]
pub struct ObjectSprite {
/// The sprite to draw
pub sprite: content::SpriteHandle,
/// This object's center, in world coordinates.
pub pos: Point3<f32>,
/// The size of this sprite,
/// given as height in world units.
pub size: f32,
/// This sprite's rotation
/// (relative to north, measured ccw)
/// Note that this is different from the angle used by our physics system.
pub angle: Deg<f32>,
/// Sprites that should be drawn relative to this sprite.
pub children: Option<Vec<ObjectSubSprite>>,
}
/// A sprite that is drawn relative to an ObjectSprite.
#[derive(Debug, Clone)]
pub struct ObjectSubSprite {
/// The sprite to draw
pub sprite: content::SpriteHandle,
/// This object's position, in world coordinates.
/// This is relative to this sprite's parent.
pub pos: Point3<f32>,
/// The size of this sprite,
/// given as height in world units.
pub size: f32,
/// This sprite's rotation
/// (relative to north, measured ccw)
/// Just as position, this is relative to this
/// subsprite's parent sprite.
pub angle: Deg<f32>,
}