Advertisement
16BItKtempo

code 2

Feb 1st, 2021
529
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 = 60
  5. const JUMP_POWER = -180
  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.         on_ground = true
  18.  elif Input.is_action_pressed("move_right") && isAttacking == false:
  19.         velocity.x = SPEED
  20.         $player.play("walk")
  21.         on_ground = true
  22.     else:
  23.         on_ground = true
  24.         velocity.x = 0
  25.        
  26.    
  27.     if Input.is_action_pressed("ui_up") && isAttacking == false:
  28.             on_ground = true
  29.             velocity.y = JUMP_POWER
  30.             on_ground = false
  31.     else:
  32.         on_ground = true
  33.            
  34.    
  35.            
  36.     if Input.is_action_just_pressed("attack_jab"):
  37.         $player.play("jab");
  38.         isAttacking = true;
  39.         on_ground = true
  40.     else:
  41.         isAttacking = false
  42.        
  43.     if Input.is_action_just_pressed("roundhouse"):
  44.         $player.play('roundhouse')
  45.         isAttacking = true;
  46.         on_ground = true;
  47.     else:
  48.         isAttacking = false
  49.        
  50.     if Input.is_action_just_pressed("teep"):
  51.         $player.play('teep')
  52.         isAttacking = true;
  53.         on_ground = true;
  54.    
  55.     if Input.is_action_just_pressed("attack_jab") and Input.is_action_pressed("move_right"):
  56.             $player.play("elbow");
  57.             isAttacking = true;
  58.             on_ground = true
  59.     else:
  60.         isAttacking = false
  61.        
  62.     if Input.is_action_just_pressed("attack cross"):
  63.         $player.play('cross')
  64.         isAttacking = true;
  65.         on_ground = true;
  66.     else:
  67.         isAttacking = false
  68.        
  69.     if Input.is_action_pressed("ui_up") && isAttacking == false:
  70.             on_ground = true
  71.             velocity.y = JUMP_POWER
  72.             on_ground = false
  73.        
  74.  
  75.     velocity.y += GRAVITY
  76.    
  77.     velocity = move_and_slide(velocity, FLOOR)
  78.    
  79.        
  80.        
  81.  
  82.            
  83.            
  84.    
  85.    
  86.        
  87.    
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. func _on_player_animation_finished():
  96.     if on_ground == true && isAttacking == false:
  97.         $player.play("idle")
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement