Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- #---------------------------VARIABLES-------------------------------------------
- var MAX_SPEED = 250
- var JUMP_SPEED = 25
- var GRAVITY =35
- var z = 0
- var JumpMultiplyer = 35
- var Jumping = false
- var punch = false
- var flyingPunch = false
- var velocity = Vector2()
- onready var animatedSprite = $AnimatedSprite
- #-------------------------JUMP + ANIMATION -------------------------------------
- # warning-ignore:unused_argument
- func _physics_process(delta):
- var input_vector = get_input_axis()
- print(Jumping)
- if Input.is_action_just_pressed("jump") and Jumping == false:
- animatedSprite.animation = "jump_right"
- Jumping = true
- z += -JUMP_SPEED * JumpMultiplyer
- if Input.is_action_just_pressed("air_attack"):
- flyingPunch = true
- animatedSprite.animation = "FlyingPunch"
- if z > 23 * JumpMultiplyer:
- Jumping = false
- z = 0
- velocity.y = 0
- if Jumping == true:
- z += GRAVITY
- velocity.y = z
- #--------------------------------walk_animation---------------------------------
- elif input_vector != Vector2.ZERO:
- if Jumping == false:
- #if !punch:
- animatedSprite.animation = "WalkRight"
- velocity = input_vector * MAX_SPEED
- #------------------------------Punch_animation-----------------------------------
- elif Input.is_action_just_pressed("punch"):
- punch = true
- #animatedSprite.speed_scale = 0.5
- animatedSprite.animation = "punch"
- #-----------------------------Idle_animation------------------------------------
- else:
- animatedSprite.animation = "IdleRight"
- Jumping = false
- flyingPunch = false
- punch = false
- velocity = Vector2()
- velocity = move_and_slide(velocity, Vector2())
- #-------------------MOVEMENT_INPUT--------------------------------------------
- func get_input_axis():
- var input_vector = Vector2()
- if !Jumping:
- punch = false
- input_vector.x = int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left"))
- input_vector.y = int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
- if input_vector.x > 0:
- animatedSprite.flip_h = false
- elif input_vector.x < 0:
- animatedSprite.flip_h = true
- return input_vector
- #velocity = velocity.clamped(MAX_SPEED)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement