1use core::cmp::Ordering;
2
3const FLAG_BGWIN_PRIO: u8 = 0b10000000;
4const FLAG_Y_FLIP: u8 = 0b01000000;
5const FLAG_X_FLIP: u8 = 0b00100000;
6const FLAG_PALETTE_NUMBER: u8 = 0b00010000;
7
8#[derive(Clone, Copy, Eq)]
9pub struct Sprite {
10 pub x: u8,
12 pub y: u8,
14 pub tile_index: u8,
16 attrs: u8,
18}
19
20impl Sprite {
21 pub fn new(x: u8, y: u8, tile_index: u8, attrs: u8) -> Self {
22 Self { x, y, tile_index, attrs }
23 }
24
25 pub fn default() -> Self {
26 Self { x: 0, y: 0, tile_index: 0, attrs: 0 }
27 }
28
29 #[inline]
30 pub fn is_x_flipped(&self) -> bool {
31 is_set!(self.attrs, FLAG_X_FLIP)
32 }
33
34 #[inline]
35 pub fn is_y_flipped(&self) -> bool {
36 is_set!(self.attrs, FLAG_Y_FLIP)
37 }
38
39 #[inline]
40 pub fn is_bgwin_prio(&self) -> bool {
41 is_set!(self.attrs, FLAG_BGWIN_PRIO)
42 }
43
44 #[inline]
45 pub fn palette_number(&self) -> u8 {
46 is_set!(self.attrs, FLAG_PALETTE_NUMBER) as u8
47 }
48}
49
50impl Ord for Sprite {
51 fn cmp(&self, other: &Self) -> Ordering {
52 self.x.cmp(&other.x)
53 }
54}
55
56impl PartialOrd for Sprite {
57 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
58 Some(self.cmp(other))
59 }
60}
61
62impl PartialEq for Sprite {
63 fn eq(&self, other: &Self) -> bool {
64 self.x == other.x
65 }
66}