Skip to content

Commit

Permalink
Convert demos to Godot 4 using regular expressions in a script
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Mar 26, 2022
1 parent 410d783 commit bbe50fc
Show file tree
Hide file tree
Showing 1,095 changed files with 13,642 additions and 13,571 deletions.
6 changes: 3 additions & 3 deletions 2d/bullet_shower/bullet.png.import
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/bullet.png-ff1424653e10246c11e3724e402c519e.stex"
type="StreamTexture2D"
path="res://.godot/imported/bullet.png-ff1424653e10246c11e3724e402c519e.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://bullet.png"
dest_files=[ "res://.import/bullet.png-ff1424653e10246c11e3724e402c519e.stex" ]
dest_files=["res://.godot/imported/bullet.png-ff1424653e10246c11e3724e402c519e.stex"]

[params]

Expand Down
26 changes: 13 additions & 13 deletions 2d/bullet_shower/bullets.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ class Bullet:
func _ready():
randomize()

shape = Physics2DServer.circle_shape_create()
shape = PhysicsServer2D.circle_shape_create()
# Set the collision shape's radius for each bullet in pixels.
Physics2DServer.shape_set_data(shape, 8)
PhysicsServer2D.shape_set_data(shape, 8)

for _i in BULLET_COUNT:
var bullet = Bullet.new()
# Give each bullet its own speed.
bullet.speed = rand_range(SPEED_MIN, SPEED_MAX)
bullet.body = Physics2DServer.body_create()
bullet.speed = randf_range(SPEED_MIN, SPEED_MAX)
bullet.body = PhysicsServer2D.body_create()

Physics2DServer.body_set_space(bullet.body, get_world_2d().get_space())
Physics2DServer.body_add_shape(bullet.body, shape)
PhysicsServer2D.body_set_space(bullet.body, get_world_2d().get_space())
PhysicsServer2D.body_add_shape(bullet.body, shape)
# Don't make bullets check collision with other bullets to improve performance.
# Their collision mask is still configured to the default value, which allows
# bullets to detect collisions with the player.
Physics2DServer.body_set_collision_layer(bullet.body, 0)
PhysicsServer2D.body_set_collision_layer(bullet.body, 0)

# Place bullets randomly on the viewport and move bullets outside the
# play area so that they fade in nicely.
bullet.position = Vector2(
rand_range(0, get_viewport_rect().size.x) + get_viewport_rect().size.x,
rand_range(0, get_viewport_rect().size.y)
randf_range(0, get_viewport_rect().size.x) + get_viewport_rect().size.x,
randf_range(0, get_viewport_rect().size.y)
)
var transform2d = Transform2D()
transform2d.origin = bullet.position
Physics2DServer.body_set_state(bullet.body, Physics2DServer.BODY_STATE_TRANSFORM, transform2d)
PhysicsServer2D.body_set_state(bullet.body, PhysicsServer2D.BODY_STATE_TRANSFORM, transform2d)

bullets.push_back(bullet)

Expand All @@ -73,7 +73,7 @@ func _physics_process(delta):

transform2d.origin = bullet.position

Physics2DServer.body_set_state(bullet.body, Physics2DServer.BODY_STATE_TRANSFORM, transform2d)
PhysicsServer2D.body_set_state(bullet.body, PhysicsServer2D.BODY_STATE_TRANSFORM, transform2d)


# Instead of drawing each bullet individually in a script attached to each bullet,
Expand All @@ -87,7 +87,7 @@ func _draw():
# Perform cleanup operations (required to exit without error messages in the console).
func _exit_tree():
for bullet in bullets:
Physics2DServer.free_rid(bullet.body)
PhysicsServer2D.free_rid(bullet.body)

Physics2DServer.free_rid(shape)
PhysicsServer2D.free_rid(shape)
bullets.clear()
6 changes: 3 additions & 3 deletions 2d/bullet_shower/face_happy.png.import
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/face_happy.png-38d387d31ec13459f749c93ce3d75d80.stex"
type="StreamTexture2D"
path="res://.godot/imported/face_happy.png-38d387d31ec13459f749c93ce3d75d80.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://face_happy.png"
dest_files=[ "res://.import/face_happy.png-38d387d31ec13459f749c93ce3d75d80.stex" ]
dest_files=["res://.godot/imported/face_happy.png-38d387d31ec13459f749c93ce3d75d80.stex"]

[params]

Expand Down
6 changes: 3 additions & 3 deletions 2d/bullet_shower/face_sad.png.import
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/face_sad.png-0ac7165eab24f595aba17a746a66c550.stex"
type="StreamTexture2D"
path="res://.godot/imported/face_sad.png-0ac7165eab24f595aba17a746a66c550.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://face_sad.png"
dest_files=[ "res://.import/face_sad.png-0ac7165eab24f595aba17a746a66c550.stex" ]
dest_files=["res://.godot/imported/face_sad.png-0ac7165eab24f595aba17a746a66c550.stex"]

[params]

Expand Down
6 changes: 3 additions & 3 deletions 2d/bullet_shower/icon.png.import
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
type="StreamTexture2D"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"]

[params]

Expand Down
2 changes: 1 addition & 1 deletion 2d/bullet_shower/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extends Node2D
# The number of bullets currently touched by the player.
var touching = 0

onready var sprite = $AnimatedSprite
@onready var sprite = $AnimatedSprite2D


func _ready():
Expand Down
4 changes: 2 additions & 2 deletions 2d/bullet_shower/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

config_version=4

_global_script_classes=[ ]
_global_script_classes=[]
_global_script_class_icons={
}

Expand Down Expand Up @@ -37,4 +37,4 @@ quality/intended_usage/framebuffer_allocation=0
quality/intended_usage/framebuffer_allocation.mobile=0
vram_compression/import_etc=true
vram_compression/import_etc2=false
environment/default_clear_color=Color( 0.133333, 0.133333, 0.2, 1 )
environment/default_clear_color=Color(0.133333, 0.133333, 0.2, 1)
12 changes: 6 additions & 6 deletions 2d/bullet_shower/shower.tscn
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[gd_scene load_steps=7 format=2]

[ext_resource path="res://bullets.gd" type="Script" id=2]
[ext_resource path="res://face_happy.png" type="Texture" id=3]
[ext_resource path="res://face_sad.png" type="Texture" id=4]
[ext_resource path="res://face_happy.png" type="Texture2D" id=3]
[ext_resource path="res://face_sad.png" type="Texture2D" id=4]
[ext_resource path="res://player.gd" type="Script" id=5]

[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 3 ), ExtResource( 4 ) ],
animations = [{
"frames": [ExtResource( 3 ), ExtResource( 4 )],
"loop": true,
"name": "default",
"speed": 5.0
} ]
}]

[sub_resource type="CircleShape2D" id=2]
radius = 27.0
Expand All @@ -24,7 +24,7 @@ script = ExtResource( 2 )
[node name="Player" type="Area2D" parent="."]
script = ExtResource( 5 )

[node name="AnimatedSprite" type="AnimatedSprite" parent="Player"]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Player"]
frames = SubResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"]
Expand Down
4 changes: 2 additions & 2 deletions 2d/dodge_the_creeps/HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ func show_message(text):

func show_game_over():
show_message("Game Over")
yield($MessageTimer, "timeout")
await $MessageTimer.timeout
$MessageLabel.text = "Dodge the\nCreeps"
$MessageLabel.show()
yield(get_tree().create_timer(1), "timeout")
await get_tree().create_timer(1).timeout
$StartButton.show()


Expand Down
22 changes: 11 additions & 11 deletions 2d/dodge_the_creeps/HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
[gd_scene load_steps=7 format=2]

[ext_resource path="res://HUD.gd" type="Script" id=1]
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="FontData" id=2]

[sub_resource type="DynamicFont" id=1]
[sub_resource type="Font" id=1]
size = 64
font_data = ExtResource( 2 )

[sub_resource type="DynamicFont" id=2]
[sub_resource type="Font" id=2]
size = 64
font_data = ExtResource( 2 )

[sub_resource type="InputEventAction" id=3]
action = "start_game"

[sub_resource type="ShortCut" id=4]
[sub_resource type="Shortcut" id=4]
shortcut = SubResource( 3 )

[node name="HUD" type="CanvasLayer"]
script = ExtResource( 1 )

[node name="ScoreLabel" type="Label" parent="."]
anchor_right = 1.0
margin_bottom = 78.0
offset_bottom = 78.0
custom_fonts/font = SubResource( 1 )
text = "0"
align = 1
Expand All @@ -31,8 +31,8 @@ align = 1
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
margin_top = -79.5
margin_bottom = 79.5
offset_top = -79.5
offset_bottom = 79.5
custom_fonts/font = SubResource( 1 )
text = "Dodge the
Creeps"
Expand All @@ -43,10 +43,10 @@ anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -90.0
margin_top = -200.0
margin_right = 90.0
margin_bottom = -100.0
offset_left = -90.0
offset_top = -200.0
offset_right = 90.0
offset_bottom = -100.0
custom_fonts/font = SubResource( 2 )
shortcut = SubResource( 4 )
text = "Start"
Expand Down
10 changes: 5 additions & 5 deletions 2d/dodge_the_creeps/Main.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends Node

export(PackedScene) var mob_scene
@export var mob_scene: PackedScene
var score

func _ready():
Expand All @@ -27,10 +27,10 @@ func new_game():

func _on_MobTimer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instance()
var mob = mob_scene.instantiate()

# Choose a random location on Path2D.
var mob_spawn_location = get_node("MobPath/MobSpawnLocation")
var mob_spawn_location = get_node(^"MobPath/MobSpawnLocation")
mob_spawn_location.offset = randi()

# Set the mob's direction perpendicular to the path direction.
Expand All @@ -40,11 +40,11 @@ func _on_MobTimer_timeout():
mob.position = mob_spawn_location.position

# Add some randomness to the direction.
direction += rand_range(-PI / 4, PI / 4)
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction

# Choose the velocity for the mob.
var velocity = Vector2(rand_range(150.0, 250.0), 0.0)
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)

# Spawn the mob by adding it to the Main scene.
Expand Down
6 changes: 3 additions & 3 deletions 2d/dodge_the_creeps/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[sub_resource type="Curve2D" id=1]
_data = {
"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 )
"points": PackedVector2Array(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)
}

[node name="Main" type="Node"]
Expand All @@ -19,7 +19,7 @@ mob_scene = ExtResource( 2 )
[node name="ColorRect" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.219608, 0.372549, 0.380392, 1 )
color = Color(0.219608, 0.372549, 0.380392, 1)
__meta__ = {
"_edit_use_anchors_": false
}
Expand All @@ -36,7 +36,7 @@ wait_time = 2.0
one_shot = true

[node name="StartPosition" type="Position2D" parent="."]
position = Vector2( 240, 450 )
position = Vector2(240, 450)

[node name="MobPath" type="Path2D" parent="."]
curve = SubResource( 1 )
Expand Down
6 changes: 3 additions & 3 deletions 2d/dodge_the_creeps/Mob.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extends RigidBody2D

func _ready():
$AnimatedSprite.playing = true
var mob_types = $AnimatedSprite.frames.get_animation_names()
$AnimatedSprite.animation = mob_types[randi() % mob_types.size()]
$AnimatedSprite2D.playing = true
var mob_types = $AnimatedSprite2D.frames.get_animation_names()
$AnimatedSprite2D.animation = mob_types[randi() % mob_types.size()]


func _on_VisibilityNotifier2D_screen_exited():
Expand Down
Loading

0 comments on commit bbe50fc

Please sign in to comment.