Struct rusty_sword_arena::game::PlayerState [−][src]
pub struct PlayerState { pub id: u8, pub name: String, pub color: Color, pub pos: Vector2, pub direction: f32, pub radius: f32, pub velocity: Vector2, pub health: f32, pub weapon: Weapon, pub player_events: Vec<PlayerEvent>, pub drop_timer: Timer, pub respawn_timer: Timer, pub dead: bool, // some fields omitted }
The state of a player on the server. The server broadcasts these to all clients every frame as
part of a FrameState. Note that you can receive PlayerState
s before you have gotten a
corresponding GameSetting telling you their name and color!
Fields
id: u8
The ID of the player
name: String
The name of the player
color: Color
The color of the player
pos: Vector2
The position of the player in OpenGL units.
direction: f32
The direction the player is facing, in radians
radius: f32
Your player occupies a circle of this radius, in OpenGL units.
velocity: Vector2
Current velocity of the player
health: f32
Current health of the player [0.0, 100.0]
weapon: Weapon
Current weapon of the player
player_events: Vec<PlayerEvent>
Any player events that have occurred to the player this frame
drop_timer: Timer
How long the server will wait to get input from you before disconnecting you
respawn_timer: Timer
How long until the player respawns. If respawn_timer.ready == false, then the player is dead and you should seriously consider indicating that visually somehow, even if only by not displaying the player.
dead: bool
Are you dead? Untangling health/respawn_timer dynamics is a pain, so we'll use this much more convenient boolean.
Methods
impl PlayerState
[src]
impl PlayerState
Represents the state of the player on the server for the current frame. Always delivered by the
server to the client inside a GameState. The server always
creates PlayeState
s, updates them, and sends them to the client each frame. The client is free
to modify its local copy (for example, to remove PlayerEvents it
has processed) -- a new set of PlayerStates
will be delivered the next frame. Clients
typically look at the fields and events, and don't use any of the methods.
pub fn new(
game_setting: &GameSetting,
id: u8,
name: String,
color: Color,
pos: Vector2,
radius: f32
) -> Self
[src]
pub fn new(
game_setting: &GameSetting,
id: u8,
name: String,
color: Color,
pos: Vector2,
radius: f32
) -> Self
The client should never create a PlayerState
-- the server will do that.
pub fn update(&mut self, delta: Duration)
[src]
pub fn update(&mut self, delta: Duration)
Clients never need to call update. The server calls it each time it processes some amount of time.
pub fn new_frame(&mut self)
[src]
pub fn new_frame(&mut self)
Used by the server to reset things that have been taken care of last frame.
pub fn die(&mut self, msg: &str)
[src]
pub fn die(&mut self, msg: &str)
Used by the server when a player needs to die
pub fn respawn(&mut self, pos: Vector2, msg: &str)
[src]
pub fn respawn(&mut self, pos: Vector2, msg: &str)
Used by the server when a player needs to spawn
Trait Implementations
impl Clone for PlayerState
[src]
impl Clone for PlayerState
fn clone(&self) -> PlayerState
[src]
fn clone(&self) -> PlayerState
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for PlayerState
[src]
impl Debug for PlayerState
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for PlayerState
[src]
impl PartialEq for PlayerState
fn eq(&self, other: &PlayerState) -> bool
[src]
fn eq(&self, other: &PlayerState) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &PlayerState) -> bool
[src]
fn ne(&self, other: &PlayerState) -> bool
This method tests for !=
.
Auto Trait Implementations
impl Send for PlayerState
impl Send for PlayerState
impl Sync for PlayerState
impl Sync for PlayerState