about summary refs log tree commit diff
path: root/src/entities/character.rs
blob: f436608ea5e744725f62f1cd0b9e65c02bac2ef8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use proptest_derive::Arbitrary;
use std::io::{self, Write};
use termion::cursor;

use crate::display;
use crate::types::{Position, Speed};

const DEFAULT_SPEED: Speed = Speed(100);

#[derive(Debug, PartialEq, Eq, Arbitrary)]
pub struct Character {
    /// The position of the character, relative to the game
    pub position: Position,
}

impl Character {
    pub fn new() -> Character {
        Character {
            position: Position { x: 0, y: 0 },
        }
    }

    pub fn speed(&self) -> Speed {
        Speed(100)
    }
}

positioned!(Character);

impl display::Draw for Character {
    fn do_draw<W: Write>(&self, out: &mut W) -> io::Result<()> {
        write!(
            out,
            "@{}",
            cursor::Left(1),
        )
    }
}