diff options
| author | freddie-a <57713959+freddie-a@users.noreply.github.com> | 2022-10-29 21:59:06 +0100 |
|---|---|---|
| committer | freddie-a <57713959+freddie-a@users.noreply.github.com> | 2022-10-29 21:59:06 +0100 |
| commit | 92758c8c998091b8c2a20e6af5f2f473aa130d7a (patch) | |
| tree | 1a86ffdf0388000b903851fb5230edb8199eff99 /KinematicBody2D.gd | |
| parent | e91f2c9f403522b22b730f777baa354b9a9cfedc (diff) | |
Add health loss
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) |
