Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var motion = Vector2(0, 0)
- const UP = Vector2(0, -1)
- const GRAVITY = 500
- const MAX_SPEED = 100
- const ACCELERATION = 600
- const JUMP_HEIGHT = -200
- const WALL_JUMP_HEIGHT = -130
- const TERMINAL_VELOCITY = 250
- const FRICTION = 1.2
- const AIR_FRICTION = 1.03
- var direction = 1
- var gravitymode = 1
- var active = 1
- var debugmode = true
- func _physics_process(delta):
- if debugmode == true:
- print(Engine.get_frames_per_second())
- print(motion.y)
- if active == 1:
- if gravitymode == 1:
- motion.y += GRAVITY * delta
- motion.y = min(motion.y, TERMINAL_VELOCITY)
- elif gravitymode == 3:
- motion.y += GRAVITY * delta * 0.4
- motion.y = min(motion.y, TERMINAL_VELOCITY/4)
- if is_on_floor():
- if Input.is_action_just_pressed("jump"):
- motion.y = JUMP_HEIGHT - (abs(motion.x) / 10)
- if Input.is_action_just_released("jump"):
- if motion.y < -100:
- motion.y = -100
- if Input.is_action_pressed("right"):
- motion.x = min(motion.x+ACCELERATION * delta, MAX_SPEED)
- elif Input.is_action_pressed("left"):
- motion.x = max(motion.x-ACCELERATION * delta, -MAX_SPEED)
- else:
- if is_on_floor():
- motion.x = motion.x / FRICTION
- else:
- motion.x = motion.x / AIR_FRICTION
- if motion.x > 0:
- $Sprite.flip_h = false
- direction = 1
- elif motion.x < 0:
- $Sprite.flip_h = true
- direction = -1
- if is_on_wall() && !is_on_floor():
- if motion.y > 0:
- gravitymode = 3
- if Input.is_action_just_pressed("jump"):
- motion.y = WALL_JUMP_HEIGHT
- motion.x = MAX_SPEED * -direction * 1.4
- elif gravitymode != 2:
- gravitymode = 1
- if is_on_floor():
- if motion.x < -10 || motion.x > 10:
- $Sprite/AnimationPlayer.play("Running")
- else:
- $Sprite/AnimationPlayer.play("Idle")
- if motion.x > 0 && Input.is_action_pressed("left") || motion.x < 0 && Input.is_action_pressed("right"):
- $Sprite/AnimationPlayer.play("Turning")
- else:
- if motion.y < 0:
- $Sprite/AnimationPlayer.play("Jumping")
- else:
- $Sprite/AnimationPlayer.play("Falling")
- if is_on_wall():
- $Sprite/AnimationPlayer.play("WallSlide")
- if position.y > 960:
- position.y = 1
- motion = move_and_slide(motion, UP)
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement