Renamed structs

master
Mark 2023-12-25 16:21:14 -08:00
parent 17aa76ac61
commit e6a45a16a4
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
7 changed files with 22 additions and 21 deletions

View File

@ -43,15 +43,15 @@ impl Game {
let t: Pfloat = self.last_update.elapsed().as_secs_f32(); let t: Pfloat = self.last_update.elapsed().as_secs_f32();
if self.input.key_thrust { if self.input.key_thrust {
self.player.body.thrust(50.0 * t); self.player.physicsbody.thrust(50.0 * t);
} }
if self.input.key_right { if self.input.key_right {
self.player.body.rot(Deg(35.0) * t); self.player.physicsbody.rot(Deg(35.0) * t);
} }
if self.input.key_left { if self.input.key_left {
self.player.body.rot(Deg(-35.0) * t); self.player.physicsbody.rot(Deg(-35.0) * t);
} }
if self.input.v_scroll != 0.0 { if self.input.v_scroll != 0.0 {
@ -60,8 +60,8 @@ impl Game {
self.input.v_scroll = 0.0; self.input.v_scroll = 0.0;
} }
self.player.body.tick(t); self.player.physicsbody.tick(t);
self.camera.pos = self.player.body.pos; self.camera.pos = self.player.physicsbody.pos;
self.last_update = Instant::now(); self.last_update = Instant::now();
} }

View File

@ -1,13 +1,13 @@
mod camera; mod camera;
mod doodad;
mod game; mod game;
mod inputstatus; mod inputstatus;
mod ship; mod ship;
mod system; mod system;
mod systemobject;
pub use camera::Camera; pub use camera::Camera;
pub use doodad::Doodad;
pub use game::Game; pub use game::Game;
pub use inputstatus::InputStatus; pub use inputstatus::InputStatus;
pub use ship::Ship; pub use ship::Ship;
pub use system::System; pub use system::System;
pub use systemobject::SystemObject;

View File

@ -1,7 +1,8 @@
use cgmath::Point2; use cgmath::Point2;
use crate::{ use crate::{
physics::Pfloat, physics::PhysBody, render::Sprite, render::SpriteTexture, render::Spriteable, physics::Pfloat, physics::PhysicsBody, render::Sprite, render::SpriteTexture,
render::Spriteable,
}; };
pub enum ShipKind { pub enum ShipKind {
@ -25,14 +26,14 @@ impl ShipKind {
} }
pub struct Ship { pub struct Ship {
pub body: PhysBody, pub physicsbody: PhysicsBody,
kind: ShipKind, kind: ShipKind,
} }
impl Ship { impl Ship {
pub fn new(kind: ShipKind, pos: Point2<Pfloat>) -> Self { pub fn new(kind: ShipKind, pos: Point2<Pfloat>) -> Self {
Ship { Ship {
body: PhysBody::new(pos), physicsbody: PhysicsBody::new(pos),
kind, kind,
} }
} }
@ -41,9 +42,9 @@ impl Ship {
impl Spriteable for Ship { impl Spriteable for Ship {
fn get_sprite(&self) -> Sprite { fn get_sprite(&self) -> Sprite {
return Sprite { return Sprite {
pos: (self.body.pos.x, self.body.pos.y, 1.0).into(), pos: (self.physicsbody.pos.x, self.physicsbody.pos.y, 1.0).into(),
texture: self.kind.sprite(), texture: self.kind.sprite(),
angle: self.body.angle, angle: self.physicsbody.angle,
scale: 1.0, scale: 1.0,
size: self.kind.size(), size: self.kind.size(),
}; };

View File

@ -1,7 +1,7 @@
use cgmath::{Point3, Vector2}; use cgmath::{Point3, Vector2};
use rand::{self, Rng}; use rand::{self, Rng};
use super::Doodad; use super::SystemObject;
use crate::{ use crate::{
consts, content, physics::Pfloat, render::Sprite, render::SpriteTexture, render::Spriteable, consts, content, physics::Pfloat, render::Sprite, render::SpriteTexture, render::Spriteable,
}; };
@ -22,7 +22,7 @@ pub struct StarfieldStar {
pub struct System { pub struct System {
pub name: String, pub name: String,
bodies: Vec<Doodad>, bodies: Vec<SystemObject>,
pub starfield: Vec<StarfieldStar>, pub starfield: Vec<StarfieldStar>,
} }
@ -50,7 +50,7 @@ impl System {
}; };
for o in &ct.objects { for o in &ct.objects {
s.bodies.push(Doodad { s.bodies.push(SystemObject {
pos: o.position, pos: o.position,
sprite: SpriteTexture(o.sprite.to_owned()), sprite: SpriteTexture(o.sprite.to_owned()),
size: o.size, size: o.size,

View File

@ -2,14 +2,14 @@ use cgmath::{Deg, Point3};
use crate::{physics::Pfloat, render::Sprite, render::SpriteTexture, render::Spriteable}; use crate::{physics::Pfloat, render::Sprite, render::SpriteTexture, render::Spriteable};
pub struct Doodad { pub struct SystemObject {
pub sprite: SpriteTexture, pub sprite: SpriteTexture,
pub pos: Point3<Pfloat>, pub pos: Point3<Pfloat>,
pub size: Pfloat, pub size: Pfloat,
pub angle: Deg<Pfloat>, pub angle: Deg<Pfloat>,
} }
impl Spriteable for Doodad { impl Spriteable for SystemObject {
fn get_sprite(&self) -> Sprite { fn get_sprite(&self) -> Sprite {
return Sprite { return Sprite {
texture: self.sprite.clone(), texture: self.sprite.clone(),

View File

@ -1,16 +1,16 @@
use super::Pfloat; use super::Pfloat;
use cgmath::{Angle, Deg, Point2, Vector2}; use cgmath::{Angle, Deg, Point2, Vector2};
pub struct PhysBody { pub struct PhysicsBody {
pub pos: Point2<Pfloat>, pub pos: Point2<Pfloat>,
pub vel: Vector2<Pfloat>, pub vel: Vector2<Pfloat>,
pub mass: Pfloat, pub mass: Pfloat,
pub angle: Deg<Pfloat>, pub angle: Deg<Pfloat>,
} }
impl PhysBody { impl PhysicsBody {
pub fn new(pos: Point2<Pfloat>) -> Self { pub fn new(pos: Point2<Pfloat>) -> Self {
return PhysBody { return PhysicsBody {
pos, pos,
vel: (0.0, 0.0).into(), vel: (0.0, 0.0).into(),
mass: 0.3, mass: 0.3,

View File

@ -4,5 +4,5 @@ mod polar;
// What kind of float shoud we use for physics? // What kind of float shoud we use for physics?
pub type Pfloat = f32; pub type Pfloat = f32;
pub use body::PhysBody; pub use body::PhysicsBody;
pub use polar::Polar; pub use polar::Polar;