Godsim/scripts/God.gd

73 lines
2.1 KiB
GDScript3
Raw Normal View History

2024-05-30 02:14:08 +03:00
extends Node3D
const SENSETIVITY = 0.009;
var walk = 0.25
@onready var head = $"."
@onready var camera = $"./Camera"
2024-05-30 07:22:27 +03:00
2024-05-30 02:14:08 +03:00
@onready var ui = $"./UI"
@onready var velocity_label: Label = ui.find_child("velocity_label")
2024-05-30 07:22:27 +03:00
@onready var tile_type_label: Label = ui.find_child("tile_type_label")
2024-05-30 06:55:13 +03:00
@onready var eye_raycast: RayCast3D = $"./Camera/eye"
@onready var earth = $"../Earth"
2024-05-30 02:14:08 +03:00
2024-05-30 07:22:27 +03:00
enum TileType {
Empty,
Plain,
Forest
}
var creating_tile_type = TileType.Plain
2024-05-30 02:14:08 +03:00
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()
2024-05-30 02:14:08 +03:00
var velocity = Vector3.ZERO
var speed
2024-05-30 07:22:27 +03:00
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])
2024-05-31 22:46:56 +03:00
if Input.is_action_just_pressed("LMC") and eye_raycast.is_colliding() and !get_node("UI/ingame_menu").visible:
2024-05-30 06:55:13 +03:00
var target = eye_raycast.get_collider()
2024-05-30 07:22:27 +03:00
if "TileType" in target:
2024-05-31 22:46:56 +03:00
earth.mark_free_tiles()
2024-05-30 07:22:27 +03:00
target.tile_type = creating_tile_type
2024-05-30 06:55:13 +03:00
target.update_tile()
earth.mark_free_tiles()
2024-05-31 22:46:56 +03:00
2024-05-30 02:14:08 +03:00
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