Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class_name Player
- extends KinematicBody2D
- #export (int) var speed = 120
- #export (int) var jump_speed = -180
- #export (int) var gravity = 400
- #
- #export (float, 0, 1.0) var friction = 0.1
- #export (float, 0, 1.0) var acceleration = 0.25
- #
- #var velocity = Vector2.ZERO
- #
- #func get_input():
- # var dir = 0
- # if Input.is_action_pressed("move_right"):
- # dir += 1
- # if Input.is_action_pressed("move_left"):
- # dir -= 1
- # if dir != 0:
- # velocity.x = lerp(velocity.x, dir * speed, acceleration)
- # else:
- # velocity.x = lerp(velocity.x, 0, friction)
- #
- #
- #func _physics_process(delta):
- # get_input()
- # velocity.y += gravity * delta
- # velocity = move_and_slide(velocity, Vector2.UP)
- # if Input.is_action_just_pressed("jump"):
- # if is_on_floor():
- # velocity.y = jump_speed
- ############################################################################################################################################
- #const MAXFALLSPEED = 200
- #const MAXSPEED = 80
- #const JUMPFORCE = 375
- export (int) var speed = 1200
- export (int) var jump_speed = -1800
- export (int) var gravity = 4000
- #var is_on_floor = 0
- #var state_machine
- var attacks = ["Sword Slash","Sword Slash Down"]
- var velocity = Vector2.ZERO
- var sworddrawn = false
- func _ready():
- state_machine = $AnimationTree.get("parameters/playback")
- $AnimationTree["parameters/conditions/Landed"] = 0
- func get_input():
- var current = state_machine.get_current_node()
- velocity.y += _gravity
- if velocity.y > MAXFALLSPEED:
- velocity.y = MAXFALLSPEED
- elif velocity.y > 0:
- state_machine.travel("fall 2")
- else:
- if sworddrawn && current == "idle":
- state_machine.travel("idle-2")
- if Input.is_action_just_pressed("Light Attack"):
- if (current == "idle-2" || current == "walk 2"):
- state_machine.travel(attacks[randi()%2])
- return
- elif current == "idle":
- state_machine.travel("punch")
- return
- elif current == "walk":
- state_machine.travel("run-punch")
- return
- if Input.is_action_just_pressed("Heavy Attack"):
- if (current == "idle-2" || current == "walk 2"):
- state_machine.travel("attack1")
- return
- elif current == "idle":
- state_machine.travel("kick")
- return
- if Input.is_action_just_pressed("Draw Sword Sheathe Sword"):
- if sworddrawn:
- state_machine.travel("idle")
- sworddrawn = false
- elif !sworddrawn:
- state_machine.travel("idle-2")
- sworddrawn = true
- if is_on_floor:
- if Input.is_action_pressed("move_right"):
- if sworddrawn:
- state_machine.travel("walk 2")
- if not sworddrawn:
- state_machine.travel("walk")
- velocity.x = MAXSPEED
- $Sprite.scale.x = 1
- elif Input.is_action_pressed("move_left"):
- if sworddrawn:
- state_machine.travel("walk 2")
- if not sworddrawn:
- state_machine.travel("walk")
- velocity.x = -MAXSPEED
- $Sprite.scale.x = -1
- else:
- velocity.x = 0
- if sworddrawn:
- state_machine.travel("idle-2")
- elif not sworddrawn:
- state_machine.travel("idle")
- if Input.is_action_just_pressed("jump"):
- state_machine.travel("jump")
- velocity.y = -JUMPFORCE
- if Input.is_action_pressed("move_right"):
- velocity.x = MAXSPEED
- $Sprite.scale.x = 1
- elif Input.is_action_pressed("move_left"):
- velocity.x = -MAXSPEED
- $Sprite.scale.x = -1
- else:
- velocity.x = 0
- velocity = move_and_slide(velocity,vector2.UP)
- func _physics_process(delta):
- # if $RayCast2D.is_colliding():
- # is_on_floor = 1
- # $AnimationTree["parameters/conditions/Landed"] = 1
- #
- # if not $RayCast2D.is_colliding():
- # is_on_floor = 0
- # $AnimationTree["parameters/conditions/Landed"] = 0
- var current = state_machine.get_current_node()
- velocity.y += _gravity
- if velocity.y > MAXFALLSPEED:
- velocity.y = MAXFALLSPEED
- elif velocity.y > 0:
- state_machine.travel("fall 2")
- else:
- if sworddrawn && current == "idle":
- state_machine.travel("idle-2")
- if Input.is_action_just_pressed("Light Attack"):
- if (current == "idle-2" || current == "walk 2"):
- state_machine.travel(attacks[randi()%2])
- return
- elif current == "idle":
- state_machine.travel("punch")
- return
- elif current == "walk":
- state_machine.travel("run-punch")
- return
- if Input.is_action_just_pressed("Heavy Attack"):
- if (current == "idle-2" || current == "walk 2"):
- state_machine.travel("attack1")
- return
- elif current == "idle":
- state_machine.travel("kick")
- return
- if Input.is_action_just_pressed("Draw Sword Sheathe Sword"):
- if sworddrawn:
- state_machine.travel("idle")
- sworddrawn = false
- elif !sworddrawn:
- state_machine.travel("idle-2")
- sworddrawn = true
- if is_on_floor:
- if Input.is_action_pressed("move_right"):
- if sworddrawn:
- state_machine.travel("walk 2")
- if not sworddrawn:
- state_machine.travel("walk")
- velocity.x = MAXSPEED
- $Sprite.scale.x = 1
- elif Input.is_action_pressed("move_left"):
- if sworddrawn:
- state_machine.travel("walk 2")
- if not sworddrawn:
- state_machine.travel("walk")
- velocity.x = -MAXSPEED
- $Sprite.scale.x = -1
- else:
- velocity.x = 0
- if sworddrawn:
- state_machine.travel("idle-2")
- elif not sworddrawn:
- state_machine.travel("idle")
- if Input.is_action_just_pressed("jump"):
- state_machine.travel("jump")
- velocity.y = -JUMPFORCE
- if Input.is_action_pressed("move_right"):
- velocity.x = MAXSPEED
- $Sprite.scale.x = 1
- elif Input.is_action_pressed("move_left"):
- velocity.x = -MAXSPEED
- $Sprite.scale.x = -1
- else:
- velocity.x = 0
- velocity = move_and_slide(velocity,vector2.UP)
- func hurt():
- state_machine.travel("hurt")
- func die():
- state_machine.travel("die")
- set_physics_process(false)
- #const GRAVITY = 100.0
- #const WALK_SPEED = 200
- #const Jump_speed = 40
- #
- #var velocity = Vector2()
- #var is_on_floor = 0
- #onready var _animation_player = $AnimationPlayer
- #
- #func _physics_process(delta):
- # velocity.y += delta * GRAVITY
- #
- # if $RayCast2D.is_colliding():
- # is_on_floor = 1
- #
- # if Input.is_action_pressed("move_left"):
- # velocity.x = -WALK_SPEED
- # elif Input.is_action_pressed("move_right"):
- # velocity.x = WALK_SPEED
- # elif Input.is_action_just_released("jump")&& is_on_floor():
- # velocity.y = -Jump_speed * delta
- # else:
- # velocity.x = 0
- #
- # # We dont need to multiply velocity by delta because "move_and_slide" already takes delta time into account.
- #
- #
- # # The second parameter of "move_and_slide" is the normal pointing up.
- # # In the case of a 2D platformer, in Godot, upward is negative y, which translates to -1 as a normal.
- # move_and_slide(velocity, Vector2(0, -1))
- #
- #func _process(_delta):#(Input.is_action_pressed("move_left") or Input.is_action_pressed("move_right"))
- # if Input.is_action_pressed("move_right") && is_on_floor():
- # $Sprite.flip_h = false
- # _animation_player.play("walk")
- # elif Input.is_action_pressed("move_left")&& is_on_floor():
- # $Sprite.flip_h = true
- # _animation_player.play("walk")
- # elif Input.is_action_just_released("jump")&& is_on_floor():
- # _animation_player.play("jump")
- # elif is_on_floor == 1:
- # _animation_player.play("idle")
- #region
- #func get_input():
- #
- # var current = state_machine.get_current_node()
- # velocity = Vector2.ZERO
- #
- # if Input.is_action_just_pressed("Light Attack") && (current == "idle-2" || current == "walk 2"):
- # state_machine.travel("Sword Slash")
- # return
- #
- # if Input.is_action_just_pressed("Light Attack") && current == "idle":
- # state_machine.travel("punch")
- # return
- #
- # if Input.is_action_just_pressed("Light Attack") && current == "walk":
- # state_machine.travel("run-punch")
- # return
- #
- # if Input.is_action_just_pressed("Heavy Attack") && (current == "idle-2" || current == "walk 2"):
- # state_machine.travel("Sword Slash Down")
- # return
- #
- # if Input.is_action_just_pressed("Heavy Attack") && current == "idle":
- # state_machine.travel("kick")
- # return
- #
- # if Input.is_action_just_pressed("Draw Sword Sheathe Sword"):
- #
- # if sworddrawn:
- # state_machine.travel("Sword Away")
- # sworddrawn = false
- # $AnimationTree["parameters/conditions/swordisdrawn"] = false
- #
- # elif !sworddrawn:
- # state_machine.travel("Sword Draw")
- # sworddrawn = true
- # $AnimationTree["parameters/conditions/swordisdrawn"] = true
- #
- # print(sworddrawn)
- # if Input.is_action_pressed("move_right"):
- #
- # if current == "idle-2":
- # state_machine.travel("walk 2")
- #
- # if current == "idle":
- # state_machine.travel("walk")
- #
- # velocity.x += 1
- # $Sprite.scale.x = 1
- #
- # if Input.is_action_pressed("move_left"):
- #
- # if current == "idle-2":
- # state_machine.travel("walk 2")
- #
- # if current == "idle":
- # state_machine.travel("walk")
- #
- # velocity.x -= 1
- # $Sprite.scale.x = -1
- #
- # if Input.is_action_just_pressed("jump"):
- # state_machine.travel("jump")
- # velocity.y = -Jump_speed
- #
- # return
- #
- # #velocity = velocity.normalized() * run_speed
- #
- # if velocity.length() != 0 && sworddrawn:
- # state_machine.travel("walk 2")
- #
- # elif velocity.length() != 0 && not sworddrawn:
- # state_machine.travel("walk")
- #
- # if velocity.length() == 0 && sworddrawn:
- # state_machine.travel("idle-2")
- #
- # elif velocity.length() == 0 && not sworddrawn:
- # state_machine.travel("idle")
- ##end region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement