godot-start/scene/demo07_collision/collision.tscn

80 lines
2.3 KiB
Plaintext
Raw Normal View History

2021-10-05 05:50:57 +00:00
[gd_scene load_steps=5 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 31.5644, 29.6976 )
[sub_resource type="GDScript" id=2]
script/source = "extends KinematicBody2D
# How fast the player will move (pixels/sec).
export var speed = 400
# Size of the game window.
var screen_size
func _ready():
screen_size = get_viewport_rect().size
func _physics_process(delta):
var velocity = Vector2.ZERO # The player's movement vector.
if Input.is_action_pressed(\"move_right\"):
velocity.x += 1
if Input.is_action_pressed(\"move_left\"):
velocity.x -= 1
if Input.is_action_pressed(\"move_down\"):
velocity.y += 1
if Input.is_action_pressed(\"move_up\"):
velocity.y -= 1
if velocity.length() <= 0:
return
velocity = velocity.normalized() * speed
var info: KinematicCollision2D = move_and_collide(velocity * delta)
if info != null:
print(info.collider.name)
"
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 30.17, 29.3458 )
[node name="Node2D" type="Node2D"]
[node name="StaticBody2D" type="StaticBody2D" parent="."]
position = Vector2( 64.5824, 547.095 )
[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D"]
color = Color( 0.329412, 0.580392, 0.270588, 1 )
polygon = PoolVector2Array( -23.2672, -184.708, -24.0164, 46.0308, 896.693, 51.2749, 897.443, -184.708, 653.968, 3.3291, 39.6617, 1.83081, 39.6617, -180.214 )
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"]
polygon = PoolVector2Array( -25.5147, -183.959, -26.2638, 45.2817, 895.944, 52.024, 897.443, -184.708, 654.717, 4.07825, 38.1633, -2.66412, 38.9125, -183.21 )
[node name="RigidBody2D" type="RigidBody2D" parent="."]
position = Vector2( 880.023, 40.7525 )
__meta__ = {
"_edit_group_": true
}
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="RigidBody2D"]
texture = ExtResource( 1 )
[node name="KinematicBody2D" type="KinematicBody2D" parent="."]
position = Vector2( 549.424, 338.422 )
script = SubResource( 2 )
__meta__ = {
"_edit_group_": true
}
[node name="CollisionShape2D" type="CollisionShape2D" parent="KinematicBody2D"]
shape = SubResource( 3 )
[node name="Sprite" type="Sprite" parent="KinematicBody2D"]
texture = ExtResource( 1 )