From fcf6f8d9e77eadc5a90d144379c8fc7a5cca4040 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Thu, 4 Jan 2024 21:08:36 -0600 Subject: [PATCH] red planet and red planet with hubs --- server/src/component.rs | 1 + server/src/main.rs | 21 ++++++++++++++++++++- starkingdoms-client/src/protocol.ts | 1 + starkingdoms-client/src/textures.ts | 3 +++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/server/src/component.rs b/server/src/component.rs index 9e7568c252f13200cd309651fec7e1915bc94fb8..6980baf18edbb84e0324b4a4b81e2c525947522d 100644 --- a/server/src/component.rs +++ b/server/src/component.rs @@ -22,6 +22,7 @@ use serde::{Deserialize, Serialize}; pub enum PlanetType { Earth, Moon, + Mars, } #[derive(Component, Clone, Copy, PartialEq, Serialize, Deserialize, Debug)] diff --git a/server/src/main.rs b/server/src/main.rs index 98080b8b5261ea225e83b5f5a9aeeaff30a67fde..bcc5b8feb54ec410c9c3b996819c2e022e4bc5a0 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -35,9 +35,11 @@ const SCALE: f32 = 10.0; const EARTH_SIZE: f32 = 1000.0; const MOON_SIZE: f32 = EARTH_SIZE / 4.; +const MARS_SIZE: f32 = EARTH_SIZE / 2.; const EARTH_MASS: f32 = 10000.0; const MOON_MASS: f32 = EARTH_MASS / 30.; +const MARS_MASS: f32 = EARTH_MASS / 8.; const GRAVITY: f32 = 0.02; const PART_HALF_SIZE: f32 = 25.0; @@ -117,6 +119,21 @@ fn spawn_planets(mut commands: Commands) { .insert(Sensor); }) .insert(RigidBody::Fixed); + let mars_pos = Transform::from_xyz(-3000.0 / SCALE, 0.0, 0.0); + commands + .spawn(PlanetBundle { + planet_type: PlanetType::Mars, + transform: TransformBundle::from(mars_pos), + }) + .insert(Collider::ball(MARS_SIZE / SCALE)) + .insert(AdditionalMassProperties::Mass(MARS_MASS)) + .insert(ReadMassProperties::default()) + .with_children(|children| { + children.spawn(Collider::ball((MARS_SIZE + 3.) / SCALE)) + .insert(ActiveEvents::COLLISION_EVENTS) + .insert(Sensor); + }) + .insert(RigidBody::Fixed); } fn module_spawn( mut commands: Commands, @@ -259,6 +276,7 @@ fn on_message( radius: match *planet_type { PlanetType::Earth => EARTH_SIZE, PlanetType::Moon => MOON_SIZE, + PlanetType::Mars => MARS_SIZE }, }, )); @@ -859,7 +877,7 @@ fn convert_modules_recursive( let (mut part_type, attach, children) = attached_query.get_mut(child).unwrap(); if *part_type == PartType::Cargo { match planet_type { - PlanetType::Moon => { + PlanetType::Mars => { *part_type = PartType::Hub; let (mut collider, mut transform, _) = collider_query.get_mut(*children.first().unwrap()).unwrap(); *collider = Collider::cuboid(PART_HALF_SIZE / SCALE, PART_HALF_SIZE / SCALE); @@ -998,6 +1016,7 @@ fn on_position_change( radius: match *planet_type { PlanetType::Earth => EARTH_SIZE, PlanetType::Moon => MOON_SIZE, + PlanetType::Mars => MARS_SIZE, }, }, )); diff --git a/starkingdoms-client/src/protocol.ts b/starkingdoms-client/src/protocol.ts index 13edcbd47dc9673769ecde672d1fd0a17d867b2c..1f0a7861398a0fe120a72f96fcaa16045e9dc0e6 100644 --- a/starkingdoms-client/src/protocol.ts +++ b/starkingdoms-client/src/protocol.ts @@ -6,6 +6,7 @@ export interface ProtoTransform { export enum PlanetType { Earth = "Earth", Moon = "Moon", + Mars = "Mars", } export enum PartType { Hearty = "Hearty", diff --git a/starkingdoms-client/src/textures.ts b/starkingdoms-client/src/textures.ts index bd70afec2898249155976cbb10eb5ef87d5d4931..a796dc9009f0275a91610659100cb056af0b6afb 100644 --- a/starkingdoms-client/src/textures.ts +++ b/starkingdoms-client/src/textures.ts @@ -1,6 +1,7 @@ import { PartType, PlanetType } from "./protocol.ts"; import tex_earth from "./assets/earth.svg"; import tex_moon from "./assets/moon.svg"; +import tex_mars from "./assets/mars.svg"; import tex_hearty from "./assets/hearty.svg"; import tex_cargo_off from "./assets/cargo_off.svg"; import tex_hub_off from "./assets/hub_off.svg"; @@ -11,6 +12,8 @@ export function planet_texture_url(type: PlanetType): string { return tex_earth; } else if (type == PlanetType.Moon) { return tex_moon; + } else if (type == PlanetType.Mars) { + return tex_mars; } return tex_missing; }