2023-10-07 17:43:33 -07:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
|
|
|
|
|
|
|
var speed = 150
|
|
|
|
var accel = 10
|
|
|
|
var immobile = false
|
|
|
|
|
|
|
|
var inventory = {
|
2023-10-09 18:33:33 -07:00
|
|
|
"points": 0,
|
2023-10-07 17:43:33 -07:00
|
|
|
"stone": 0,
|
|
|
|
"wood": 0,
|
|
|
|
"food": 0
|
|
|
|
}
|
|
|
|
var status = {
|
|
|
|
"health": 100,
|
2023-10-09 18:33:33 -07:00
|
|
|
"stamina": 100,
|
|
|
|
"level": 1
|
2023-10-07 17:43:33 -07:00
|
|
|
}
|
2023-10-07 18:24:14 -07:00
|
|
|
var current_tool = "none"
|
2023-10-07 17:43:33 -07:00
|
|
|
|
|
|
|
|
2024-03-29 18:49:36 -07:00
|
|
|
func next_level_points():
|
2023-10-09 18:33:33 -07:00
|
|
|
return status.level*10
|
|
|
|
|
2023-10-07 18:24:14 -07:00
|
|
|
func change_tool(tool):
|
|
|
|
current_tool = tool
|
|
|
|
$body_pivot/body/tool.texture = load(game_data.tools[tool].image)
|
|
|
|
$body_pivot/body/tool.position = game_data.tools[tool].offset
|
|
|
|
|
|
|
|
func _ready():
|
2024-03-29 18:12:59 -07:00
|
|
|
change_tool("stick") # This is when the starting tool is set
|
2023-10-07 18:24:14 -07:00
|
|
|
|
2023-10-07 17:43:33 -07:00
|
|
|
func _physics_process(delta):
|
|
|
|
var pre_velocity = Vector2(0, 0)
|
|
|
|
if !immobile:
|
|
|
|
pre_velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
|
|
|
velocity = lerp(velocity, pre_velocity * speed, accel*delta)
|
|
|
|
move_and_slide()
|
|
|
|
|
2024-03-29 18:49:36 -07:00
|
|
|
func _process(_delta):
|
2023-10-07 17:43:33 -07:00
|
|
|
if Input.is_action_pressed("game_interact"):
|
|
|
|
if !$animation.is_playing():
|
|
|
|
$animation.play("hit")
|
|
|
|
if $body_pivot/raycast.is_colliding():
|
|
|
|
var hit_object = $body_pivot/raycast.get_collider()
|
|
|
|
if hit_object.type == "resource":
|
|
|
|
inventory[hit_object.resource_type] += 1
|
2023-10-09 18:33:33 -07:00
|
|
|
inventory.points += 1
|
2023-10-07 17:56:15 -07:00
|
|
|
hit_object.get_node("animation").play("hit")
|
2024-03-29 18:12:59 -07:00
|
|
|
|
|
|
|
# Update inventory HUD
|
2023-10-07 17:43:33 -07:00
|
|
|
$hud/inventory/stone_label.text = str(inventory.stone)
|
|
|
|
$hud/inventory/wood_label.text = str(inventory.wood)
|
2024-03-29 18:49:36 -07:00
|
|
|
$hud/level/points.text = str(inventory.points) + "/" + str(next_level_points())
|
2023-10-09 18:33:33 -07:00
|
|
|
$hud/level/level_bar.value = inventory.points
|
2024-03-29 18:12:59 -07:00
|
|
|
|
|
|
|
# Update status HUD
|
2023-10-09 18:33:17 -07:00
|
|
|
$hud/bars/health.value = status.health
|
|
|
|
$hud/bars/stamina.value = status.stamina
|
2023-10-09 18:33:33 -07:00
|
|
|
$hud/level/level.text = "Level " + str(status.level)
|
2024-03-29 18:49:36 -07:00
|
|
|
$hud/level/level_bar.max_value = next_level_points()
|
2024-03-29 18:12:59 -07:00
|
|
|
|
|
|
|
# Level up
|
2024-03-29 18:49:36 -07:00
|
|
|
if inventory.points >= (next_level_points()):
|
|
|
|
inventory.points -= next_level_points()
|
2023-10-09 18:33:33 -07:00
|
|
|
status.level += 1
|
2023-11-04 13:45:37 -07:00
|
|
|
level_up()
|
|
|
|
|
|
|
|
|
|
|
|
func level_up():
|
2024-03-29 18:49:36 -07:00
|
|
|
pass
|
2023-10-07 17:43:33 -07:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event is InputEventMouseMotion:
|
|
|
|
var mouse_pos = get_global_mouse_position()
|
|
|
|
$body_pivot.rotation = atan2((mouse_pos.y-position.y), (mouse_pos.x-position.x)) + (PI * 0.5)
|