Skip to content

Commit

Permalink
Fix errors in Physics-Based Platformer 2D demo (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex2782 authored Oct 17, 2023
1 parent 1c169ad commit 9484fbb
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 92 deletions.
32 changes: 16 additions & 16 deletions 2d/physics_platformer/background/parallax_bg.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=7 format=3 uid="uid://csdn3dwkaprow"]

[ext_resource path="res://background/scroll_bg_sky.png" type="Texture2D" id=1]
[ext_resource path="res://background/scroll_bg_cloud_1.png" type="Texture2D" id=2]
[ext_resource path="res://background/scroll_bg_cloud_2.png" type="Texture2D" id=3]
[ext_resource path="res://background/scroll_bg_cloud_3.png" type="Texture2D" id=4]
[ext_resource path="res://background/scroll_bg_fg_2.png" type="Texture2D" id=5]
[ext_resource path="res://background/scroll_bg_fg_1.png" type="Texture2D" id=6]
[ext_resource type="Texture2D" uid="uid://obtbrlptthky" path="res://background/scroll_bg_sky.png" id="1"]
[ext_resource type="Texture2D" uid="uid://udnu8aekj8mh" path="res://background/scroll_bg_cloud_1.png" id="2"]
[ext_resource type="Texture2D" uid="uid://crkm8guj5obto" path="res://background/scroll_bg_cloud_2.png" id="3"]
[ext_resource type="Texture2D" uid="uid://bb8syr2l4kbwp" path="res://background/scroll_bg_cloud_3.png" id="4"]
[ext_resource type="Texture2D" uid="uid://bitu0xunnhbjf" path="res://background/scroll_bg_fg_2.png" id="5"]
[ext_resource type="Texture2D" uid="uid://bdhblhpgjebrc" path="res://background/scroll_bg_fg_1.png" id="6"]

[node name="ParallaxBg" type="ParallaxBackground"]
scroll_base_scale = Vector2(0.7, 0)
Expand All @@ -15,7 +15,7 @@ motion_mirroring = Vector2(400, 0)

[node name="Sprite2D" type="Sprite2D" parent="Sky"]
scale = Vector2(1000, 0.94)
texture = ExtResource( 1 )
texture = ExtResource("1")
centered = false
offset = Vector2(-15, 0)

Expand All @@ -25,32 +25,32 @@ motion_mirroring = Vector2(400, 0)

[node name="Sprite1" type="Sprite2D" parent="Clouds"]
position = Vector2(14, 64)
texture = ExtResource( 2 )
texture = ExtResource("2")
centered = false

[node name="Sprite2" type="Sprite2D" parent="Clouds"]
position = Vector2(202, 12)
texture = ExtResource( 2 )
texture = ExtResource("2")
centered = false

[node name="Sprite3" type="Sprite2D" parent="Clouds"]
position = Vector2(77, 23)
texture = ExtResource( 3 )
texture = ExtResource("3")
centered = false

[node name="Sprite4" type="Sprite2D" parent="Clouds"]
position = Vector2(272, 65)
texture = ExtResource( 3 )
texture = ExtResource("3")
centered = false

[node name="Sprite5" type="Sprite2D" parent="Clouds"]
position = Vector2(127, 79)
texture = ExtResource( 4 )
texture = ExtResource("4")
centered = false

[node name="Sprite6" type="Sprite2D" parent="Clouds"]
position = Vector2(337, 35)
texture = ExtResource( 4 )
texture = ExtResource("4")
centered = false

[node name="Mount2" type="ParallaxLayer" parent="."]
Expand All @@ -59,7 +59,7 @@ motion_mirroring = Vector2(400, 0)

[node name="Sprite2D" type="Sprite2D" parent="Mount2"]
position = Vector2(0, 113)
texture = ExtResource( 5 )
texture = ExtResource("5")
centered = false
region_rect = Rect2(0, 0, 400, 128)

Expand All @@ -69,6 +69,6 @@ motion_mirroring = Vector2(400, 0)

[node name="Sprite2D" type="Sprite2D" parent="Mount1"]
position = Vector2(0, 113)
texture = ExtResource( 6 )
texture = ExtResource("6")
centered = false
region_rect = Rect2(0, 0, 400, 128)
77 changes: 40 additions & 37 deletions 2d/physics_platformer/coin/coin.tscn
Original file line number Diff line number Diff line change
@@ -1,137 +1,140 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=3 uid="uid://6uilf6rad880"]

[ext_resource path="res://coin/coin.gd" type="Script" id=1]
[ext_resource path="res://coin/coin.png" type="Texture2D" id=2]
[ext_resource path="res://audio/sound_coin.wav" type="AudioStream" id=3]
[ext_resource path="res://player/bullet.png" type="Texture2D" id=4]
[ext_resource type="Script" path="res://coin/coin.gd" id="1"]
[ext_resource type="Texture2D" uid="uid://bio1crwbvrmc2" path="res://coin/coin.png" id="2"]
[ext_resource type="AudioStream" uid="uid://cy7lxrapbqu1r" path="res://audio/sound_coin.wav" id="3"]
[ext_resource type="Texture2D" uid="uid://7sv64orewgmb" path="res://player/bullet.png" id="4"]

[sub_resource type="Animation" id=1]
[sub_resource type="Animation" id="1"]
resource_name = "spin"
length = 1.5
loop = true
loop_mode = 1
step = 0.25
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.25, 0.5, 0.75, 1, 1.25, 1.5),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 3, 2, 1, 0]
}

[sub_resource type="Animation" id=2]
[sub_resource type="Animation" id="2"]
length = 8.0
step = 0.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("GPUParticles3D:emitting")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/2/type = "method"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PackedFloat32Array(2.7),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": "queue_free"
"method": &"queue_free"
}]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("Sound:playing")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/4/type = "value"
tracks/4/imported = false
tracks/4/enabled = true
tracks/4/path = NodePath("Sprite2D:self_modulate")
tracks/4/interp = 1
tracks/4/loop_wrap = true
tracks/4/imported = false
tracks/4/enabled = true
tracks/4/keys = {
"times": PackedFloat32Array(0, 0.41),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
}

[sub_resource type="CircleShape2D" id=3]
[sub_resource type="AnimationLibrary" id="AnimationLibrary_4atuj"]
_data = {
"spin": SubResource("1"),
"taken": SubResource("2")
}

[sub_resource type="CircleShape2D" id="3"]
radius = 5.0

[sub_resource type="CanvasItemMaterial" id=4]
[sub_resource type="CanvasItemMaterial" id="4"]
blend_mode = 1

[sub_resource type="Curve" id=5]
[sub_resource type="Curve" id="5"]

[node name="Coin" type="Area2D"]
script = ExtResource( 1 )
script = ExtResource("1")

[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource( 2 )
texture = ExtResource("2")
hframes = 4

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "spin"
anims/spin = SubResource( 1 )
anims/taken = SubResource( 2 )
libraries = {
"": SubResource("AnimationLibrary_4atuj")
}

[node name="Collision" type="CollisionShape2D" parent="."]
shape = SubResource( 3 )
shape = SubResource("3")

[node name="Sound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource( 3 )
stream = ExtResource("3")

[node name="GPUParticles3D" type="CPUParticles2D" parent="."]
modulate = Color(0.596863, 0.638745, 1, 1)
material = SubResource( 4 )
material = SubResource("4")
emitting = false
one_shot = true
explosiveness = 0.7
texture = ExtResource( 4 )
texture = ExtResource("4")
emission_shape = 1
emission_sphere_radius = 20.0
gravity = Vector2(0, 0)
initial_velocity = 1.0
angular_velocity = 0.0191222
scale_amount = 0.3
scale_amount_curve = SubResource( 5 )
scale_amount_curve = SubResource("5")

[node name="Enabler" type="VisibleOnScreenEnabler2D" parent="."]
rect = Rect2(-5, -5, 10, 10)
pause_particles = false

[connection signal="body_entered" from="." to="." method="_on_body_enter"]
69 changes: 35 additions & 34 deletions 2d/physics_platformer/enemy/enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@

[sub_resource type="PhysicsMaterial" id="1"]

[sub_resource type="Animation" id="Animation_a7qal"]
resource_name = "RESET"
length = 0.01
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:self_modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}

[sub_resource type="Animation" id="2"]
length = 6.0
step = 0.0
Expand Down Expand Up @@ -99,34 +127,6 @@ tracks/0/keys = {
"values": [0, 1, 2, 3, 4, 0]
}

[sub_resource type="Animation" id="Animation_a7qal"]
resource_name = "RESET"
length = 0.01
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:self_modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_ay0tp"]
_data = {
"RESET": SubResource("Animation_a7qal"),
Expand Down Expand Up @@ -154,6 +154,13 @@ libraries = {
"": SubResource("AnimationLibrary_ay0tp")
}

[node name="SoundExplode" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("5_t2e2f")

[node name="SoundHit" type="AudioStreamPlayer2D" parent="."]
position = Vector2(0, -1)
stream = ExtResource("4_5rkwm")

[node name="VisibleOnScreenEnabler2D" type="VisibleOnScreenEnabler2D" parent="."]
rect = Rect2(-150, -100, 300, 200)

Expand Down Expand Up @@ -193,9 +200,3 @@ emission_sphere_radius = 8.0
spread = 180.0
gravity = Vector2(0, 0)
color_ramp = SubResource("6")

[node name="SoundHit" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("4_5rkwm")

[node name="SoundExplode" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("5_t2e2f")
6 changes: 3 additions & 3 deletions 2d/physics_platformer/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ config/description="This demo uses RigidDynamicBody2D for the player and enemies
character controllers are more powerful than CharacterBody2D,
but can be more difficult to handle, as they require
manual modification of the RigidDynamicBody3D velocity."
config/tags=PackedStringArray("2d", "demo", "official", "physics", "tilemap")
run/main_scene="res://stage.tscn"
config/features=PackedStringArray("4.0")
config/features=PackedStringArray("4.1")
config/icon="res://icon.webp"
config/tags=PackedStringArray("2d", "demo", "official", "physics", "tilemap")

[debug]

Expand Down Expand Up @@ -89,7 +89,7 @@ shoot={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":90,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":7,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null)
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
spawn={
Expand Down
4 changes: 2 additions & 2 deletions 2d/physics_platformer/stage.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[gd_scene load_steps=24 format=3 uid="uid://b53muvlsw1tx3"]

[ext_resource type="TileSet" uid="uid://rowrak7ls50v" path="res://tileset.tres" id="1"]
[ext_resource type="PackedScene" path="res://coin/coin.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://6uilf6rad880" path="res://coin/coin.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://dtbrdmojpvetu" path="res://platform/moving_platform.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://rxbjx7rhfd8k" path="res://background/seesaw.tscn" id="4"]
[ext_resource type="PackedScene" uid="uid://dkmxopg1dknq8" path="res://platform/one_way_platform.tscn" id="5"]
[ext_resource type="PackedScene" uid="uid://bbxsp4gp554vh" path="res://player/player.tscn" id="6_fauva"]
[ext_resource type="PackedScene" uid="uid://daqqtote00syu" path="res://enemy/enemy.tscn" id="7"]
[ext_resource type="PackedScene" path="res://background/parallax_bg.tscn" id="8"]
[ext_resource type="PackedScene" uid="uid://csdn3dwkaprow" path="res://background/parallax_bg.tscn" id="8"]
[ext_resource type="AudioStream" uid="uid://gunv00cij80t" path="res://audio/music.ogg" id="9"]

[sub_resource type="Animation" id="Animation_oxal6"]
Expand Down

0 comments on commit 9484fbb

Please sign in to comment.