Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody2D
- @export var yes = 1
- var up
- var down
- var left
- var right
- var input = Vector2.ZERO
- var speed
- var zoom_minimum= Vector2(2, 2)
- var zoom_maximum= Vector2(.5, .5)
- var zoom_speed= Vector2(.08, .08)
- var dashing = false
- var can_dash = true
- var direction
- @onready var camera = $Camera2D
- const move_speed: int = 6000
- const max_speed = 2100
- const accel = 1800
- const friction = 2500
- const dash_speed = 9000
- #Movement
- func _physics_process(delta):
- player_movement(delta)
- func get_input():
- input.x = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"))
- input.y = int(Input.is_action_pressed("down")) - int(Input.is_action_pressed("up"))
- return input.normalized()
- func _input(_delta):
- if Input.is_action_pressed("plus"):
- if camera.zoom < zoom_minimum:
- camera.zoom += zoom_speed
- if Input.is_action_pressed("minus"):
- if camera.zoom > zoom_maximum:
- camera.zoom -= zoom_speed
- if Input.is_action_just_pressed("dashing") and can_dash:
- dashing = true
- can_dash = false
- $dash_timer.start()
- $dash_again_timer.start()
- func player_movement(delta):
- input = get_input()
- if input == Vector2.ZERO:
- if velocity.length() > (friction * delta):
- velocity -= velocity.normalized() * (friction * delta)
- else:
- velocity = Vector2.ZERO
- else:
- velocity += (input * accel * delta * 2)
- velocity = velocity.limit_length(max_speed)
- if direction:
- if dashing:
- velocity = input + dash_speed
- else:
- velocity = input + speed
- #animation I hate it so much
- if velocity == Vector2.ZERO:
- pass
- else:
- $AnimationTree.set("parameters/Idle/blend_position", velocity)
- $AnimationTree.set("parameters/Walk/blend_position", velocity)
- move_and_slide()
- #make it stop dashing
- func _on_dash_timer_timeout():
- dashing = false
- func _on_dash_again_timer_timeout():
- can_dash = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement