You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.7 KiB
78 lines
1.7 KiB
3 years ago
|
extends KinematicBody2D
|
||
|
|
||
3 years ago
|
|
||
|
# Declare member variables here. Examples:
|
||
|
# var a = 2
|
||
|
# var b = "text"
|
||
|
var curHp : int = 10
|
||
|
var maxHp : int = 10
|
||
|
var moveSpeed : int = 180
|
||
|
var damage : int = 1
|
||
|
var gold : int = 0
|
||
|
var curLevel : int = 0
|
||
|
var curXp : int = 0
|
||
|
var xpToNextLevel : int = 50
|
||
|
var xpToLevelIncreaseRate : float = 1.2
|
||
3 years ago
|
var interactDist : int = 70
|
||
|
var vel = Vector2()
|
||
|
var facingDir = Vector2()
|
||
|
onready var rayCast = $RayCast2D
|
||
|
onready var anim = $AnimatedSprite
|
||
|
|
||
3 years ago
|
# Called when the node enters the scene tree for the first time.
|
||
|
func _ready():
|
||
|
pass # Replace with function body.
|
||
|
|
||
3 years ago
|
func _physics_process (delta):
|
||
|
|
||
|
vel = Vector2()
|
||
|
|
||
|
# inputs
|
||
|
if Input.is_action_pressed("move_up"):
|
||
3 years ago
|
vel.y -= 1
|
||
3 years ago
|
facingDir = Vector2(0, -1)
|
||
|
if Input.is_action_pressed("move_down"):
|
||
3 years ago
|
vel.y += 1
|
||
3 years ago
|
facingDir = Vector2(0, 1)
|
||
|
if Input.is_action_pressed("move_left"):
|
||
3 years ago
|
vel.x -= 1
|
||
3 years ago
|
facingDir = Vector2(-1, 0)
|
||
|
if Input.is_action_pressed("move_right"):
|
||
3 years ago
|
vel.x += 1
|
||
3 years ago
|
facingDir = Vector2(1, 0)
|
||
|
|
||
|
# normalize the velocity to prevent faster diagonal movement
|
||
|
vel = vel.normalized()
|
||
|
|
||
|
# move the player
|
||
|
move_and_slide(vel * moveSpeed, Vector2.ZERO)
|
||
|
manage_animations()
|
||
|
|
||
|
func play_animation (anim_name):
|
||
|
|
||
|
if anim.animation != anim_name:
|
||
|
anim.play(anim_name)
|
||
|
|
||
|
func manage_animations ():
|
||
|
|
||
|
if vel.x > 0:
|
||
|
play_animation("MoveRight")
|
||
|
elif vel.x < 0:
|
||
|
play_animation("MoveLeft")
|
||
|
elif vel.y < 0:
|
||
|
play_animation("MoveUp")
|
||
|
elif vel.y > 0:
|
||
|
play_animation("MoveDown")
|
||
|
elif facingDir.x == 1:
|
||
|
play_animation("IdleRight")
|
||
|
elif facingDir.x == -1:
|
||
|
play_animation("IdleLeft")
|
||
|
elif facingDir.y == -1:
|
||
|
play_animation("IdleUp")
|
||
|
elif facingDir.y == 1:
|
||
|
play_animation("IdleDown")
|
||
3 years ago
|
|
||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||
|
#func _process(delta):
|
||
|
# pass
|