Skip to content

Commit

Permalink
font
Browse files Browse the repository at this point in the history
  • Loading branch information
2bt committed Aug 13, 2023
1 parent 27a4697 commit 1d3d6e7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 42 deletions.
Binary file added assets/Copilme.ttf
Binary file not shown.
6 changes: 3 additions & 3 deletions src/bike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const WHEEL_INERTIA: f32 = 50.0;
const WHEEL_R: f32 = 8.0;
const WHEEL_X: f32 = 17.0;
const WHEEL_Y: f32 = 12.0;
const SUSPENSION: f32 = 700.0;
const SUSPENSION: f32 = 900.0;
const SUSPENSION_FRICTION: f32 = 40.0;
// const BREAK: f32 = 60000.0 * 0.5;
// const BREAK_FRICTION: f32 = 40000.0 * 0.5;
const BREAK: f32 = 0.0;
const BREAK: f32 = 0.0; // disable this for now, it feels weird
const BREAK_FRICTION: f32 = 7000.0;
const MAX_SPEED: f32 = 50.0;
const GAS: f32 = 17000.0;
const GAS: f32 = 18000.0;

pub struct Body {
pub pos: Vec2,
Expand Down
2 changes: 1 addition & 1 deletion src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Level {
for i in 1..points.len() {
let r = if i % 2 == 0 { STAR_R } else { STAR_R * 0.5 };
let ang = (i as f32) * 0.2 * PI + (self.time * 3.0).sin() * 0.8;
points[i] = star.pos + vec2(0.0, -r).rotate(Vec2::from_angle(ang));
points[i] = star.pos - Vec2::from_angle(ang) * r;
}
fx::draw_polygon(&points, c);
}
Expand Down
92 changes: 54 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl Game {
let dt = get_frame_time();
self.time += dt;


match self.state {
GameState::Playing => {
self.level.update(dt);
Expand Down Expand Up @@ -113,26 +112,27 @@ impl Game {
self.bike.draw();

// labels
let f = macroquad::text::camera_font_scale(8.0);
let x = self.level.start.x - 15.0;
let mut y = self.level.start.y + 58.0;
let mut txt = |text| {
draw_text_ex(
text,
x,
y,
TextParams {
font_size: f.0,
font_scale: f.1,
..TextParams::default()
},
);
y += 8.0;
let font_scale = macroquad::text::camera_font_scale(10.0);
let text_params = TextParams {
font: Some(&self.materials.font),
font_size: font_scale.0,
font_scale: font_scale.1,
..TextParams::default()
};
txt("[UP] - accelerate");
txt("[DOWN] - break");
txt("[SPACE] - toggle direction");
txt("[ENTER] - reset position");

{
let x = self.level.start.x - 16.0;
let mut y = self.level.start.y + 64.0;
let mut txt = |left, right| {
draw_text_ex(left, x, y, text_params.clone());
draw_text_ex(right, x + 64.0, y, text_params.clone());
y += 16.0;
};
txt("[UP] ", "accelerate");
txt("[DOWN] ", "break");
txt("[SPACE]", "toggle direction");
txt("[ENTER]", "reset position");
}

cam.target = rect.size() * 0.5;
set_camera(&cam);
Expand All @@ -144,31 +144,47 @@ impl Game {
),
6.0,
10.0,
TextParams {
font_size: f.0,
font_scale: f.1,
..TextParams::default()
},
text_params.clone(),
);

// show time
cam.target = vec2(-rect.w, rect.h) * 0.5;
set_camera(&cam);
let t = (self.physics_time * 100.0) as u32;
let str = format!(
"{:0>2}:{:0>2}:{:0>2}",
t / (100 * 60),
t / 100 % 60,
t % 100,
);
let mut x = -40.0;
// make it a bit more monospacy
for c in str.chars() {
let o = match c {
':' => 1.0,
'1' => 1.5,
_ => 0.0,
};
draw_text_ex(&c.to_string(), x + o, 10.0, text_params.clone());
x += match c {
':' => 3.0,
_ => 5.0,
};
}

if let GameState::LevelCompleted = self.state {
cam.target = Vec2::ZERO;
set_camera(&cam);
let msg = "WELL DONE!";
let f = macroquad::text::camera_font_scale(30.0);
let p = get_text_center(msg, None, f.0, f.1, 0.0);
draw_text_ex(
msg,
0.0 - p.x,
-50.0 - p.y,
TextParams {
font_size: f.0,
font_scale: f.1,
..TextParams::default()
},
);
let fs = macroquad::text::camera_font_scale(30.0);
let tp = TextParams {
font: Some(&self.materials.font),
font_size: fs.0,
font_scale: fs.1,
..TextParams::default()
};
draw_text_ex(msg, -75.0, -50.0, tp);
}

}
}

Expand Down
6 changes: 6 additions & 0 deletions src/materials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ use macroquad::prelude::*;

pub struct Materials {
pub wall_material: Material,
pub font: Font,
}

impl Materials {
pub fn load() -> Materials {

let mut font = load_ttf_font_from_bytes(include_bytes!("../assets/Copilme.ttf")).unwrap();
font.set_filter(FilterMode::Linear);

Materials {
wall_material: load_material(
ShaderSource {
Expand Down Expand Up @@ -41,6 +46,7 @@ void main() {
Default::default(),
)
.unwrap(),
font,
}
}
}
Binary file modified wasm/bike.wasm
Binary file not shown.

0 comments on commit 1d3d6e7

Please sign in to comment.