New features and plenty of code still in testing. This includes a level select, basic inventory, and a basic HUD.

This commit is contained in:
VoidTwo
2021-11-15 22:29:42 -06:00
parent bbb245f7b7
commit 2c98c112bd
47 changed files with 753 additions and 68 deletions

59
Player/Player.gd Normal file
View File

@@ -0,0 +1,59 @@
extends KinematicBody2D
const ACCELERATION: int = 1000
const MAX_SPEED: int = 120
const FRICTION: int = 1000
const HEALTH_SLICES: Array = [0, 20, 35, 50, 65, 80, 100]
var health_index: int = 6
var hud: CanvasLayer = null
var velocity: Vector2 = Vector2.ZERO
func _physics_process(delta) -> void:
var input_vector: Vector2 = Vector2.ZERO
input_vector.x = Input.get_action_strength('player_right') \
- Input.get_action_strength('player_left')
input_vector.y = Input.get_action_strength('player_down') \
- Input.get_action_strength('player_up')
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
velocity = move_and_slide(velocity)
return
func load_hud(node: CanvasLayer) -> void:
hud = node
if hud.connect('add_currency', self, 'add_currency') != OK:
print('ERROR: HUD "add_currency" signal already connected.')
hud.update_health(HEALTH_SLICES[health_index])
hud.update_currency($Inventory.get_currency())
return
func add_currency(amount: int) -> void:
$Inventory.add_currency(amount)
return
func _on_Inventory_update_currency(amount: int) -> void:
hud.update_currency(amount)
return
func _on_Hitbox_body_entered(body: Node) -> void:
if not 'enemies' in body.get_groups():
return
if health_index != 0:
health_index -= 1
hud.update_health(HEALTH_SLICES[health_index])
return