Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- var walkTexture = null
- export var canMove = true
- var isMoving = false
- var facing = DIRECTION.DOWN
- var move_direction = Vector2()
- var action
- var direction
- var movement_type
- var movement_speed
- var state
- enum STATE {
- IDLE,
- MOVE,
- FISH
- }
- enum MOVEMENT_TYPE {
- FOOT,
- BIKE,
- SURF,
- SCUBA
- }
- enum MOVEMENT_SPEED {
- NORMAL,
- FAST
- }
- enum DIRECTION{
- DOWN,
- LEFT,
- RIGHT,
- UP
- }
- func _ready():
- load_texture()
- func _process(delta):
- if !isMoving:
- if canMove and !Input.is_action_pressed("z"):
- get_input()
- func get_input():
- if Input.is_action_pressed("ui_down"):
- direction = DIRECTION.DOWN
- elif Input.is_action_pressed("ui_up"):
- direction = DIRECTION.UP
- elif Input.is_action_pressed("ui_left"):
- direction = DIRECTION.LEFT
- elif Input.is_action_pressed("ui_right"):
- direction = DIRECTION.RIGHT
- else:
- state = STATE.IDLE
- return
- state = STATE.MOVE
- if state == STATE.MOVE and movement_type == MOVEMENT_TYPE.FOOT and Input.is_action_pressed("run"):
- movement_speed = MOVEMENT_SPEED.FAST
- else:
- movement_speed = MOVEMENT_SPEED.NORMAL
- check_tile()
- func check_tile():
- if direction == DIRECTION.DOWN:
- move_direction = Vector2(0, 32)
- elif direction == DIRECTION.UP:
- move_direction = Vector2(0, -32)
- elif direction == DIRECTION.LEFT:
- move_direction = Vector2(-32, 0)
- elif direction == DIRECTION.RIGHT:
- move_direction = Vector2(32, 0)
- $RayCast2D.cast_to = move_direction
- if !$RayCast2D.is_colliding():
- move()
- func move():
- set_process(false)
- # Start Animation
- if direction == DIRECTION.DOWN:
- $AnimationPlayer.play("Down")
- elif direction == DIRECTION.UP:
- $AnimationPlayer.play("Up")
- elif direction == DIRECTION.LEFT:
- $AnimationPlayer.play("Left")
- elif direction == DIRECTION.RIGHT:
- $AnimationPlayer.play("Right")
- # Set Tween settings and set position instantly
- $Tween.interpolate_property($Position2D, "position", - move_direction, Vector2(), $AnimationPlayer.current_animation_length, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
- position = position + move_direction
- # Start Tween
- $Tween.start()
- # Wait Till animation finished
- yield($AnimationPlayer, "animation_finished")
- set_process(true)
- pass
- func load_texture():
- if Global.TrainerGender == 0:
- walkTexture = preload("res://Graphics/Characters/HERO.png")
- if Global.TrainerGender == 1:
- walkTexture = preload("res://Graphics/Characters/PU-Pluto.png")
- if Global.TrainerGender == 2:
- walkTexture = preload("res://Graphics/Characters/HEROINE.png")
- $Position2D/Sprite.texture = walkTexture
- $Position2D/Sprite.frame = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement