Compare commits
No commits in common. "a75ca14eadd3b5e5d8e990975fb0afcbf57cb8ce" and "3784aa3e08fddd522b73238432c8ece9c9f5db47" have entirely different histories.
a75ca14ead
...
3784aa3e08
|
@ -585,7 +585,6 @@ dependencies = [
|
|||
"galactica-gameobject",
|
||||
"galactica-render",
|
||||
"galactica-shipbehavior",
|
||||
"galactica-ui",
|
||||
"galactica-world",
|
||||
"image",
|
||||
"nalgebra",
|
||||
|
@ -651,16 +650,6 @@ dependencies = [
|
|||
"galactica-world",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "galactica-ui"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cgmath",
|
||||
"galactica-content",
|
||||
"galactica-render",
|
||||
"galactica-world",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "galactica-world"
|
||||
version = "0.0.0"
|
||||
|
|
|
@ -35,7 +35,6 @@ members = [
|
|||
"crates/world",
|
||||
"crates/shipbehavior",
|
||||
"crates/gameobject",
|
||||
"crates/ui",
|
||||
]
|
||||
|
||||
|
||||
|
@ -47,7 +46,6 @@ galactica-constants = { path = "crates/constants" }
|
|||
galactica-world = { path = "crates/world" }
|
||||
galactica-shipbehavior = { path = "crates/shipbehavior" }
|
||||
galactica-gameobject = { path = "crates/gameobject" }
|
||||
galactica-ui = { path = "crates/ui" }
|
||||
|
||||
# Files
|
||||
image = { version = "0.24", features = ["png"] }
|
||||
|
|
|
@ -30,11 +30,6 @@ impl Ship {
|
|||
}
|
||||
}
|
||||
|
||||
/// Has this ship been destroyed?
|
||||
pub fn is_destroyed(&self) -> bool {
|
||||
self.hull <= 0.0
|
||||
}
|
||||
|
||||
pub fn handle_projectile_collision(&mut self, ct: &content::Content, p: &Projectile) -> bool {
|
||||
let f = ct.get_faction(self.faction);
|
||||
let r = f.relationships.get(&p.faction).unwrap();
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
[package]
|
||||
name = "galactica-ui"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
galactica-content = { path = "../content" }
|
||||
galactica-world = { path = "../world" }
|
||||
galactica-render = { path = "../render" }
|
||||
cgmath = "0.18.0"
|
|
@ -1,3 +0,0 @@
|
|||
mod radar;
|
||||
|
||||
pub use radar::build_radar;
|
|
@ -1,51 +0,0 @@
|
|||
use cgmath::{Deg, InnerSpace, Point2};
|
||||
use galactica_content as content;
|
||||
use galactica_render::{AnchoredUiPosition, UiSprite};
|
||||
use galactica_world::{util, ShipPhysicsHandle, World};
|
||||
|
||||
pub fn build_radar(
|
||||
player: &ShipPhysicsHandle,
|
||||
physics: &World,
|
||||
ct: &content::Content,
|
||||
) -> Vec<UiSprite> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
let radar_range = 2000.0;
|
||||
let radar_size = 300.0;
|
||||
|
||||
out.push(UiSprite {
|
||||
texture: ct.get_texture_handle("ui::radar"),
|
||||
pos: AnchoredUiPosition::NorthWest(Point2 { x: 10.0, y: -10.0 }),
|
||||
dimensions: Point2 {
|
||||
x: radar_size,
|
||||
y: radar_size,
|
||||
},
|
||||
angle: Deg(0.0),
|
||||
});
|
||||
|
||||
let (_, pr) = physics.get_ship_body(player).unwrap();
|
||||
let pr = util::rigidbody_position(pr);
|
||||
for (s, r) in physics.iter_ship_body() {
|
||||
if s.physics_handle == *player {
|
||||
continue;
|
||||
}
|
||||
let r = util::rigidbody_position(r);
|
||||
let d = r - pr;
|
||||
let m = d.magnitude() / radar_range;
|
||||
if m < 0.8 {
|
||||
out.push(UiSprite {
|
||||
texture: ct.get_texture_handle("ui::blip"),
|
||||
pos: AnchoredUiPosition::NorthWest(
|
||||
Point2 {
|
||||
x: radar_size / 2.0 + 10.0,
|
||||
y: radar_size / -2.0 - 10.0,
|
||||
} + (d / radar_range * 150.0),
|
||||
),
|
||||
dimensions: Point2 { x: 1.0, y: 1.0 } * 5.0f32.min((0.8 - m) * 50.0),
|
||||
angle: Deg(0.0),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
|
@ -49,8 +49,8 @@ impl ShipWorldObject {
|
|||
}
|
||||
}
|
||||
|
||||
/// Step this ship's state by t seconds
|
||||
pub fn step(&mut self, r: &mut RigidBody, t: f32) {
|
||||
/// Apply the effects of all active controls
|
||||
pub fn tick(&mut self, r: &mut RigidBody, t: f32) {
|
||||
let ship_rot = util::rigidbody_rotation(r);
|
||||
let engine_force = ship_rot * t;
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ impl<'a> World {
|
|||
}
|
||||
|
||||
/// Add a ship to this physics system
|
||||
/// TODO: decouple from Ship::new()
|
||||
pub fn add_ship(
|
||||
&mut self,
|
||||
ct: &content::Content,
|
||||
|
@ -148,7 +149,6 @@ impl<'a> World {
|
|||
// (Collider starts pointing east, sprite starts pointing north.)
|
||||
.rotation(PI / -2.0)
|
||||
.mass(ship_content.mass);
|
||||
// TODO: only build colliders once
|
||||
|
||||
let rb = RigidBodyBuilder::dynamic()
|
||||
.angular_damping(ship_content.angular_drag)
|
||||
|
@ -171,25 +171,26 @@ impl<'a> World {
|
|||
/// Step this physics system by `t` seconds
|
||||
pub fn step(&mut self, t: f32, ct: &content::Content) {
|
||||
// Run ship updates
|
||||
// TODO: maybe reorganize projectile creation?
|
||||
let mut projectiles = Vec::new();
|
||||
// TODO: Clean this mess
|
||||
let mut ps = Vec::new();
|
||||
let mut to_remove = Vec::new();
|
||||
for (_, s) in &mut self.ships {
|
||||
if s.ship.is_destroyed() {
|
||||
if s.ship.hull <= 0.0 {
|
||||
to_remove.push(s.physics_handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
let r = &mut self.wrapper.rigid_body_set[s.physics_handle.0];
|
||||
s.step(r, t);
|
||||
s.tick(r, t);
|
||||
if s.controls.guns {
|
||||
projectiles.push((s.physics_handle, s.ship.fire_guns()));
|
||||
ps.push((s.physics_handle, s.ship.fire_guns()));
|
||||
}
|
||||
}
|
||||
let _ = projectiles
|
||||
.into_iter()
|
||||
.map(|(s, p)| self.add_projectiles(&s, p));
|
||||
let _ = to_remove.into_iter().map(|s| self.remove_ship(s));
|
||||
for r in to_remove {
|
||||
self.remove_ship(r);
|
||||
}
|
||||
for (s, p) in ps {
|
||||
self.add_projectiles(&s, p);
|
||||
}
|
||||
|
||||
// Update physics
|
||||
self.wrapper.step(t, &self.collision_handler);
|
||||
|
|
|
@ -1,17 +1,72 @@
|
|||
use cgmath::Point2;
|
||||
use cgmath::{Deg, InnerSpace, Point2};
|
||||
use content::SystemHandle;
|
||||
use std::time::Instant;
|
||||
use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
|
||||
|
||||
use crate::camera::Camera;
|
||||
use super::camera::Camera;
|
||||
use crate::{content, inputstatus::InputStatus};
|
||||
use galactica_constants;
|
||||
use galactica_gameobject as object;
|
||||
use galactica_render::{ObjectSprite, UiSprite};
|
||||
use galactica_render::{AnchoredUiPosition, ObjectSprite, UiSprite};
|
||||
use galactica_shipbehavior::{behavior, ShipBehavior};
|
||||
use galactica_ui as ui;
|
||||
use galactica_world::{util, ShipPhysicsHandle, World};
|
||||
|
||||
struct Ui {}
|
||||
|
||||
impl Ui {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn build_radar(
|
||||
&self,
|
||||
player: &ShipPhysicsHandle,
|
||||
physics: &World,
|
||||
ct: &content::Content,
|
||||
) -> Vec<UiSprite> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
let radar_range = 2000.0;
|
||||
let radar_size = 300.0;
|
||||
|
||||
out.push(UiSprite {
|
||||
texture: ct.get_texture_handle("ui::radar"),
|
||||
pos: AnchoredUiPosition::NorthWest(Point2 { x: 10.0, y: -10.0 }),
|
||||
dimensions: Point2 {
|
||||
x: radar_size,
|
||||
y: radar_size,
|
||||
},
|
||||
angle: Deg(0.0),
|
||||
});
|
||||
|
||||
let (_, pr) = physics.get_ship_body(player).unwrap();
|
||||
let pr = util::rigidbody_position(pr);
|
||||
for (s, r) in physics.iter_ship_body() {
|
||||
if s.physics_handle == *player {
|
||||
continue;
|
||||
}
|
||||
let r = util::rigidbody_position(r);
|
||||
let d = r - pr;
|
||||
let m = d.magnitude() / radar_range;
|
||||
if m < 0.8 {
|
||||
out.push(UiSprite {
|
||||
texture: ct.get_texture_handle("ui::blip"),
|
||||
pos: AnchoredUiPosition::NorthWest(
|
||||
Point2 {
|
||||
x: radar_size / 2.0 + 10.0,
|
||||
y: radar_size / -2.0 - 10.0,
|
||||
} + (d / radar_range * 150.0),
|
||||
),
|
||||
dimensions: Point2 { x: 1.0, y: 1.0 } * 5.0f32.min((0.8 - m) * 50.0),
|
||||
angle: Deg(0.0),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Game {
|
||||
pub input: InputStatus,
|
||||
pub last_update: Instant,
|
||||
|
@ -21,6 +76,7 @@ pub struct Game {
|
|||
paused: bool,
|
||||
pub time_scale: f32,
|
||||
|
||||
ui: Ui,
|
||||
physics: World,
|
||||
shipbehaviors: Vec<Box<dyn ShipBehavior>>,
|
||||
playerbehavior: behavior::Player,
|
||||
|
@ -95,6 +151,7 @@ impl Game {
|
|||
shipbehaviors,
|
||||
content: ct,
|
||||
playerbehavior: behavior::Player::new(h1),
|
||||
ui: Ui::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +236,8 @@ impl Game {
|
|||
}
|
||||
|
||||
pub fn get_ui_sprites(&self) -> Vec<UiSprite> {
|
||||
return ui::build_radar(&self.player, &self.physics, &self.content);
|
||||
return self
|
||||
.ui
|
||||
.build_radar(&self.player, &self.physics, &self.content);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
//! This module is responsible for high-level game control logic.
|
||||
|
||||
mod camera;
|
||||
mod game;
|
||||
|
||||
pub use game::Game;
|
|
@ -1,4 +1,3 @@
|
|||
mod camera;
|
||||
mod game;
|
||||
mod inputstatus;
|
||||
|
||||
|
|
Loading…
Reference in New Issue