direction weapons, added javelin weapon

This commit is contained in:
2021-12-04 17:44:29 -06:00
parent f18924dd3d
commit db6cec47b4
9 changed files with 180 additions and 30 deletions

View File

@@ -10,7 +10,6 @@ var health_index: int = 6
var hud: CanvasLayer = null
var velocity: Vector2 = Vector2.ZERO
func _physics_process(delta: float) -> void:
var input_vector: Vector2 = Vector2.ZERO
@@ -23,6 +22,7 @@ func _physics_process(delta: float) -> void:
if input_vector != Vector2.ZERO:
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
set_weapon_position(input_vector)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
@@ -39,6 +39,56 @@ func load_hud(node: CanvasLayer) -> void:
hud.update_currency($Inventory.get_currency())
return
func set_weapon_position(pos: Vector2) -> void:
if pos[0] < 0: # facing left
$SwordAnimation.position.x = -8
$SwordAnimation.position.y = -6
$SwordAnimation.scale.x = -1
$SwordAnimation.rotation_degrees = 0
$SwordAnimation.z_index = 0
$JavelinAnimation.position.x = -8
$JavelinAnimation.position.y = -4
$JavelinAnimation.scale.x = -1
$JavelinAnimation.rotation_degrees = 0
$JavelinAnimation.z_index = 0
elif pos[0] > 0: # facing right
$SwordAnimation.position.x = 8
$SwordAnimation.position.y = -6
$SwordAnimation.scale.x = 1
$SwordAnimation.rotation_degrees = 0
$SwordAnimation.z_index = 0
$JavelinAnimation.position.x = 8
$JavelinAnimation.position.y = -4
$JavelinAnimation.scale.x = 1
$JavelinAnimation.rotation_degrees = 0
$JavelinAnimation.z_index = 0
elif pos[1] < 0: # facing up
$SwordAnimation.position.x = -4
$SwordAnimation.position.y = -12
$SwordAnimation.scale.x = 1
$SwordAnimation.rotation_degrees = -90
$SwordAnimation.z_index = 0
$JavelinAnimation.position.x = 0
$JavelinAnimation.position.y = -10
$JavelinAnimation.scale.x = 1
$JavelinAnimation.rotation_degrees = -90
$JavelinAnimation.z_index = 0
elif pos[1] > 0: # facing down
$SwordAnimation.position.x = 4
$SwordAnimation.position.y = 2
$SwordAnimation.scale.x = 1
$SwordAnimation.rotation_degrees = 90
$SwordAnimation.z_index = 1
$JavelinAnimation.position.x = 0
$JavelinAnimation.position.y = 0
$JavelinAnimation.scale.x = 1
$JavelinAnimation.rotation_degrees = 90
$JavelinAnimation.z_index = 1
return
func add_currency(amount: int) -> void:
$Inventory.add_currency(amount)
@@ -49,7 +99,6 @@ 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
@@ -75,6 +124,10 @@ func _input(event: InputEvent) -> void:
print('ERROR: Failed saving screenshot.')
if event.is_action_pressed("player_attack"):
$SwordAnimation/SwordAttack.play("swing")
if hud.weapon == "sword":
$SwordAnimation/SwordAttack.play("swing")
elif hud.weapon == "javelin":
$JavelinAnimation/JavelinAttack.play("swing")
return