Advertisement
16BItKtempo

Untitled

Jan 25th, 2021
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends KinematicBody2D
  2.  
  3. const SPEED = 100
  4. const GRAVITY = 10
  5. const JUMP_POWER = -250
  6. const FLOOR = Vector2(0, -1)
  7.  
  8. var velocity = Vector2()
  9. var on_ground = false
  10. var isAttacking = false
  11.  
  12. func _physics_process(_delta):
  13.    
  14.     if Input.is_action_pressed("ui_left") && isAttacking == false:
  15.         velocity.x = -SPEED
  16.         $player.play("walk")
  17.  elif Input.is_action_pressed("move_right") && isAttacking == false:
  18.         velocity.x = SPEED
  19.         $player.play("walk")
  20.    
  21.        
  22.     if Input.is_action_pressed("ui_up") && isAttacking == false:
  23.         if on_ground == true:
  24.             velocity.y = JUMP_POWER
  25.             on_ground = false
  26.            
  27.     if Input.is_action_just_pressed("attack_jab"):
  28.         $player.play("jab");
  29.         isAttacking = true;
  30.         on_ground = true
  31.    
  32.        
  33.     if Input.is_action_just_pressed("roundhouse"):
  34.         $player.play('roundhouse')
  35.         isAttacking = true;
  36.         on_ground = true;
  37.        
  38.  
  39.     velocity.y += GRAVITY
  40.    
  41.     velocity = move_and_slide(velocity, FLOOR)
  42.    
  43.     if is_on_floor():
  44.         on_ground = true
  45.     else:
  46.         on_ground = false
  47.        
  48.        
  49. func _on_player_animation_finished():
  50.         if $player.animation == 'jab:':
  51.             isAttacking = false;
  52.             on_ground = true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement