Skip to content

Commit 958f686

Browse files
committed
Update Dodge the Creeps GDScript to Godot 3.1.2
1 parent edb8372 commit 958f686

File tree

12 files changed

+103
-48
lines changed

12 files changed

+103
-48
lines changed

2d/dodge_the_creeps/Button.gd

Lines changed: 0 additions & 7 deletions
This file was deleted.

2d/dodge_the_creeps/HUD.gd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ func show_message(text):
77
$MessageLabel.show()
88
$MessageTimer.start()
99

10+
1011
func show_game_over():
1112
show_message("Game Over")
1213
yield($MessageTimer, "timeout")
@@ -15,12 +16,15 @@ func show_game_over():
1516
yield(get_tree().create_timer(1), 'timeout')
1617
$StartButton.show()
1718

19+
1820
func update_score(score):
1921
$ScoreLabel.text = str(score)
2022

23+
2124
func _on_StartButton_pressed():
2225
$StartButton.hide()
2326
emit_signal("start_game")
2427

28+
2529
func _on_MessageTimer_timeout():
26-
$MessageLabel.hide()
30+
$MessageLabel.hide()

2d/dodge_the_creeps/HUD.tscn

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]
55

66
[sub_resource type="DynamicFont" id=1]
7-
87
size = 64
98
font_data = ExtResource( 2 )
109

1110
[sub_resource type="DynamicFont" id=2]
12-
1311
size = 64
1412
font_data = ExtResource( 2 )
1513

1614
[sub_resource type="InputEventAction" id=3]
17-
1815
action = "ui_select"
1916

2017
[sub_resource type="ShortCut" id=4]
21-
2218
shortcut = SubResource( 3 )
2319

2420
[node name="HUD" type="CanvasLayer"]
@@ -57,6 +53,5 @@ text = "Start"
5753

5854
[node name="MessageTimer" type="Timer" parent="."]
5955
one_shot = true
60-
6156
[connection signal="pressed" from="StartButton" to="." method="_on_StartButton_pressed"]
6257
[connection signal="timeout" from="MessageTimer" to="." method="_on_MessageTimer_timeout"]

2d/dodge_the_creeps/Main.gd

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ var score
66
func _ready():
77
randomize()
88

9+
910
func game_over():
1011
$ScoreTimer.stop()
1112
$MobTimer.stop()
1213
$HUD.show_game_over()
1314
$Music.stop()
1415
$DeathSound.play()
1516

17+
1618
func new_game():
1719
score = 0
1820
$Player.start($StartPosition.position)
@@ -21,20 +23,23 @@ func new_game():
2123
$HUD.show_message("Get Ready")
2224
$Music.play()
2325

26+
2427
func _on_MobTimer_timeout():
2528
$MobPath/MobSpawnLocation.offset = randi()
2629
var mob = Mob.instance()
2730
add_child(mob)
28-
var direction = $MobPath/MobSpawnLocation.rotation + PI/2
31+
var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
2932
mob.position = $MobPath/MobSpawnLocation.position
30-
direction += rand_range(-PI/4, PI/4)
33+
direction += rand_range(-PI / 4, PI / 4)
3134
mob.rotation = direction
3235
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0).rotated(direction)
3336

37+
3438
func _on_ScoreTimer_timeout():
3539
score += 1
3640
$HUD.update_score(score)
3741

42+
3843
func _on_StartTimer_timeout():
3944
$MobTimer.start()
40-
$ScoreTimer.start()
45+
$ScoreTimer.start()

2d/dodge_the_creeps/Main.tscn

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[sub_resource type="Curve2D" id=1]
1111
_data = {
12-
"points": PoolVector2Array( 0, 0, 0, 0, -0.901337, 0.225891, 0, 0, 0, 0, 480.262, 1.29041, 0, 0, 0, 0, 481.327, 700.681, 0, 0, 0, 0, 0.163177, 698.552, 0, 0, 0, 0, -0.901337, 0.225891 )
12+
"points": PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 480, 0, 0, 0, 0, 0, 480, 720, 0, 0, 0, 0, 0, 720, 0, 0, 0, 0, 0, 0 )
1313
}
1414

1515
[node name="Main" type="Node"]
@@ -19,7 +19,7 @@ Mob = ExtResource( 2 )
1919
[node name="ColorRect" type="ColorRect" parent="."]
2020
anchor_right = 1.0
2121
anchor_bottom = 1.0
22-
color = Color( 0.223529, 0.317647, 0.368627, 1 )
22+
color = Color( 0.219608, 0.372549, 0.380392, 1 )
2323

2424
[node name="Player" parent="." instance=ExtResource( 3 )]
2525

@@ -39,8 +39,6 @@ position = Vector2( 240, 450 )
3939
curve = SubResource( 1 )
4040

4141
[node name="MobSpawnLocation" type="PathFollow2D" parent="MobPath"]
42-
position = Vector2( -0.901337, 0.225891 )
43-
rotation = 0.00221238
4442

4543
[node name="HUD" parent="." instance=ExtResource( 4 )]
4644

@@ -49,7 +47,6 @@ stream = ExtResource( 5 )
4947

5048
[node name="DeathSound" type="AudioStreamPlayer" parent="."]
5149
stream = ExtResource( 6 )
52-
5350
[connection signal="hit" from="Player" to="." method="game_over"]
5451
[connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"]
5552
[connection signal="timeout" from="ScoreTimer" to="." method="_on_ScoreTimer_timeout"]

2d/dodge_the_creeps/Mob.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
extends RigidBody2D
22

3+
#warning-ignore-all:unused_class_variable
34
export var min_speed = 150
45
export var max_speed = 250
56
var mob_types = ["walk", "swim", "fly"]
67

78
func _ready():
89
$AnimatedSprite.animation = mob_types[randi() % mob_types.size()]
910

11+
1012
func _on_VisibilityNotifier2D_screen_exited():
11-
queue_free()
13+
queue_free()

2d/dodge_the_creeps/Mob.tscn

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
[gd_scene load_steps=10 format=2]
22

33
[ext_resource path="res://Mob.gd" type="Script" id=1]
4-
[ext_resource path="res://art/enemySwimming_1.png" type="Texture" id=2]
5-
[ext_resource path="res://art/enemySwimming_2.png" type="Texture" id=3]
4+
[ext_resource path="res://art/enemyFlyingAlt_1.png" type="Texture" id=2]
5+
[ext_resource path="res://art/enemyFlyingAlt_2.png" type="Texture" id=3]
66
[ext_resource path="res://art/enemyWalking_1.png" type="Texture" id=4]
77
[ext_resource path="res://art/enemyWalking_2.png" type="Texture" id=5]
8-
[ext_resource path="res://art/enemyFlyingAlt_1.png" type="Texture" id=6]
9-
[ext_resource path="res://art/enemyFlyingAlt_2.png" type="Texture" id=7]
8+
[ext_resource path="res://art/enemySwimming_1.png" type="Texture" id=6]
9+
[ext_resource path="res://art/enemySwimming_2.png" type="Texture" id=7]
1010

1111
[sub_resource type="SpriteFrames" id=1]
12-
1312
animations = [ {
1413
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
1514
"loop": true,
16-
"name": "swim",
17-
"speed": 4.0
15+
"name": "fly",
16+
"speed": 3.0
1817
}, {
1918
"frames": [ ExtResource( 4 ), ExtResource( 5 ) ],
2019
"loop": true,
@@ -23,12 +22,11 @@ animations = [ {
2322
}, {
2423
"frames": [ ExtResource( 6 ), ExtResource( 7 ) ],
2524
"loop": true,
26-
"name": "fly",
27-
"speed": 3.0
25+
"name": "swim",
26+
"speed": 4.0
2827
} ]
2928

3029
[sub_resource type="CapsuleShape2D" id=2]
31-
3230
radius = 35.2706
3331
height = 23.3281
3432

@@ -44,12 +42,12 @@ __meta__ = {
4442
scale = Vector2( 0.75, 0.75 )
4543
frames = SubResource( 1 )
4644
animation = "walk"
45+
frame = 1
4746
playing = true
4847

4948
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
5049
rotation = 1.5708
5150
shape = SubResource( 2 )
5251

5352
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
54-
5553
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]

2d/dodge_the_creeps/Player.gd

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,18 @@ extends Area2D
33
signal hit
44

55
export var speed = 400
6-
var extents
76
var screen_size
87

98
func _ready():
109
screen_size = get_viewport_rect().size
1110
hide()
1211

12+
1313
func _process(delta):
1414
var velocity = Vector2()
15-
if Input.is_action_pressed("ui_right"):
16-
velocity.x += 1
17-
if Input.is_action_pressed("ui_left"):
18-
velocity.x -= 1
19-
if Input.is_action_pressed("ui_up"):
20-
velocity.y -= 1
21-
if Input.is_action_pressed("ui_down"):
22-
velocity.y += 1
15+
velocity.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
16+
velocity.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
17+
2318
if velocity.length() > 0:
2419
velocity = velocity.normalized() * speed
2520
$AnimatedSprite.play()
@@ -37,12 +32,14 @@ func _process(delta):
3732
$AnimatedSprite.animation = "up"
3833
$AnimatedSprite.flip_v = velocity.y > 0
3934

40-
func _on_Player_body_entered(body):
41-
hide()
42-
emit_signal("hit")
43-
$CollisionShape2D.set_deferred("disabled", true)
4435

4536
func start(pos):
4637
position = pos
4738
show()
4839
$CollisionShape2D.disabled = false
40+
41+
42+
func _on_Player_body_entered(_body):
43+
hide()
44+
emit_signal("hit")
45+
$CollisionShape2D.set_deferred("disabled", true)

2d/dodge_the_creeps/Player.tscn

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=8 format=2]
1+
[gd_scene load_steps=13 format=2]
22

33
[ext_resource path="res://Player.gd" type="Script" id=1]
44
[ext_resource path="res://art/playerGrey_walk1.png" type="Texture" id=2]
@@ -23,7 +23,30 @@ animations = [ {
2323
radius = 26.1701
2424
height = 14.822
2525

26+
[sub_resource type="Gradient" id=3]
27+
colors = PoolColorArray( 1, 1, 1, 0.501961, 1, 1, 1, 0 )
28+
29+
[sub_resource type="GradientTexture" id=4]
30+
gradient = SubResource( 3 )
31+
32+
[sub_resource type="Curve" id=5]
33+
_data = [ Vector2( 0.00501098, 0.5 ), 0.0, 0.0, 0, 0, Vector2( 0.994989, 0.324 ), 0.0, 0.0, 0, 0 ]
34+
35+
[sub_resource type="CurveTexture" id=6]
36+
curve = SubResource( 5 )
37+
38+
[sub_resource type="ParticlesMaterial" id=7]
39+
flag_disable_z = true
40+
gravity = Vector3( 0, 0, 0 )
41+
initial_velocity = 1.0
42+
orbit_velocity = 0.0
43+
orbit_velocity_random = 0.0
44+
scale = 0.75
45+
scale_curve = SubResource( 6 )
46+
color_ramp = SubResource( 4 )
47+
2648
[node name="Player" type="Area2D"]
49+
z_index = 10
2750
script = ExtResource( 1 )
2851
__meta__ = {
2952
"_edit_group_": true
@@ -37,4 +60,11 @@ animation = "right"
3760
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
3861
shape = SubResource( 2 )
3962

63+
[node name="Trail" type="Particles2D" parent="."]
64+
z_index = -1
65+
amount = 10
66+
speed_scale = 2.0
67+
local_coords = false
68+
process_material = SubResource( 7 )
69+
texture = ExtResource( 2 )
4070
[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]

2d/dodge_the_creeps/default_env.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55
[resource]
66
background_mode = 2
77
background_sky = SubResource( 1 )
8-

0 commit comments

Comments
 (0)