...
This commit is contained in:
parent
9d3b7827eb
commit
cc2ec3b61c
33 changed files with 5 additions and 1 deletions
|
|
@ -0,0 +1,9 @@
|
|||
```python
|
||||
extends Area2D
|
||||
|
||||
func _ready() -> void:
|
||||
area_entered.connect(_on_area_entered)
|
||||
|
||||
func _on_area_entered(area_that_entred: Area2D) -> void:
|
||||
queue_free()
|
||||
```
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
````python
|
||||
extends Area2D
|
||||
|
||||
var max_speed := 1200.0
|
||||
var velocity := Vector2(0, 0)
|
||||
var steering_factor := 3.0
|
||||
|
||||
var health := 10
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
area_entered.connect(_on_area_entered)
|
||||
# This call updates the health bar to match the health variable when the
|
||||
# game starts.
|
||||
set_health(health)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var direction := Vector2(0, 0)
|
||||
direction.x = Input.get_axis("move_left", "move_right")
|
||||
direction.y = Input.get_axis("move_up", "move_down")
|
||||
|
||||
if direction.length() > 1.0:
|
||||
direction = direction.normalized()
|
||||
|
||||
var desired_velocity := max_speed * direction
|
||||
var steering := desired_velocity - velocity
|
||||
velocity += steering * steering_factor * delta
|
||||
position += velocity * delta
|
||||
|
||||
if velocity.length() > 0.0:
|
||||
get_node("Sprite2D").rotation = velocity.angle()
|
||||
|
||||
|
||||
func set_health(new_health: int) -> void:
|
||||
health = new_health
|
||||
get_node("UI/HealthBar").value = health
|
||||
|
||||
|
||||
func _on_area_entered(area_that_entered: Area2D) -> void:
|
||||
set_health(health + 10)
|
||||
```
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue