Mostly health
This commit is contained in:
21
scripts/bullet.gd
Normal file
21
scripts/bullet.gd
Normal file
@ -0,0 +1,21 @@
|
||||
extends Area2D
|
||||
|
||||
const SPEED = 500
|
||||
const RANGE = 500
|
||||
|
||||
var travelled_distance = 0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var direction = Vector2.RIGHT.rotated(rotation)
|
||||
position += direction * SPEED * delta
|
||||
|
||||
travelled_distance += SPEED * delta
|
||||
|
||||
if travelled_distance > RANGE:
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
queue_free()
|
||||
if body.has_method("take_damage"):
|
||||
body.take_damage()
|
@ -1,8 +1,14 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
var health = 5
|
||||
@onready var player = get_node("/root/Game/player")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var direction = global_position.direction_to(player.global_position)
|
||||
velocity = direction * 50
|
||||
move_and_slide()
|
||||
|
||||
func take_damage():
|
||||
health -= 1
|
||||
if health == 0:
|
||||
queue_free()
|
||||
|
@ -1,7 +1,20 @@
|
||||
extends CharacterBody2D
|
||||
signal health_depleted
|
||||
|
||||
var health = 100.0
|
||||
const DAMAGE_RATE = 5.0
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = direction * 200
|
||||
move_and_slide()
|
||||
pass
|
||||
|
||||
|
||||
var overlappong_mobs = %Hurtbox.get_overlapping_bodies()
|
||||
|
||||
if overlappong_mobs.size() > 0 :
|
||||
health -= DAMAGE_RATE * overlappong_mobs.size() * delta
|
||||
%ProgressBar.value = health
|
||||
if health <= 0.0:
|
||||
health_depleted.emit()
|
||||
|
Reference in New Issue
Block a user