73 lines
2.1 KiB
GDScript
73 lines
2.1 KiB
GDScript
extends Node3D
|
|
|
|
const SENSETIVITY = 0.009;
|
|
var walk = 0.25
|
|
@onready var head = $"."
|
|
@onready var camera = $"./Camera"
|
|
|
|
@onready var ui = $"./UI"
|
|
@onready var velocity_label: Label = ui.find_child("velocity_label")
|
|
@onready var tile_type_label: Label = ui.find_child("tile_type_label")
|
|
|
|
@onready var eye_raycast: RayCast3D = $"./Camera/eye"
|
|
@onready var earth = $"../Earth"
|
|
|
|
enum TileType {
|
|
Empty,
|
|
Plain,
|
|
Forest
|
|
}
|
|
|
|
var creating_tile_type = TileType.Plain
|
|
|
|
func _ready():
|
|
camera.make_current()
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
func _unhandled_input(event):
|
|
if Input.is_action_pressed("MWU"):
|
|
walk += walk / 5.
|
|
if Input.is_action_pressed("MWD"):
|
|
walk -= walk / 5.
|
|
|
|
walk = clamp(snapped(walk, 0.0005), 0.01, 15)
|
|
|
|
if event is InputEventMouseMotion:
|
|
head.rotate_y(-event.relative.x * SENSETIVITY)
|
|
camera.rotate_x(-event.relative.y * SENSETIVITY)
|
|
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-90), deg_to_rad(90))
|
|
|
|
func _physics_process(delta):
|
|
velocity_label.text = "Velocity: " + str(walk)
|
|
|
|
var input_dir = Input.get_vector("left", "right", "forward", "backward")
|
|
var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
var velocity = Vector3.ZERO
|
|
var speed
|
|
|
|
if Input.is_action_just_pressed("tile type loop"):
|
|
creating_tile_type = wrap(creating_tile_type + 1, 0, 3)
|
|
tile_type_label.text = "Tile type: " + str(TileType.keys()[creating_tile_type])
|
|
|
|
if Input.is_action_just_pressed("LMC") and eye_raycast.is_colliding() and !get_node("UI/ingame_menu").visible:
|
|
var target = eye_raycast.get_collider()
|
|
if "TileType" in target:
|
|
#earth.mark_free_tiles()
|
|
target.tile_type = creating_tile_type
|
|
target.update_tile()
|
|
earth.mark_free_tiles()
|
|
|
|
|
|
if Input.is_action_pressed("run"):
|
|
speed = walk * 2
|
|
else:
|
|
speed = walk
|
|
velocity.y = Input.get_vector("down", "up", "left", "right").x * speed
|
|
if direction:
|
|
velocity.x = direction.x * speed
|
|
velocity.z = direction.z * speed
|
|
else:
|
|
velocity.x = lerp(velocity.x, direction.x * speed, delta * 4)
|
|
velocity.z = lerp(velocity.z, direction.z * speed, delta * 4)
|
|
head.position += velocity
|