diff --git a/globals.gd b/globals.gd new file mode 100644 index 0000000..faa8cc1 --- /dev/null +++ b/globals.gd @@ -0,0 +1,3 @@ +extends Node + +var multiplayer_type=0 \ No newline at end of file diff --git a/globals.gd.uid b/globals.gd.uid new file mode 100644 index 0000000..99d4706 --- /dev/null +++ b/globals.gd.uid @@ -0,0 +1 @@ +uid://b8o32xf6kknhu diff --git a/lobby.gd b/lobby.gd index cd3d8d3..9ef0a4b 100644 --- a/lobby.gd +++ b/lobby.gd @@ -25,7 +25,7 @@ func start(id,given_name): func add_player(pid): players[pid]={} var a - if multiplayer.get_unique_id()==1: + if Globals.multiplayer_type&1: # hosting a=PLAYER_SCENE.instantiate() a.name=str(pid) $fuck_layouts/player_list.add_child(a) @@ -50,6 +50,7 @@ func _on_send_message_pressed(message=""): @rpc("any_peer","call_local") func receive_message(pid,message): + if !Globals.multiplayer_type&2: return # displaying var a=Label.new() a.text=str(pid)+": "+message var scroll=$fuck_layouts/menu_shiz/chats/elder @@ -75,7 +76,7 @@ func _start_clicked(): @rpc("any_peer","call_local") func gamestart(players): - emit_signal('game_start',players) + emit_signal('game_start',players,Globals.multiplayer_type) hide() func _idk_clicked(): diff --git a/menu.gd b/menu.gd index 6bea11f..ab03d69 100644 --- a/menu.gd +++ b/menu.gd @@ -14,9 +14,11 @@ func _ready(): if DisplayServer.get_name() == "headless": # Should attempt to pull port from config file print("Automatically starting dedicated server.") - _on_host_pressed.call_deferred(true) + _on_host_pressed.call_deferred() + else: + Globals.multiplayer_type|=2 # displaying -func _on_host_pressed(headless=false): +func _on_host_pressed(): # Start as server. var peer = ENetMultiplayerPeer.new() var port = $Net/Options/port.text @@ -25,8 +27,9 @@ func _on_host_pressed(headless=false): if peer.get_connection_status() == MultiplayerPeer.CONNECTION_DISCONNECTED: OS.alert("Failed to start multiplayer server.") return + Globals.multiplayer_type|=1 # hosting multiplayer.multiplayer_peer = peer - start_game(headless) + start_game() func _on_join_pressed(): # Start as client. @@ -44,7 +47,7 @@ func _on_join_pressed(): multiplayer.multiplayer_peer = peer start_game() # Can't run a headless client lol what are you trying to bot the game -func start_game(headless=false): - if headless: return +func start_game(): + if !Globals.multiplayer_type&2: return # displaying emit_signal("lobby_join",multiplayer.get_unique_id(),$Net/pname/Name.text) hide() diff --git a/project.godot b/project.godot index c271f9f..5c55919 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="res://ui.tscn" config/features=PackedStringArray("4.4", "GL Compatibility") config/icon="res://icon.svg" +[autoload] + +Globals="*res://globals.gd" + [dotnet] project/assembly_name="net-test" diff --git a/src/game.cpp b/src/game.cpp index 8512783..7317346 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -19,10 +19,11 @@ Game::Game() } Game::~Game(){} -void Game::start(const Dictionary &players) +void Game::start(const Dictionary &players, const int p_multiplayer_type) { - show(); - if (get_multiplayer()->get_unique_id()!=1) return; + multiplayer_type=p_multiplayer_type; + if (multiplayer_type&2) show(); // displaying + if (!(multiplayer_type&1)) return; // hosting Array keys=players.keys(); for (int i=0; iset_name(dat["name"]); kya->multiplayerowner=dat["pid"]; kya->set_position(Vector2(50,50)); - kya->set_texture(ImageTexture::create_from_image(Image::load_from_file("res://icon.svg"))); + if (multiplayer_type&2) kya->set_texture(ResourceLoader::get_singleton()->load("res://icon.svg")); // displaying return kya; } \ No newline at end of file diff --git a/src/game.h b/src/game.h index 163d7de..f701f5f 100644 --- a/src/game.h +++ b/src/game.h @@ -6,8 +6,7 @@ #include "kyara.h" #include #include -#include -#include +#include namespace godot { @@ -15,13 +14,14 @@ class Game : public Node2D { GDCLASS(Game, Node2D) private: + int multiplayer_type; MultiplayerSpawner *spawn; protected: static void _bind_methods(); public: Game(); ~Game(); - void start(const Dictionary &players); + void start(const Dictionary &players, const int p_multiplayer_type); Node* kyaraspawn(const Variant &data); }; } diff --git a/src/kyara.cpp b/src/kyara.cpp index 7b6e270..3cd0927 100644 --- a/src/kyara.cpp +++ b/src/kyara.cpp @@ -23,6 +23,7 @@ Character::Character() set_motion_mode(MOTION_MODE_FLOATING); speed=1.0; balance_radius=64.0; + balance_radius_cur=8.0; face=memnew(Sprite2D); face->set_name("_face"); add_child(face,false,INTERNAL_MODE_BACK); @@ -42,10 +43,9 @@ Character::~Character(){} void Character::_process(double delta) { // これも嫌い - if (input->flags&1) move(0.0,-speed); - if (input->flags&2) move(0.0,speed); - if (input->flags&4) move(-speed,0.0); - if (input->flags&8) move(speed,0.0); + balance_radius_cur-=3.0; + balance_radius_cur=godot::Math::max(balance_radius_cur,8.0); + move(input->flags); look_at(input->target); // Not sure if I should do this. Issues could occur if I'm wrong either side. //CharacterBody2D::_process(delta); @@ -65,9 +65,15 @@ void Character::_enter_tree() input->set_multiplayer_authority(multiplayerowner); } -void Character::move(double x,double y) +void Character::move(int flags) { - // Collision detection needs to go in here, as well as adjusting and displaying balance radius, buncha shit + if (!flags) return; + // Collision detection needs to go in here, buncha shit + balance_radius_cur+=6.0; + balance_radius_cur=godot::Math::min(balance_radius_cur,balance_radius); + double x=speed*(((flags&8)>>3)-((flags&4)>>2)); + double y=speed*(((flags&2)>>1)-((flags&1)>>0)); + // Very C set_position(get_position()+Vector2(x,y)); } diff --git a/src/kyara.h b/src/kyara.h index a344544..c975be4 100644 --- a/src/kyara.h +++ b/src/kyara.h @@ -21,7 +21,8 @@ class Character : public CharacterBody2D private: double speed; double balance_radius; - void move(double x,double y); + double balance_radius_cur; + void move(int flags); Sprite2D *face; Controller *input; MultiplayerSynchronizer *sync; diff --git a/src/nodespawner.cpp b/src/nodespawner.cpp.no similarity index 100% rename from src/nodespawner.cpp rename to src/nodespawner.cpp.no diff --git a/src/nodespawner.h b/src/nodespawner.h.no similarity index 100% rename from src/nodespawner.h rename to src/nodespawner.h.no diff --git a/src/register_types.cpp b/src/register_types.cpp index 9efd291..51b8bf4 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -2,7 +2,7 @@ #include "kyara.h" #include "controller.h" #include "game.h" -#include "nodespawner.h" +//#include "nodespawner.h" #include #include #include @@ -15,7 +15,7 @@ void initialize_character_module(ModuleInitializationLevel p_level) GDREGISTER_RUNTIME_CLASS(Character); GDREGISTER_RUNTIME_CLASS(Controller); GDREGISTER_RUNTIME_CLASS(Game); - GDREGISTER_RUNTIME_CLASS(NodeSpawner); +// GDREGISTER_RUNTIME_CLASS(NodeSpawner); } void uninitialize_character_module(ModuleInitializationLevel p_level) { diff --git a/ui.tscn b/ui.tscn index f8089a0..3a40c6c 100644 --- a/ui.tscn +++ b/ui.tscn @@ -139,6 +139,7 @@ _spawnable_scenes = PackedStringArray("uid://b25q27admm4le") spawn_path = NodePath("..") [node name="Game" type="Game" parent="."] +visible = false [connection signal="lobby_join" from="main_menu" to="Lobby" method="start"] [connection signal="pressed" from="main_menu/Net/buttons/Host" to="main_menu" method="_on_host_pressed"]