// StarKingdoms.IO, a browser game about drifting through space // Copyright (C) 2023 ghostly_zsh, TerraMaster85, core // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . use std::net::Ipv4Addr; use crate::mathutil::rot2d; use bevy::log::Level; use bevy::log::LogPlugin; use bevy::math::{vec2, vec3}; use bevy::{ecs::event::ManualEventReader, prelude::*}; use bevy_rapier2d::prelude::*; use bevy_twite::{twite::frame::MessageType, ServerEvent, TwiteServerConfig, TwiteServerPlugin}; use component::*; use packet::*; use rand::Rng; pub mod component; pub mod macros; pub mod mathutil; pub mod packet; const SCALE: f32 = 10.0; const EARTH_SIZE: f32 = 1000.0; const GRAVITY: f32 = 0.02; const PART_HALF_SIZE: f32 = 25.0; const THRUSTER_FORCE: f32 = 0.08; fn main() { App::new() .insert_resource(TwiteServerConfig { addr: Ipv4Addr::new(0, 0, 0, 0), port: 3000, }) .add_plugins(MinimalPlugins) .add_plugins(LogPlugin { level: Level::DEBUG, filter: "wgpu=error,bevy_render=info,bevy_ecs=trace".to_string(), }) .insert_resource(RapierConfiguration { gravity: Vect { x: 0.0, y: 0.0 }, ..Default::default() }) .init_resource::() .add_plugins(RapierPhysicsPlugin::::pixels_per_meter(SCALE)) .add_plugins(TwiteServerPlugin) .add_systems(Startup, setup_integration_parameters) .add_systems(Startup, spawn_planets) .add_systems(FixedUpdate, module_spawn) .add_systems(Update, on_message) .add_systems(Update, on_close) .add_systems(FixedUpdate, on_position_change) .add_systems(FixedUpdate, gravity_update) .add_systems(FixedUpdate, player_input_update) //.insert_resource(Time::::from_seconds(1.0/20.0)) .run(); info!("Goodbye!"); } fn setup_integration_parameters(mut context: ResMut) { context.integration_parameters.dt = 1.0 / 60.0; context.integration_parameters.joint_erp = 0.2; context.integration_parameters.erp = 0.5; context.integration_parameters.max_stabilization_iterations = 16; } fn spawn_planets(mut commands: Commands) { info!("Spawning planets"); let earth_pos = Transform::from_xyz(0.0, 0.0, 0.0); commands .spawn(PlanetBundle { planet_type: PlanetType::Earth, transform: TransformBundle::from(earth_pos), }) .insert(Collider::ball(EARTH_SIZE / SCALE)) .insert(AdditionalMassProperties::Mass(10000.0)) .insert(ReadMassProperties::default()) .insert(RigidBody::Fixed); } fn module_spawn(mut commands: Commands, time: Res