Commit 0988fe2e authored by Astro's avatar Astro
Browse files

l0dable, rkanoid: update display coordinate types everywhere else

parent d2bca3b8
Pipeline #4120 passed with stage
in 9 minutes and 27 seconds
......@@ -86,10 +86,10 @@ pub enum Font {
/// Immediate mode routines
impl Display {
pub const W: u16 = 160;
pub const H: u16 = 80;
pub const FONT_W: u16 = 14;
pub const FONT_H: u16 = 20;
pub const W: i16 = 160;
pub const H: i16 = 80;
pub const FONT_W: i16 = 14;
pub const FONT_H: i16 = 20;
/// Open the display, return an instance
pub fn open() -> Self {
......
......@@ -61,16 +61,16 @@ impl<'d> FrameBuffer<'d> {
impl<'d> Index<(u16, u16)> for FrameBuffer<'d> {
type Output = RawColor;
fn index(&self, (x, y): (u16, u16)) -> &Self::Output {
let x = usize::from(Display::W - 1 - x);
let y = usize::from(Display::H - 1 - y);
let x = usize::from(Display::W as u16 - 1 - x);
let y = usize::from(Display::H as u16 - 1 - y);
unsafe { transmute(&self.buffer.fb[y][x]) }
}
}
impl<'d> IndexMut<(u16, u16)> for FrameBuffer<'d> {
fn index_mut(&mut self, (x, y): (u16, u16)) -> &mut Self::Output {
let x = usize::from(Display::W - 1 - x);
let y = usize::from(Display::H - 1 - y);
let x = usize::from(Display::W as u16 - 1 - x);
let y = usize::from(Display::H as u16 - 1 - y);
unsafe { transmute(&mut self.buffer.fb[y][x]) }
}
}
......@@ -85,7 +85,7 @@ impl<'d, C: PixelColor + Into<RawColor>> Drawing<C> for FrameBuffer<'d> {
let x = coord[0] as u16;
let y = coord[1] as u16;
if x >= Display::W || y >= Display::H {
if x >= Display::W as u16 || y >= Display::H as u16 {
continue;
}
// Swap bytes
......
......@@ -24,10 +24,10 @@ impl<'a, 'd, 'f> Write for TextRenderer<'a, 'd, 'f> {
Some(glyph) => {
for y in 0..self.font.h {
let y1 = (self.y + y as isize) as u16;
if y1 < Display::H {
if y1 < Display::H as u16 {
for x in 0..self.font.w {
let x1 = (self.x + x as isize) as u16;
if x1 < Display::W {
if x1 < Display::W as u16 {
if glyph.get_pixel(x as usize, y as usize) {
self.framebuffer[(x1, y1)] = self.color;
}
......
......@@ -184,7 +184,7 @@ fn game(level: u16, mut score: u32) -> GameResult {
let mut blocks = Blocks::generate((0x3F + 0x10 * level).min(0xff) as u8);
// Clear screen
draw_rect(&mut fb, 0, 0, Display::W - 1, Display::H - 1, RawColor::black());
draw_rect(&mut fb, 0, 0, Display::W as u16 - 1, Display::H as u16 - 1, RawColor::black());
// Draw Blocks
for (lineno, line) in blocks.blocks.iter_mut().enumerate() {
let lineno = lineno as u32;
......@@ -299,11 +299,11 @@ fn game(level: u16, mut score: u32) -> GameResult {
}
// Space below blocks
draw_rect(&mut fb, 0, (BLOCK_H * BLOCKS_Y) as u16,
Display::W, Display::H, RawColor::black());
Display::W as u16, Display::H as u16, RawColor::black());
// Paddle
draw_rect(&mut fb,
(paddle - paddle_size) as u16, Display::H - PADDLE_HEIGHT as u16,
(paddle + paddle_size) as u16, Display::H - 1,
(paddle - paddle_size) as u16, Display::H as u16 - PADDLE_HEIGHT as u16,
(paddle + paddle_size) as u16, Display::H as u16 - 1,
RawColor::rgb8(0x7f, 0xff, 0x7f));
// Ball
fb.draw(
......@@ -412,10 +412,10 @@ fn main() {
}
fn draw_rect(fb: &mut FrameBuffer, x1: u16, y1: u16, x2: u16, y2: u16, color: RawColor) {
let x1 = x1.max(0).min(Display::W - 1);
let x2 = x2.max(0).min(Display::W - 1);
let y1 = y1.max(0).min(Display::H - 1);
let y2 = y2.max(0).min(Display::H - 1);
let x1 = x1.max(0).min(Display::W as u16 - 1);
let x2 = x2.max(0).min(Display::W as u16 - 1);
let y1 = y1.max(0).min(Display::H as u16 - 1);
let y2 = y2.max(0).min(Display::H as u16 - 1);
for y in y1..=y2 {
for x in x1..=x2 {
fb[(x, y)] = color;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment