@@ -8,28 +8,28 @@ const BULLET_COUNT = 500
88const SPEED_MIN = 20
99const SPEED_MAX = 80
1010
11- const bullet_image = preload ("res://bullet.png" )
11+ const bullet_image : = preload ("res://bullet.png" )
1212
1313var bullets := []
14- var shape
14+ var shape := RID ()
1515
1616
1717class Bullet :
18- var position = Vector2 ()
19- var speed = 1.0
18+ var position : = Vector2 ()
19+ var speed : = 1.0
2020 # The body is stored as a RID, which is an "opaque" way to access resources.
2121 # With large amounts of objects (thousands or more), it can be significantly
2222 # faster to use RIDs compared to a high-level approach.
23- var body = RID ()
23+ var body : = RID ()
2424
2525
26- func _ready ():
26+ func _ready () -> void :
2727 shape = PhysicsServer2D .circle_shape_create ()
2828 # Set the collision shape's radius for each bullet in pixels.
2929 PhysicsServer2D .shape_set_data (shape , 8 )
3030
3131 for _i in BULLET_COUNT :
32- var bullet = Bullet .new ()
32+ var bullet : = Bullet .new ()
3333 # Give each bullet its own random speed.
3434 bullet .speed = randf_range (SPEED_MIN , SPEED_MAX )
3535 bullet .body = PhysicsServer2D .body_create ()
@@ -45,22 +45,22 @@ func _ready():
4545 randf_range (0 , get_viewport_rect ().size .x ) + get_viewport_rect ().size .x ,
4646 randf_range (0 , get_viewport_rect ().size .y )
4747 )
48- var transform2d = Transform2D ()
48+ var transform2d : = Transform2D ()
4949 transform2d .origin = bullet .position
5050 PhysicsServer2D .body_set_state (bullet .body , PhysicsServer2D .BODY_STATE_TRANSFORM , transform2d )
5151
5252 bullets .push_back (bullet )
5353
5454
55- func _process (_delta ) :
55+ func _process (_delta : float ) -> void :
5656 # Order the CanvasItem to update every frame.
5757 queue_redraw ()
5858
5959
60- func _physics_process (delta ) :
61- var transform2d = Transform2D ()
62- var offset = get_viewport_rect ().size .x + 16
63- for bullet in bullets :
60+ func _physics_process (delta : float ) -> void :
61+ var transform2d : = Transform2D ()
62+ var offset : = get_viewport_rect ().size .x + 16
63+ for bullet : Bullet in bullets :
6464 bullet .position .x -= bullet .speed * delta
6565
6666 if bullet .position .x < - 16 :
@@ -73,15 +73,15 @@ func _physics_process(delta):
7373
7474# Instead of drawing each bullet individually in a script attached to each bullet,
7575# we are drawing *all* the bullets at once here.
76- func _draw ():
77- var offset = - bullet_image .get_size () * 0.5
78- for bullet in bullets :
76+ func _draw () -> void :
77+ var offset : = - bullet_image .get_size () * 0.5
78+ for bullet : Bullet in bullets :
7979 draw_texture (bullet_image , bullet .position + offset )
8080
8181
8282# Perform cleanup operations (required to exit without error messages in the console).
83- func _exit_tree ():
84- for bullet in bullets :
83+ func _exit_tree () -> void :
84+ for bullet : Bullet in bullets :
8585 PhysicsServer2D .free_rid (bullet .body )
8686
8787 PhysicsServer2D .free_rid (shape )
0 commit comments