let text_ref = text.as_ref();
unsafe { extern_text(text_ref.as_ptr(), text_ref.len(), x, y) }
}
+pub fn custom_text<T: AsRef<[u8]>>(text: T, len: usize, x: i32, y: i32) {
+ let text_ref = text.as_ref();
+ unsafe { extern_text(text_ref.as_ptr(), len, x, y) }
+}
extern "C" {
#[link_name = "textUtf8"]
fn extern_text(text: *const u8, length: usize, x: i32, y: i32);
use crate::sprites::*;
use tinyrand::{Rand, StdRand};
+use crate::helpers::round_f32_to_i32;
const CAR_ANIM_FRAMES: u8 = 10;
const MOVE_RATE: f32 = 1f32;
-const MULTIPLIER_INC_RATE: f32 = 0.04f32;
-const HOUSE_FRAMES: u32 = 180;
+const MULTIPLIER_INC_RATE: f32 = 0.07f32;
+const HOUSE_FRAMES: u32 = 150;
const HOUSE_RANGE: f32 = 90f32;
pub struct World {
score: u64,
rate_multiplier: f32,
status_text: Option<(&'static str, u32)>,
+ str_buf: [u8; 16],
}
impl World {
score: 0,
rate_multiplier: 1f32,
status_text: None,
+ str_buf: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
}
}
crate::rect(-5, 120, 170, 5);
- let mut x = -5 + self.street_offset.round() as i32;
+ let mut x = -5 + round_f32_to_i32(self.street_offset);
while x < 170 {
crate::rect(x, 140, 30, 5);
x += 45;
if let Some((x, y)) = shrub {
crate::blit(
&PLANT,
- x.round() as i32,
- y.round() as i32,
+ round_f32_to_i32(*x),
+ round_f32_to_i32(*y),
PLANT_WIDTH,
PLANT_HEIGHT,
PLANT_FLAGS,
match state {
0 => crate::blit(
&HOUSE1,
- x.round() as i32,
+ round_f32_to_i32(x),
30 + HOUSE0_HEIGHT as i32 - HOUSE1_HEIGHT as i32,
HOUSE1_WIDTH,
HOUSE1_HEIGHT,
),
1 => crate::blit(
&HOUSE0,
- x.round() as i32,
+ round_f32_to_i32(x),
30,
HOUSE0_WIDTH,
HOUSE0_HEIGHT,
if width == 0 {
width = 1;
}
- crate::text(format!("{}", self.score), 160 - width * 7, 0);
+ temp = self.score;
+ if width < 15 {
+ for i in 0..width {
+ self.str_buf[width - 1 - i] = '0' as u8 + (temp % 10) as u8;
+ temp /= 10;
+ }
+ for i in width..16 {
+ self.str_buf[i] = 0;
+ }
+ crate::custom_text(self.str_buf, width, 160 - width as i32 * 8, 0);
+ } else {
+ crate::text("9999999999", 160 - 10 * 8, 0);
+ }
}
}