diff options
Diffstat (limited to 'KinematicBody2D.gd')
| -rw-r--r-- | KinematicBody2D.gd | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd index 3be3afc..4f2949c 100644 --- a/KinematicBody2D.gd +++ b/KinematicBody2D.gd @@ -1,5 +1,7 @@ -extends KinematicBody2D +extends Area2D +signal hit +var screen_size export (int) var speed = 200 var spawn_object = load("res://Bullet.tscn") var velocity = Vector2() @@ -17,11 +19,20 @@ func get_input(): velocity.y -= 1 velocity = velocity.normalized() * speed +func _ready(): + screen_size = get_viewport_rect().size + func _physics_process(delta): get_input() globals.playerPos = global_position - velocity = move_and_slide(velocity) + position += velocity * delta + position.x = clamp(position.x, 0, screen_size.x) + position.y = clamp(position.y, 0, screen_size.y) if Input.is_action_just_pressed("click"): var obj = spawn_object.instance() obj.position = get_position() get_owner().add_child(obj) + var bodies = get_overlapping_bodies() + for body in bodies: + if body.get_name() != "Bullet": + emit_signal("hit", delta) |
