Untitled
unknown
python
6 months ago
1.5 kB
5
Indexable
extends CharacterBody2D var movement_speed = 200.0 var hp = 100 @onready var sprite = $Sprite2D @onready var walkTimer = get_node("%walkTimer") #var animation_speed = 0.1 # Seconds per frame #var animation_timer = 0.0 func _process(delta): # Update the animation timer # animation_timer += delta # if animation_timer >= animation_speed: # # Reset the timer and advance the frame # animation_timer = 0.0 # sprite.frame += 1 # # Loop back to frame 0 after reaching frame 49 # if sprite.frame > 49: # sprite.frame = 0 # movement() # Calls the movement function # Trigger taunt on key press if Input.is_action_just_pressed("taunt"): taunt() #BASE CODE func movement(): # Basic movement code remains the same var x_mov = Input.get_action_strength("right") - Input.get_action_strength("left") var y_mov = Input.get_action_strength("down") - Input.get_action_strength("up") var mov = Vector2(x_mov, y_mov) if mov.x > 0: sprite.flip_h = true elif mov.x < 0: sprite.flip_h = false if mov != Vector2.ZERO: if walkTimer.is_stopped(): if sprite.frame >= sprite.hframes - 1: sprite.frame = 0 else: sprite.frame += 1 walkTimer.start() velocity = mov.normalized() * movement_speed move_and_slide() # Function to make the player do a taunt dance func taunt(): for i in range(500): await get_tree().create_timer(0.05).timeout sprite.flip_h = !sprite.flip_h # Flip the sprite back and forth func _on_hurt_box_hurt(damage): hp -= damage print(hp)
Editor is loading...
Leave a Comment