...
This commit is contained in:
parent
1fe0ac690c
commit
3436132866
7 changed files with 47 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
![[Pasted image 20240320114003.png]]
|
||||
|
|
@ -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)
|
||||
```
|
||||
|
||||
BIN
MyObsidianVault/Pasted image 20240320113513.png
Normal file
BIN
MyObsidianVault/Pasted image 20240320113513.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
BIN
MyObsidianVault/Pasted image 20240320114003.png
Normal file
BIN
MyObsidianVault/Pasted image 20240320114003.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
1
MyObsidianVault/Untitled.canvas
Normal file
1
MyObsidianVault/Untitled.canvas
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
docker-compose up -d
|
||||
./shell.sh
|
||||
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
Loading…
Add table
Add a link
Reference in a new issue