Add MovingPlatformComponent and moving platform scene; implement movement along a path with customizable speed and loop modes
This commit is contained in:
@@ -123,12 +123,12 @@ bus = &"sfx"
|
||||
script = ExtResource("6_q78ru")
|
||||
Area = NodePath("../Hitbox")
|
||||
|
||||
[node name="PeriodicShootingComponent" type="Node" parent="." node_paths=PackedStringArray("BulletSpawnRight", "BulletSpawnLeft")]
|
||||
[node name="PeriodicShootingComponent" type="Node" parent="." node_paths=PackedStringArray("BulletSpawnPointRight", "BulletSpawnPointLeft")]
|
||||
script = ExtResource("7_weo6b")
|
||||
BulletScene = ExtResource("7_4ajjm")
|
||||
ShootInterval = 2.0
|
||||
BulletSpawnRight = NodePath("../laser spawn point right")
|
||||
BulletSpawnLeft = NodePath("../laser spawn point left")
|
||||
BulletSpawnPointRight = NodePath("../laser spawn point right")
|
||||
BulletSpawnPointLeft = NodePath("../laser spawn point left")
|
||||
ShootingIntervalVariation = 0.5
|
||||
|
||||
[node name="EnemyDeathComponent" type="Node" parent="." node_paths=PackedStringArray("CollisionShape", "Health")]
|
||||
|
40
objects/level/moving_platform.tscn
Normal file
40
objects/level/moving_platform.tscn
Normal file
@@ -0,0 +1,40 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dt6rnh7v6dcmd"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://g4ryqvpelmvl" path="res://scripts/components/MovingPlatformComponent.cs" id="1_hd47u"]
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="2_6wunj"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1avbh"]
|
||||
size = Vector2(48, 4)
|
||||
|
||||
[node name="MovingPlatformComponent" type="AnimatableBody2D"]
|
||||
script = ExtResource("1_hd47u")
|
||||
metadata/_custom_type_script = "uid://g4ryqvpelmvl"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_1avbh")
|
||||
|
||||
[node name="Gfx" type="Node2D" parent="."]
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Gfx"]
|
||||
position = Vector2(-16, 6)
|
||||
texture = ExtResource("2_6wunj")
|
||||
hframes = 12
|
||||
vframes = 12
|
||||
frame = 81
|
||||
|
||||
[node name="Sprite2D2" type="Sprite2D" parent="Gfx"]
|
||||
position = Vector2(0, 6)
|
||||
texture = ExtResource("2_6wunj")
|
||||
hframes = 12
|
||||
vframes = 12
|
||||
frame = 82
|
||||
|
||||
[node name="Sprite2D3" type="Sprite2D" parent="Gfx"]
|
||||
position = Vector2(16, 6)
|
||||
texture = ExtResource("2_6wunj")
|
||||
hframes = 12
|
||||
vframes = 12
|
||||
frame = 83
|
||||
|
||||
[node name="VisibleOnScreenEnabler2D" type="VisibleOnScreenEnabler2D" parent="."]
|
||||
scale = Vector2(1, 0.2)
|
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=23 format=4 uid="uid://bbwef3n2gjkt8"]
|
||||
[gd_scene load_steps=25 format=4 uid="uid://bbwef3n2gjkt8"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bqi5s710xb1ju" path="res://objects/entities/brick_player.tscn" id="1_cchob"]
|
||||
[ext_resource type="PackedScene" uid="uid://cawlpch2lk3a2" path="res://objects/level/world_environment.tscn" id="2_yd68a"]
|
||||
@@ -14,6 +14,7 @@
|
||||
[ext_resource type="TileSet" uid="uid://bbppo0irxdmqy" path="res://resources/tilesets/village/foreground.tres" id="11_osyc3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bqom4cm7r18db" path="res://objects/entities/killzone.tscn" id="12_m6e8x"]
|
||||
[ext_resource type="PackedScene" uid="uid://bwdlmualj6xbw" path="res://objects/entities/enemy.tscn" id="14_qxp43"]
|
||||
[ext_resource type="PackedScene" uid="uid://dt6rnh7v6dcmd" path="res://objects/level/moving_platform.tscn" id="15_1jx8o"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_qxp43"]
|
||||
script = ExtResource("3_ggm0n")
|
||||
@@ -60,6 +61,12 @@ color_ramp = SubResource("GradientTexture1D_f1fvy")
|
||||
[sub_resource type="OccluderPolygon2D" id="OccluderPolygon2D_qxp43"]
|
||||
polygon = PackedVector2Array(-214, -1594, 571, -1596, 571, 321, -220, 317)
|
||||
|
||||
[sub_resource type="Curve2D" id="Curve2D_8fwqm"]
|
||||
_data = {
|
||||
"points": PackedVector2Array(0, 0, 0, 0, 256, -436, 0, 0, 0, 0, 0, -436, 0, 0, 0, 0, 0, -665, 0, 0, 0, 0, 358, -665, 0, 0, 0, 0, 362, -899, 0, 0, 0, 0, 0, -898, 0, 0, 0, 0, -1, -1159, 0, 0, 0, 0, 260, -1159)
|
||||
}
|
||||
point_count = 8
|
||||
|
||||
[node name="World" type="Node2D"]
|
||||
|
||||
[node name="WorldEnvironment" parent="." instance=ExtResource("2_yd68a")]
|
||||
@@ -102,7 +109,6 @@ position = Vector2(32, -16)
|
||||
script = ExtResource("6_qm38r")
|
||||
follow_mode = 5
|
||||
follow_target = NodePath("../Brick Player")
|
||||
snap_to_pixel = true
|
||||
tween_resource = SubResource("Resource_0nwt7")
|
||||
follow_offset = Vector2(32, -16)
|
||||
follow_damping = true
|
||||
@@ -123,7 +129,7 @@ tile_map_data = PackedByteArray("AAAjABMAAQAEAAMAAAAjABIAAQAEAAIAAAAjABEAAQAEAAI
|
||||
tile_set = ExtResource("9_tmn5u")
|
||||
|
||||
[node name="Entities layer" type="TileMapLayer" parent="."]
|
||||
tile_map_data = PackedByteArray("AAANAAEAAQAAAAAADAAWAPP/AQAAAAAADAAYAAIAAQAAAAAADQA=")
|
||||
tile_map_data = PackedByteArray("AAANAAEAAQAAAAAADAAWAPP/AQAAAAAADAAYAAIAAQAAAAAADQD4/wIAAQAAAAAADQD1/wEAAQAAAAAAAQD0/wEAAQAAAAAAAQDz/wEAAQAAAAAAAQDz/wAAAQAAAAAAAQD0/wAAAQAAAAAAAQD1/wAAAQAAAAAAAQD1////AQAAAAAAAQD0////AQAAAAAAAQDz////AQAAAAAAAQAdAAEAAQAAAAAAAQAeAAEAAQAAAAAAAQAfAAEAAQAAAAAAAQAfAAAAAQAAAAAAAQAeAAAAAQAAAAAAAQAdAAAAAQAAAAAAAQAdAP//AQAAAAAAAQAeAP//AQAAAAAAAQAfAP//AQAAAAAAAQAMANP/AQAAAAAACgALANP/AQAAAAAACgAKANP/AQAAAAAACgAJANP/AQAAAAAACgAIANP/AQAAAAAACgAHANP/AQAAAAAACgAKANH/AQAAAAAAAwA=")
|
||||
tile_set = ExtResource("10_yka2u")
|
||||
|
||||
[node name="Foreground layer" type="TileMapLayer" parent="."]
|
||||
@@ -149,6 +155,14 @@ occluder = SubResource("OccluderPolygon2D_qxp43")
|
||||
visible = false
|
||||
polygon = PackedVector2Array(-208, 32, 561, 33, 565, 311, -216, 310)
|
||||
|
||||
[node name="MovingPlatformComponent" parent="." node_paths=PackedStringArray("Path") instance=ExtResource("15_1jx8o")]
|
||||
position = Vector2(236, -436)
|
||||
Path = NodePath("../Moving Platform Path")
|
||||
Speed = 32.0
|
||||
|
||||
[node name="Moving Platform Path" type="Path2D" parent="."]
|
||||
curve = SubResource("Curve2D_8fwqm")
|
||||
|
||||
[connection signal="Death" from="Brick Player/HealthComponent" to="UI Layer/DeathScreen" method="OnPlayerDeath"]
|
||||
[connection signal="Death" from="Brick Player/HealthComponent" to="UI Layer/GameOverScreen" method="OnPlayerDeath"]
|
||||
|
||||
|
74
scripts/components/MovingPlatformComponent.cs
Normal file
74
scripts/components/MovingPlatformComponent.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class MovingPlatformComponent : AnimatableBody2D
|
||||
{
|
||||
public enum LoopModeEnum { OneShot, Loop, PingPong }
|
||||
|
||||
[Export] public Path2D Path { get; set; }
|
||||
[Export(PropertyHint.Range, "10, 1000, 1")] public float Speed { get; set; } = 100.0f;
|
||||
[Export] public LoopModeEnum LoopMode { get; set; } = LoopModeEnum.PingPong;
|
||||
[Export(PropertyHint.Range, "0, 10, 0.1")] public float WaitTime { get; set; } = 1.0f;
|
||||
|
||||
private PathFollow2D _pathFollower;
|
||||
private Tween _tween;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Path == null)
|
||||
{
|
||||
GD.PrintErr("MovingPlatform: Path is not set. The platform will not move.");
|
||||
return;
|
||||
}
|
||||
|
||||
_pathFollower = new PathFollow2D
|
||||
{
|
||||
Loop = false,
|
||||
Rotates = false
|
||||
};
|
||||
Path.AddChild(_pathFollower);
|
||||
|
||||
StartMovement();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (_pathFollower == null) return;
|
||||
|
||||
GlobalPosition = _pathFollower.GlobalPosition;
|
||||
}
|
||||
|
||||
private void StartMovement()
|
||||
{
|
||||
_tween?.Kill();
|
||||
_tween = CreateTween();
|
||||
_tween.SetParallel(false);
|
||||
|
||||
var pathLength =Path.Curve.GetBakedLength();
|
||||
var duration = pathLength / Speed;
|
||||
|
||||
switch (LoopMode)
|
||||
{
|
||||
case LoopModeEnum.OneShot:
|
||||
_tween.TweenProperty(_pathFollower, "progress", pathLength, duration);
|
||||
break;
|
||||
|
||||
case LoopModeEnum.Loop:
|
||||
_tween.TweenProperty(_pathFollower, "progress", pathLength, duration);
|
||||
_tween.TweenInterval(WaitTime);
|
||||
_tween.TweenCallback(Callable.From(() => _pathFollower.Progress = 0));
|
||||
_tween.SetLoops();
|
||||
break;
|
||||
|
||||
case LoopModeEnum.PingPong:
|
||||
_tween.TweenProperty(_pathFollower, "progress", pathLength, duration);
|
||||
_tween.TweenInterval(WaitTime);
|
||||
_tween.TweenProperty(_pathFollower, "progress", 0, duration);
|
||||
_tween.TweenInterval(WaitTime);
|
||||
_tween.SetLoops();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
1
scripts/components/MovingPlatformComponent.cs.uid
Normal file
1
scripts/components/MovingPlatformComponent.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://g4ryqvpelmvl
|
Reference in New Issue
Block a user