Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody2D
- class_name Player
- @export var speed : int = 5
- @export var can_move : bool = true
- @export var health : int = 1
- @onready var punch = $PunchCollision
- @onready var animation = $AnimationPlayer
- var dir: String #where the player is moving
- # Called when the node enters the scene tree for the first time.
- func _ready():
- pass # Replace with function body.
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- func _process(delta):
- if health < 1:
- queue_free()
- # move_and_slide()
- func _physics_process(delta):
- var input_vector = Input.get_vector("left", "right", "up", "down")
- velocity += input_vector * speed * 100 * delta
- if can_move == true:
- sprite_movement()
- position = velocity
- move_and_slide()
- if Input.is_action_just_pressed("punch"):
- can_move = false
- animation.play("punch")
- func sprite_movement():
- if Input.is_action_pressed("up"):
- rotation_degrees = 0
- elif Input.is_action_pressed("down"):
- rotation_degrees = 180
- elif Input.is_action_pressed("right"):
- rotation_degrees = 90
- elif Input.is_action_pressed("left"):
- rotation_degrees = 270
- func _on_punch_collision_area_entered(area):
- if area is Bullet:
- var direction : int = rotation_degrees
- var current_dir : int = area.rotation_degrees
- area.rotation_degrees = direction
- area.dir_vector = area.dir_vector.rotated(deg_to_rad(direction - current_dir))
- area.velocity = -150
- Eventsbus.deflected.emit(direction)
- area.is_deflected = true
- area.can_deflect = false
Advertisement
Add Comment
Please, Sign In to add comment