From f71816ed3162b6c8e94b788061792dbd3d7fadce Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Thu, 8 Jul 2021 00:16:41 -0400 Subject: [PATCH] Minor tweaks to Pong and Dodge the Creeps --- 2d/dodge_the_creeps/Main.gd | 4 ++-- 2d/dodge_the_creeps/Mob.gd | 8 -------- 2d/dodge_the_creeps/README.md | 2 ++ 2d/pong/README.md | 2 ++ 2d/pong/logic/ball.gd | 2 +- 3d/voxel/settings.gd | 2 +- mono/dodge_the_creeps/Main.cs | 4 ++-- mono/dodge_the_creeps/Mob.cs | 12 ------------ mono/dodge_the_creeps/README.md | 2 ++ mono/pong/README.md | 2 ++ networking/webrtc_minimal/chat.gd | 8 ++++---- networking/webrtc_minimal/main.gd | 4 ++-- 12 files changed, 20 insertions(+), 32 deletions(-) diff --git a/2d/dodge_the_creeps/Main.gd b/2d/dodge_the_creeps/Main.gd index 12a273bd..65917fc1 100644 --- a/2d/dodge_the_creeps/Main.gd +++ b/2d/dodge_the_creeps/Main.gd @@ -44,8 +44,8 @@ func _on_MobTimer_timeout(): direction += rand_range(-PI / 4, PI / 4) mob.rotation = direction - # Choose the velocity. - var velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0) + # Choose the velocity for the mob. + var velocity = Vector2(rand_range(150.0, 250.0), 0.0) mob.linear_velocity = velocity.rotated(direction) diff --git a/2d/dodge_the_creeps/Mob.gd b/2d/dodge_the_creeps/Mob.gd index 8aa1e84c..56e9be6a 100644 --- a/2d/dodge_the_creeps/Mob.gd +++ b/2d/dodge_the_creeps/Mob.gd @@ -1,9 +1,5 @@ extends RigidBody2D -#warning-ignore-all:unused_class_variable -export var min_speed = 150 -export var max_speed = 250 - func _ready(): $AnimatedSprite.playing = true var mob_types = $AnimatedSprite.frames.get_animation_names() @@ -12,7 +8,3 @@ func _ready(): func _on_VisibilityNotifier2D_screen_exited(): queue_free() - - -func _on_start_game(): - queue_free() diff --git a/2d/dodge_the_creeps/README.md b/2d/dodge_the_creeps/README.md index c6fbeafb..ae8c96d9 100644 --- a/2d/dodge_the_creeps/README.md +++ b/2d/dodge_the_creeps/README.md @@ -14,6 +14,8 @@ Renderer: GLES 3 (particles are not available in GLES 2) Note: There is a C# version available [here](https://github.com/godotengine/godot-demo-projects/tree/master/mono/dodge_the_creeps). +Note: There is a GDNative C++ version available [here](https://github.com/godotengine/gdnative-demos/tree/master/cpp/dodge_the_creeps). + Check out this demo on the asset library: https://godotengine.org/asset-library/asset/515 ## Screenshots diff --git a/2d/pong/README.md b/2d/pong/README.md index 075924d7..dbcd509e 100644 --- a/2d/pong/README.md +++ b/2d/pong/README.md @@ -12,6 +12,8 @@ Note: There is a C# version available [here](https://github.com/godotengine/godo Note: There is a VisualScript version available [here](https://github.com/godotengine/godot-demo-projects/tree/master/visual_script/pong). +Note: There is a GDNative C++ version available [here](https://github.com/godotengine/gdnative-demos/tree/master/cpp/pong). + Check out this demo on the asset library: https://godotengine.org/asset-library/asset/121 ## How does it work? diff --git a/2d/pong/logic/ball.gd b/2d/pong/logic/ball.gd index 71d53e6b..f087e239 100644 --- a/2d/pong/logic/ball.gd +++ b/2d/pong/logic/ball.gd @@ -2,10 +2,10 @@ extends Area2D const DEFAULT_SPEED = 100 +var _speed = DEFAULT_SPEED var direction = Vector2.LEFT onready var _initial_pos = position -onready var _speed = DEFAULT_SPEED func _process(delta): _speed += delta * 2 diff --git a/3d/voxel/settings.gd b/3d/voxel/settings.gd index 404a7e74..cc6a9b95 100644 --- a/3d/voxel/settings.gd +++ b/3d/voxel/settings.gd @@ -12,7 +12,7 @@ var _loaded = false func _enter_tree(): if Settings._loaded: printerr("Error: Settings is an AutoLoad singleton and it shouldn't be instanced elsewhere.") - printerr("Please delete the instance at: " + get_path()) + printerr("Please delete the instance at: " + String(get_path())) else: Settings._loaded = true diff --git a/mono/dodge_the_creeps/Main.cs b/mono/dodge_the_creeps/Main.cs index 8a468872..a05d2af0 100644 --- a/mono/dodge_the_creeps/Main.cs +++ b/mono/dodge_the_creeps/Main.cs @@ -83,8 +83,8 @@ public class Main : Node direction += (float)GD.RandRange(-Mathf.Pi / 4, Mathf.Pi / 4); mob.Rotation = direction; - // Choose the velocity. - var velocity = new Vector2((float)GD.RandRange(mob.minSpeed, mob.maxSpeed), 0); + // Choose the velocity for the mob. + var velocity = new Vector2((float)GD.RandRange(150.0, 250.0), 0); mob.LinearVelocity = velocity.Rotated(direction); } } diff --git a/mono/dodge_the_creeps/Mob.cs b/mono/dodge_the_creeps/Mob.cs index d56ca749..ee83d167 100644 --- a/mono/dodge_the_creeps/Mob.cs +++ b/mono/dodge_the_creeps/Mob.cs @@ -1,14 +1,7 @@ using Godot; -using System; public class Mob : RigidBody2D { - [Export] - public int minSpeed; - - [Export] - public int maxSpeed; - public override void _Ready() { var animSprite = GetNode("AnimatedSprite"); @@ -21,9 +14,4 @@ public class Mob : RigidBody2D { QueueFree(); } - - public void OnStartGame() - { - QueueFree(); - } } diff --git a/mono/dodge_the_creeps/README.md b/mono/dodge_the_creeps/README.md index 36a52382..4709feaa 100644 --- a/mono/dodge_the_creeps/README.md +++ b/mono/dodge_the_creeps/README.md @@ -14,6 +14,8 @@ Renderer: GLES 3 (particles are not available in GLES 2) Note: There is a GDScript version available [here](https://github.com/godotengine/godot-demo-projects/tree/master/2d/dodge_the_creeps). +Note: There is a GDNative C++ version available [here](https://github.com/godotengine/gdnative-demos/tree/master/cpp/dodge_the_creeps). + Check out this demo on the asset library: https://godotengine.org/asset-library/asset/534 ## Screenshots diff --git a/mono/pong/README.md b/mono/pong/README.md index 87378436..63655beb 100644 --- a/mono/pong/README.md +++ b/mono/pong/README.md @@ -12,6 +12,8 @@ Note: There is a GDScript version available [here](https://github.com/godotengin Note: There is a VisualScript version available [here](https://github.com/godotengine/godot-demo-projects/tree/master/visual_script/pong). +Note: There is a GDNative C++ version available [here](https://github.com/godotengine/gdnative-demos/tree/master/cpp/pong). + Check out this demo on the asset library: https://godotengine.org/asset-library/asset/535 ## How does it work? diff --git a/networking/webrtc_minimal/chat.gd b/networking/webrtc_minimal/chat.gd index 8e6da42a..26c6fa26 100644 --- a/networking/webrtc_minimal/chat.gd +++ b/networking/webrtc_minimal/chat.gd @@ -12,17 +12,17 @@ func _ready(): peer.connect("session_description_created", self, "_on_session") # Register to the local signaling server (see below for the implementation). - Signaling.register(get_path()) + Signaling.register(String(get_path())) func _on_ice_candidate(mid, index, sdp): # Send the ICE candidate to the other peer via signaling server. - Signaling.send_candidate(get_path(), mid, index, sdp) + Signaling.send_candidate(String(get_path()), mid, index, sdp) func _on_session(type, sdp): # Send the session to other peer via signaling server. - Signaling.send_session(get_path(), type, sdp) + Signaling.send_session(String(get_path()), type, sdp) # Set generated description as local. peer.set_local_description(type, sdp) @@ -32,7 +32,7 @@ func _process(delta): peer.poll() if channel.get_ready_state() == WebRTCDataChannel.STATE_OPEN: while channel.get_available_packet_count() > 0: - print(get_path(), " received: ", channel.get_packet().get_string_from_utf8()) + print(String(get_path()), " received: ", channel.get_packet().get_string_from_utf8()) func send_message(message): diff --git a/networking/webrtc_minimal/main.gd b/networking/webrtc_minimal/main.gd index e86b17a7..cfb706d1 100644 --- a/networking/webrtc_minimal/main.gd +++ b/networking/webrtc_minimal/main.gd @@ -10,8 +10,8 @@ func _ready(): # Wait a second and send message from P1 yield(get_tree().create_timer(1), "timeout") - p1.send_message("Hi from %s" % p1.get_path()) + p1.send_message("Hi from %s" % String(p1.get_path())) # Wait a second and send message from P2 yield(get_tree().create_timer(1), "timeout") - p2.send_message("Hi from %s" % p2.get_path()) + p2.send_message("Hi from %s" % String(p2.get_path()))