M client/src/rendering/renderer.rs => client/src/rendering/renderer.rs +20 -2
@@ 41,20 41,38 @@ impl Renderer for WebRenderer {
let camera_translate_x = -client.x + (typed_canvas_element.width() / 2) as f64;
let camera_translate_y = -client.y + (typed_canvas_element.height() / 2) as f64;
- debug!("translating to {} {}", camera_translate_x, camera_translate_y);
-
context.translate(camera_translate_x, camera_translate_y).map_err(|e: JsValue| e.as_string().unwrap())?;
for planet in &client.planets {
context.save();
+
context.set_transform(1f64, 0f64, 0f64, 1f64, 0f64, 0f64).map_err(|e: JsValue| e.as_string().unwrap())?;
context.translate(-planet.x, -planet.y).map_err(|e: JsValue| e.as_string().unwrap())?;
+
let texture_image = document.get_element_by_id(&format!("tex-{}", planet.planet_type.as_texture_id())).unwrap().dyn_into::<HtmlImageElement>().unwrap();
context.draw_image_with_html_image_element_and_dw_and_dh(&texture_image, -planet.radius, -planet.radius, planet.radius * 2f64, planet.radius * 2f64).map_err(|e: JsValue| e.as_string().unwrap())?;
+
context.restore();
}
+ for player in &client.players {
+ context.save();
+
+ context.translate(player.x, player.y).map_err(|e: JsValue| e.as_string().unwrap())?;
+ context.set_text_align("center");
+ context.set_font("30px Segoe UI");
+ context.set_fill_style(&JsValue::from_str("white"));
+
+ context.fill_text(&player.username, 0f64, -35f64).map_err(|e: JsValue| e.as_string().unwrap())?;
+
+ context.rotate(player.rotation).map_err(|e: JsValue| e.as_string().unwrap())?;
+
+ let texture_image = document.get_element_by_id("tex-hearty").unwrap().dyn_into::<HtmlImageElement>().unwrap();
+ context.draw_image_with_html_image_element_and_dw_and_dh(&texture_image, -25f64, -25f64, 50f64, 50f64).map_err(|e: JsValue| e.as_string().unwrap())?;
+
+ context.restore();
+ }
// do not remove
// im making this smiley an easter egg soon
M server/src/planet.rs => server/src/planet.rs +11 -13
@@ 39,7 39,7 @@ impl Planets {
pub fn new(rigid_body_set: &mut RigidBodySet, collider_set: &mut ColliderSet) -> Planets {
let mut planets = Vec::new();
- let _earth = Planets::make_planet(
+ Planets::make_planet(
&mut planets,
PlanetType::Earth,
2000.0,
@@ 53,21 53,19 @@ impl Planets {
}
pub fn to_protocol(&self) -> ClientHandlerMessage {
- let mut message = ClientHandlerMessage::PlanetData {
- planets: Vec::new()
- };
+ let mut planets = vec![];
for planet in self.planets.clone() {
- if let ClientHandlerMessage::PlanetData { mut planets } = message.clone() {
- planets.push(ProtocolPlanet {
- planet_type: planet.planet_type,
- x: planet.position.0 * SCALE,
- y: planet.position.1 * SCALE,
- radius: planet.radius,
- });
- }
+ planets.push(ProtocolPlanet {
+ planet_type: planet.planet_type,
+ x: planet.position.0 * SCALE,
+ y: planet.position.1 * SCALE,
+ radius: planet.radius,
+ });
}
- message
+ ClientHandlerMessage::PlanetData {
+ planets
+ }
}
}