Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ship sync #14

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
1a4c213
draft menu and ship builder
Bobscorn Aug 19, 2023
8a77ca8
add main menu with simple play button
Bobscorn Aug 19, 2023
89757b1
move: file
DoubleCouponDay Aug 19, 2023
062e782
refactor: systems into categories
DoubleCouponDay Aug 19, 2023
418d1e7
chore: version
DoubleCouponDay Aug 19, 2023
ef24af6
chore: readmes
DoubleCouponDay Aug 19, 2023
eda81b6
add cleanup to menu state
Bobscorn Aug 20, 2023
b7c4b23
remove unnecessary parameter
Bobscorn Aug 20, 2023
0b95234
clean old reference
Bobscorn Aug 20, 2023
e5ea08f
refac colors and setup
Bobscorn Aug 20, 2023
2cd8b38
tweak menu UI
Bobscorn Aug 20, 2023
52b8607
add ui checking system
Bobscorn Aug 20, 2023
e2e7965
add ui system to plugin
Bobscorn Aug 20, 2023
35d6048
move button colors to ui.rs
Bobscorn Aug 21, 2023
1c76ecf
change buttons to use new system
Bobscorn Aug 21, 2023
50ec924
add very simple ship builder UI
Bobscorn Aug 21, 2023
d86aadd
very important space removal
Bobscorn Aug 21, 2023
77af820
very basic ship builder ui
Bobscorn Aug 21, 2023
a600dd4
super basic text placement
Bobscorn Aug 21, 2023
3314b0d
add basic preview
Bobscorn Aug 22, 2023
adec047
add draft info
Bobscorn Aug 24, 2023
df1ff25
get ship builder scale matching
Bobscorn Aug 24, 2023
cc9b88c
very simple grid system for ship building
Bobscorn Aug 25, 2023
6a19e0c
spawn placeholder buttons
Bobscorn Aug 25, 2023
c8d2263
add destroy function
Bobscorn Aug 25, 2023
af32016
make piece buttons work
Bobscorn Aug 25, 2023
f5847b1
refactor: world
DoubleCouponDay Aug 25, 2023
1ca41d1
chore: docs
DoubleCouponDay Aug 25, 2023
191f0b7
rename: textsub
DoubleCouponDay Aug 25, 2023
fc42f07
chore: goals
DoubleCouponDay Aug 25, 2023
1264250
chore: goals
DoubleCouponDay Aug 25, 2023
a63052d
refactor: submarine terms
DoubleCouponDay Aug 25, 2023
7bf2b8e
chore: goals
DoubleCouponDay Aug 25, 2023
b96392c
refactor: sub name
DoubleCouponDay Aug 25, 2023
e5bdfba
chore: todos
DoubleCouponDay Aug 25, 2023
575c5f8
refactor: category files
DoubleCouponDay Aug 25, 2023
ce7f643
refactor: names
DoubleCouponDay Aug 25, 2023
afc3024
chore: stuff
DoubleCouponDay Aug 25, 2023
1d14078
chore: todos
DoubleCouponDay Aug 25, 2023
1304b81
refactor: dry
DoubleCouponDay Aug 25, 2023
d26fc27
fix: dupe
DoubleCouponDay Aug 25, 2023
dedc438
chore: todo
DoubleCouponDay Aug 26, 2023
f75f20f
wip: labels
DoubleCouponDay Aug 26, 2023
da68021
add subpiece instead of char
Bobscorn Aug 26, 2023
9717120
fix sub piece compile errors
Bobscorn Aug 26, 2023
38cafea
add doc links
Bobscorn Aug 26, 2023
72367dd
update todo
Bobscorn Aug 26, 2023
b9d1220
rm dead code
Bobscorn Aug 26, 2023
f5f3aba
add builder rotation
Bobscorn Aug 26, 2023
cb7b9da
fix piece rotation
Bobscorn Aug 26, 2023
293c5b6
clean imports
Bobscorn Aug 26, 2023
8d8e5de
wip descriptions and rotation
Bobscorn Aug 26, 2023
0e9f0ac
fix rotation direction
Bobscorn Aug 26, 2023
7a7dd03
remove white square in ships
Bobscorn Aug 26, 2023
ce0e50e
rm rotate goal
Bobscorn Aug 26, 2023
87a16c0
add doc link
Bobscorn Aug 26, 2023
67d3222
add feature to list
Bobscorn Aug 26, 2023
7475624
fix descriptions behind buttons
Bobscorn Aug 26, 2023
14b5636
chore: update bevy 0.11, rust 1.7
Bobscorn Aug 26, 2023
8ee8b77
big update to bevy 0.11
Bobscorn Aug 26, 2023
8ccb408
fix: out of bounds during builder left click
DoubleCouponDay Aug 26, 2023
90a76e0
chore: docs
DoubleCouponDay Aug 26, 2023
329dda6
fix: compile errors
DoubleCouponDay Aug 26, 2023
9048816
refactor: structs, parts
DoubleCouponDay Aug 26, 2023
be96903
fix: improved compilation time
DoubleCouponDay Aug 26, 2023
4a58be5
fix: compilation errors
DoubleCouponDay Aug 26, 2023
5b4c44e
draft: fixing usize overflow
DoubleCouponDay Aug 26, 2023
0e8a32a
fix: expected i32
DoubleCouponDay Aug 26, 2023
9eb9719
fix: symbol buttons not big enough
DoubleCouponDay Aug 27, 2023
193297d
fix: unaligned symbol buttons
DoubleCouponDay Aug 27, 2023
e325c6e
fix: button alignment
DoubleCouponDay Aug 27, 2023
cf54d3d
fix: component not found
DoubleCouponDay Aug 27, 2023
fa313cd
chore: use inspector again
DoubleCouponDay Aug 27, 2023
8bad3d8
fix: invisible grid
DoubleCouponDay Aug 27, 2023
7aec3f9
test: idea 1
DoubleCouponDay Aug 27, 2023
d9f0d2b
Revert "test: idea 1"
DoubleCouponDay Aug 27, 2023
b649073
fix: unaligned buttons
DoubleCouponDay Aug 27, 2023
f96d3b5
wip: adjacent detection
DoubleCouponDay Aug 27, 2023
a4eef4d
add enemy sub resource
Bobscorn Aug 27, 2023
0d31865
add sub syncing types
Bobscorn Aug 27, 2023
e095c2f
implement synchronising of enemy subs
Bobscorn Aug 27, 2023
851c5fa
chore: readme
DoubleCouponDay Mar 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Textship #
# Text Sub #

Build a spaceship out of ASCII Symbols and fight in a 2 Player deathmatch.
Build a submarine out of ASCII Symbols and fight in a multiplayer deathmatch.

## Setup Bevy to run in the browser ##

Expand Down Expand Up @@ -49,18 +49,18 @@ Build a spaceship out of ASCII Symbols and fight in a 2 Player deathmatch.

## Client: Run a development build ##

- Run the signalling server locally:
```
matchbox_server
```

- Start the wasm-server-runner:
```
cargo run --target wasm32-unknown-unknown
```

- Open a browser tab at 127.0.0.1:1334 (or whatever the port is).

- Run the signalling server locally:
```
matchbox_server
```

Multiple tabs can connect to the wasm-server-runner, which means you can run multiple clients on the same machine.

### Client: Run tests ###
Expand All @@ -77,14 +77,18 @@ wasm-pack build --release --target bundler --out-dir target/bundle

## FAQ ##

### My ships don't move when I open two tabs! ###
### My subs don't move when I open two tabs! ###

This is a known bug with the ship detection algorithm. It will work with multi windows and real 2 player scenarios.
This is a known bug with the sub detection algorithm. It will work with multi windows and real 2 player scenarios.

## Libraries ##

- rust syntax refresher: https://learnxinyminutes.com/docs/rust/

- rust book: https://doc.rust-lang.org/stable/book/

- rust api: https://doc.rust-lang.org/std/

- bevy api: https://docs.rs/bevy/latest/bevy/

- bevy unofficial book: https://bevy-cheatbook.github.io/
Expand All @@ -103,6 +107,12 @@ This is a known bug with the ship detection algorithm. It will work with multi w

- rocket api: https://api.rocket.rs/v0.5-rc/rocket/

- matchbox: https://github.com/johanhelsing/matchbox/
- bevy_ggrs api: https://docs.rs/bevy_ggrs/0.12.0/bevy_ggrs/

- bevy_matchbox api: https://docs.rs/bevy_matchbox/0.7.0/bevy_matchbox/index.html

- wasm server runner: https://github.com/jakobhellermann/wasm-server-runner

- bevy_ui api: https://docs.rs/bevy_ui/latest/bevy_ui/

- bevy_pkg: https://docs.rs/bevy_pkv/0.8.0/bevy_pkv/
18 changes: 18 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
- ship builder feature

- fix not able to draw outside the box

- fix being able to draw where parts are not connected

- spawn placement grid

- fixes feature

- direction of torpedo should rotate with ship

- change explosions into text, not sprites

- change torpedos into text, not sprites

- fix player should be in the center of the screen at all times

- send sub builds to other players
29 changes: 17 additions & 12 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
[package]
name = "textship"
name = "textsub"
version = "0.1.0"
edition = "2021"
authors = ["doublecouponday <[email protected]>", "bobscorn <[email protected]>" ]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.10.1", features = [] }
bevycheck = "0.5.2"
bevy = { version = "0.11", features = [] }
console_error_panic_hook = "0.1.7"
web-sys = { version = "0.3", features = ["console"] }
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4.37"
wee_alloc = { version = "0.4.5", optional = true } #enables smaller builds at the cost of runtime allocation time
bevy_ggrs = { version = "0.12", features = ["wasm-bindgen"] }
bevy_matchbox = { version = "0.6", features = ["ggrs"] }
bevy_asset_loader = "0.15"
bevy_ggrs = { version = "0.13", features = ["wasm-bindgen"] }
bevy_matchbox = { version = "0.7", features = ["ggrs"] }
bevy_asset_loader = "0.17"
bevy_pkv = "0.8.0"
serde = "1.0.188"
serde_json = "1.0"
bevy-inspector-egui = "0.19"

[dev-dependencies]
wasm-bindgen-test = "0.3.13"
bevy-inspector-egui = "0.18.3"

# Enable a small amount of optimization in debug mode
#dont optimise runtime performance in dev mode
[profile.dev]
opt-level = 1
opt-level = 0

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3
opt-level = 0

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

[profile.release.package."*"]
opt-level = 3

[[bin]]
name = "textship"
name = "textsub"
path = "main.rs"

[lib]
name = "textship_lib"
name = "textsub_lib"
crate-type = ["cdylib", "rlib"]
path = "lib.rs"
2 changes: 1 addition & 1 deletion client/assets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "textship"
name = "textsub"
version = "0.1.0"
edition = "2021"
authors = ["doublecouponday <[email protected]>", "bobscorn <[email protected]>" ]
Expand Down
42 changes: 39 additions & 3 deletions client/components.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
use bevy::prelude::*;
use crate::constants::*;
use crate::enums::*;
use crate::resources::*;
use crate::structs::*;

#[derive(Component)]
pub struct SymbolButton {}

#[derive(Component)]
pub struct HoverText {}

#[derive(Component)]
pub struct MyButton {
pub identifier: ButtonType
}

#[derive(Component)]
pub struct SubBuilderButton {
pub part: SubPart,
}

#[derive(Component, Reflect, Default)]
pub struct Velocity {
Expand Down Expand Up @@ -105,7 +125,7 @@ pub struct HangarDoor {
}

#[derive(Component)]
pub struct Thruster {
pub struct Propeller {

}

Expand All @@ -114,11 +134,18 @@ pub struct FighterDrone {

}

#[derive(Component, Default)]
pub struct Mothership {
#[derive(Component)]
pub struct SubsRoot {
pub parts: Vec<char>,
pub num_entities: u32
}

impl Default for SubsRoot {
fn default() -> Self {
SubsRoot { parts: Vec::new(), num_entities: 0 }
}
}

#[derive(Component)]
pub struct Player {
pub handle: usize
Expand All @@ -128,3 +155,12 @@ pub struct Player {
pub struct Lifetime {
pub lifetime: f32 // Remaining Lifetime in seconds
}

#[derive(Component)]
pub struct MainCamera;

#[derive(Component)]
pub struct MySubmarineTag;

#[derive(Component)]
pub struct UnerasablePiece;
51 changes: 35 additions & 16 deletions client/constants.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,56 @@

pub const MOTHERSHIP_SPEED: f32 = 0.25;
pub const SUB_SPEED: f32 = 0.25;
pub const ROTATION_SPEED: f32 = 0.025;

pub const MOTHERSHIP_STRUCTURE_SPACING: f32 = 15.0;
pub const SUB_STRUCTURE_SPACING: f32 = 3.5;
pub const SUB_SCALE: f32 = 0.2;
pub const SUB_MAX_WIDTH: usize = 100;
pub const SUB_MAX_HEIGHT: usize = 100;

pub const TEXT_FONT_SIZE: f32 = 30.0;
pub const EMPTY_CHAR: char = '\0';

//armour
pub const ARMOUR_LABEL: &'static str = "Hull Panel";
pub const ARMOUR_DESC: &'static str = "Submarine construction part. Suitable for pressurised environments.";

pub const SQUARE_OPEN: char = '[';
pub const SQUARE_CLOSE: char = ']';
pub const ANGLE_OPEN: char = '<';
pub const ANGLE_CLOSE: char = '>';

pub const ROUND_OPEN: char = '(';
pub const ROUND_CLOSE: char = ')';

pub const CURLY_OPEN: char = '{';
pub const CURL_CLOSE: char = '}';
pub const CURLY_CLOSE: char = '}';

pub const BACKSLASH: char = '\\';
pub const FORWARD_SLASH: char = '/';
pub const PIPE: char = '|';
pub const EQUALS: char = '=';
pub const PERCENT: char = '%';
pub const TILDE: char = '~';

pub const FULLSTOP: char = '.';
//utilities
pub static PROPELLER_LABEL: &'static str = "Propeller ";
pub static PROPELLER_DESCRIPTION: &'static str = "Used for propulsion in the watery depths.";
pub const PLUS: char = '+';
pub const MINUS: char = '-';
pub const BACKTICK: char = '`';

pub const STAR: char = '*';

pub static TORPEDO_LABEL: &'static str = "Torpedo ";
pub static TORPEDO_DESC: &'static str = "Explodey thing";
pub const EXCLAMATION: char = '!';


pub static TORPEDO_LAUNCHER_LABEL: &'static str = "Torpedo Launcher";
pub static TORPEDO_LAUNCHER_DESC: &'static str = "Throws explodey things.";
pub const EQUALS: char = '=';

pub static REACTOR_LABEL: &'static str = "Reactor ";
pub static REACTOR_DESC: &'static str = "Generates power using unholy science.";
pub const AT: char = '@';
pub const DOLLAR: char = '$';
pub const QUESTION: char = '?';
pub const APOSTROPHE: char = '\'';
pub const COLON: char = ':';

//debris
pub const TILDE: char = '~';
pub const FULLSTOP: char = '.';
pub const BUBBLE: char = 'o';

pub const TEAM_KEY: &'static str = "amogus";
pub const GAME_NAME: &'static str = "Text Sub";
pub const CACHED_KEY: &'static str = "saved_build";
75 changes: 75 additions & 0 deletions client/enums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::{default, f32::consts::PI};

use bevy::prelude::*;
use serde::{Serialize, Deserialize};

use crate::resources::Submarine;

#[derive(PartialEq)]
pub enum ButtonType {
PlayButton,
SubBuilderButton,
BackToMenuButton,
SaveButton
}

#[derive(States, Clone, Eq, PartialEq, Debug, Hash, Default)]
pub enum GameState {
#[default]
AssetLoading,
SubBuilding,
MainMenu,
MatchMaking,
SubSyncing,
InGame,
}

#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize, Reflect)]
pub enum PieceRotation {
#[default]
North,
East,
South,
West
}

impl PieceRotation {
pub fn default() -> PieceRotation {
PieceRotation::North
}

pub fn rotated_cw(&self) -> Self {
match self {
Self::North => Self::East,
Self::East => Self::South,
Self::South => Self::West,
Self::West => Self::North
}
}

pub fn rotated_ccw(&self) -> Self {
match self {
Self::North => Self::West,
Self::West => Self::South,
Self::South => Self::East,
Self::East => Self::North
}
}

pub fn rotation_radians(&self) -> f32 {
match self {
Self::North => 0.0,
Self::East => PI * 1.5,
Self::South => PI,
Self::West => PI * 0.5
}
}
}

#[derive(Serialize, Deserialize)]
pub enum SyncShipsMessageType {
SyncShip(Submarine),
SyncShipAck,
ReadyToStart,
ReadyToStartAck
}
10 changes: 2 additions & 8 deletions client/events.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use bevy::prelude::*;

#[derive(Debug)]
#[derive(Debug, Event)]
pub struct TorpedoCollisionEvent {
pub position: Vec3,
pub damage: u8,
pub radius: f32
}

#[derive(Debug)]
#[derive(Debug, Event)]
pub struct SpawnTorpedoEvent {
pub position: Vec3,
pub velocity: Vec3
}

#[derive(Resource, Default)]
pub struct FontResource {
pub font: TextStyle,
pub p1_font: TextStyle,
}
Loading
Loading