Advertisement
Guest User

Untitled

a guest
Aug 30th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. extends "res://Actors/ActorTemplate.gd"
  2.  
  3. var motion = Vector2.ZERO
  4. var up = Vector2(0,-1)
  5. var snap_vec = Vector2.DOWN
  6. var sprite_flipped: bool
  7.  
  8.  
  9. func _ready():
  10.     sprite_flipped = false
  11.  
  12.  
  13. func _physics_process(delta):
  14.     move_and_animation()
  15.     player_animations()
  16.     motion = move_and_slide_with_snap(motion,snap_vec,up)
  17.     apply_gravity()
  18.     on_player_flip()
  19.  
  20.  
  21. func apply_gravity():
  22.     motion.y += GRAVITY
  23.  
  24.  
  25. func move_and_animation():
  26.     #Falling animation
  27.     if ! is_on_floor() and motion.y > 0:
  28.         $CharacterRig/AnimationPlayer.play("fall")
  29.     #Move left / Aninmate left
  30.     if Input.is_action_pressed("move_left"):
  31.         sprite_flipped = true
  32.         motion.x = lerp(motion.x -SPEED, -MAX_SPEED, ACCELERATION)
  33.         if is_on_floor():
  34.             $CharacterRig/AnimationPlayer.play("run")
  35.     #Move right / Animate right
  36.     elif Input.is_action_pressed("move_right"):
  37.         sprite_flipped = false
  38.         motion.x = lerp(motion.x +SPEED, +MAX_SPEED, ACCELERATION)
  39.         if is_on_floor():
  40.             $CharacterRig/AnimationPlayer.play("run")
  41.     #When on floor with no input, stop player, animate idle
  42.     else:
  43.         motion.x = lerp(motion.x, 0, FRICTION)
  44.         if is_on_floor() and $PlayerCollision/GroundDetection.is_colliding():
  45.             $CharacterRig/AnimationPlayer.play("idle")
  46.     #When on floor jump and animate jump
  47.     if is_on_floor():
  48.         if Input.is_action_just_pressed("jump"):
  49.             motion.y = clamp(motion.y, 0, -JUMP)
  50.             $CharacterRig/AnimationPlayer.play("jump")
  51.  
  52.  
  53. func player_animations():
  54.     if Input.is_action_just_pressed("dance"):
  55.         $CharacterRig/AnimationPlayer.play("dance")
  56.     if Input.is_action_just_pressed("attack"):
  57.         $CharacterRig/AnimationPlayer.play("attack")
  58.  
  59.  
  60.     #Flip stuff for player (Sprite / Physics Collision)
  61. func on_player_flip():
  62.     if sprite_flipped == true:
  63.         $CharacterRig.scale.x = -1
  64.         $PlayerCollision.scale.x = -1
  65.     elif sprite_flipped == false:
  66.         $CharacterRig.scale.x = 1
  67.         $PlayerCollision.scale.x = 1
  68.    
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement