adding physics object statue
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed:int = 50
|
||||
@export var speed:int = 150
|
||||
@export var max_speed:int = 350
|
||||
@export var push_power:int = 50 + speed
|
||||
@onready var health := max_health
|
||||
@@ -12,10 +12,7 @@ extends CharacterBody2D
|
||||
@onready var player := get_node(".")
|
||||
#Animation
|
||||
@onready var anim_tree = $AnimationTree
|
||||
@onready var atk_str := "parameters/attacking/current"
|
||||
@onready var mov_str := "parameters/moving/current"
|
||||
@onready var damage_str := "parameters/damaged/current"
|
||||
@onready var disabled_str := "parameters/disabled/current"
|
||||
@onready var anim_mode = anim_tree.get("parameters/playback")
|
||||
#Other
|
||||
@export var value:int = 0
|
||||
|
||||
@@ -49,6 +46,8 @@ signal player_killed
|
||||
|
||||
func _ready():
|
||||
if not is_multiplayer_authority(): return
|
||||
print("Setting IDLE")
|
||||
#anim_mode.travel("idle")
|
||||
|
||||
|
||||
func value_changed_func(amount: int) -> void:
|
||||
@@ -58,9 +57,11 @@ func value_changed_func(amount: int) -> void:
|
||||
func set_disabled(is_disabled:bool):
|
||||
player_disabled = is_disabled
|
||||
if is_disabled:
|
||||
anim_tree.set(disabled_str, 1)
|
||||
anim_tree.set("parameters/DamageOneShot/request", 1)
|
||||
#anim_tree.set(disabled_str, 1)
|
||||
else:
|
||||
anim_tree.set(disabled_str, 0)
|
||||
pass
|
||||
#anim_tree.set(disabled_str, 0)
|
||||
|
||||
func speed_changed_func(amount: int) -> void:
|
||||
speed = speed + amount
|
||||
@@ -74,9 +75,11 @@ func speed_changed_func(amount: int) -> void:
|
||||
|
||||
# reset our invulnerability animations
|
||||
func _on_invulnerable_timer_timeout():
|
||||
anim_tree.set(damage_str, 0)
|
||||
pass
|
||||
#anim_tree.set(damage_str, 0)
|
||||
|
||||
func health_changed_func(amount: int):
|
||||
print("Health DAMAGED!")
|
||||
if amount < 0:
|
||||
if invulnerability_timer.is_stopped():
|
||||
invulnerability_timer.start()
|
||||
@@ -87,13 +90,20 @@ func health_changed_func(amount: int):
|
||||
#TODO: Respawn char
|
||||
else:
|
||||
print("Setting health frame: ", health)
|
||||
anim_tree.set(damage_str, 1)
|
||||
#anim_tree.set(damage_str, 1)
|
||||
else:
|
||||
health = health + amount
|
||||
emit_signal("health_changed", health)
|
||||
|
||||
|
||||
func set_animation_state():
|
||||
if(velocity != Vector2.ZERO):
|
||||
anim_tree.travel("walk")
|
||||
else:
|
||||
pass
|
||||
#anim_tree.travel("idle")
|
||||
|
||||
func attack_finished():
|
||||
anim_tree.set(atk_str, 0)
|
||||
#anim_tree.set(atk_str, 0)
|
||||
is_attacking = false
|
||||
|
||||
func get_input():
|
||||
@@ -117,10 +127,16 @@ func get_input():
|
||||
is_attacking = true
|
||||
if player_facing == "left":
|
||||
player_sprite.flip_h = true
|
||||
anim_tree.set(atk_str, 1)
|
||||
print("Attacking!")
|
||||
#anim_tree.set("parameters/AttackOneShot/active", true)
|
||||
anim_tree.set("parameters/AttackOneShot/request", 1)
|
||||
#anim_tree.set(atk_str, 1)
|
||||
else:
|
||||
player_sprite.flip_h = false
|
||||
anim_tree.set(atk_str, 1)
|
||||
anim_tree.set("parameters/AttackOneShot/request", 1)
|
||||
#anim_tree.set(atk_str, 1)
|
||||
#anim_mode.travel("attack")
|
||||
next_attack_time = now + attack_speed
|
||||
if equipped:
|
||||
pass
|
||||
#spawned_item = load(ItemDatabase.Castable_objects[equipped.item_name]).instantiate()
|
||||
@@ -133,31 +149,27 @@ func get_input():
|
||||
#next_attack_time = now + attack_speed
|
||||
velocity = Vector2()
|
||||
var direction : String
|
||||
# if not input_active:
|
||||
# return
|
||||
if Input.is_action_pressed("right") and not is_attacking:
|
||||
player_facing = "right"
|
||||
player_sprite.flip_h = false
|
||||
velocity.x += 1
|
||||
anim_tree.set(mov_str, 1)
|
||||
if Input.is_action_pressed("left") and not is_attacking:
|
||||
player_sprite.flip_h = true
|
||||
player_facing = "left"
|
||||
velocity.x -= 1
|
||||
anim_tree.set(mov_str, 1)
|
||||
if Input.is_action_pressed("down") and not is_attacking:
|
||||
direction = "down"
|
||||
velocity.y += 1
|
||||
anim_tree.set(mov_str, 1)
|
||||
if Input.is_action_pressed("up") and not is_attacking:
|
||||
direction = "up"
|
||||
velocity.y -= 1
|
||||
anim_tree.set(mov_str, 1)
|
||||
|
||||
|
||||
velocity = velocity.normalized() * speed
|
||||
if velocity == Vector2.ZERO:
|
||||
anim_tree.set(mov_str, 0)
|
||||
anim_tree.set("parameters/walkIdleBlend/blend_amount", 1)
|
||||
else:
|
||||
anim_tree.set("parameters/walkIdleBlend/blend_amount", 0)
|
||||
|
||||
func _physics_process(delta):
|
||||
# if not is_multiplayer_authority():
|
||||
@@ -174,8 +186,11 @@ func _physics_process(delta):
|
||||
if collider.is_in_group("moveable"):
|
||||
var normal = collision.get_normal()
|
||||
collider.apply_central_impulse(-collision.get_normal() * push_power)
|
||||
# push back the player when player pushed
|
||||
#player_hit.is_player_hit = true
|
||||
#player_hit.hit_velocity = push_power * .1
|
||||
|
||||
if player_hit.is_player_hit:
|
||||
if player_hit.is_player_hit: # moves player over time
|
||||
velocity = Vector2.ZERO
|
||||
set_disabled(true)
|
||||
player_hit.is_player_hit = false
|
||||
@@ -192,6 +207,9 @@ func _physics_process(delta):
|
||||
# $Networking.flipped_h = player_sprite.flip_h
|
||||
# $Networking.sync_frame_coords = player_sprite.get_frame_coords()
|
||||
|
||||
|
||||
|
||||
|
||||
func move_player(c_velocity: Vector2):
|
||||
# rpc(&'update_movement', velocity)
|
||||
var collided = move_and_collide(c_velocity)
|
||||
|
Reference in New Issue
Block a user