rename consistency

This commit is contained in:
2025-08-19 19:57:24 -05:00
parent e74896527b
commit 379c7007aa
56 changed files with 43 additions and 36 deletions

125
entity/EntityMovement.gd Normal file
View File

@@ -0,0 +1,125 @@
class_name EntityMovement extends Node
const SPEED = 64.0
const FRICTION = 0.01
enum FacingDirection {
SOUTH = 0,
EAST = 1,
NORTH = 2,
WEST = 3
};
const FacingDirWalkAnimations = {
FacingDirection.SOUTH: "walk_south",
FacingDirection.EAST: "walk_east",
FacingDirection.NORTH: "walk_north",
FacingDirection.WEST: "walk_west"
};
const FacingDirAngle = {
FacingDirection.SOUTH: 0.0,
FacingDirection.EAST: PI / 2,
FacingDirection.NORTH: PI,
FacingDirection.WEST: -PI / 2
};
@export var body:CharacterBody3D
@export var rotate:Node3D
@export var sprite:AnimatedSprite3D
var facingDir:FacingDirection = FacingDirection.SOUTH
var inputDir:Vector2 = Vector2.ZERO
func _enter_tree() -> void:
if !sprite:
return
for dir in FacingDirWalkAnimations:
if sprite.animation != FacingDirWalkAnimations[dir]:
continue
facingDir = dir
break
func canMove() -> bool:
return true
func applyFacingDir() -> void:
if !sprite || inputDir.length() <= 0.01:
return
if inputDir.y > 0:
if facingDir != FacingDirection.NORTH && inputDir.x != 0:
if inputDir.x > 0 && facingDir == FacingDirection.EAST:
facingDir = FacingDirection.EAST
elif inputDir.x < 0 && facingDir == FacingDirection.WEST:
facingDir = FacingDirection.WEST
else:
facingDir = FacingDirection.NORTH
else:
facingDir = FacingDirection.NORTH
elif inputDir.y < 0:
if facingDir != FacingDirection.SOUTH && inputDir.x != 0:
if inputDir.x > 0 && facingDir == FacingDirection.EAST:
facingDir = FacingDirection.EAST
elif inputDir.x < 0 && facingDir == FacingDirection.WEST:
facingDir = FacingDirection.WEST
else:
facingDir = FacingDirection.SOUTH
else:
facingDir = FacingDirection.SOUTH
elif inputDir.x > 0:
facingDir = FacingDirection.EAST
else:
facingDir = FacingDirection.WEST
sprite.animation = FacingDirWalkAnimations[facingDir]
func applyGravity() -> void:
if !body.is_on_floor():
body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
func applyMovement() -> void:
if !canMove():
return
var cameraCurrent = get_viewport().get_camera_3d()
if !cameraCurrent:
return
# Use camera orientation for movement direction
var camBasis = cameraCurrent.global_transform.basis
# Forward and right vectors, ignore vertical component
var forward = -camBasis.z
forward.y = 0
forward = forward.normalized()
var right = camBasis.x
right.y = 0
right = right.normalized()
var directionAdjusted = (
forward * inputDir.y + right * inputDir.x
).normalized()
if directionAdjusted.length() <= 0.01:
return
if rotate:
var targetRot = atan2(directionAdjusted.x, directionAdjusted.z)
rotate.rotation.y = targetRot
body.velocity.x = directionAdjusted.x * SPEED
body.velocity.z = directionAdjusted.z * SPEED
func applyFriction(delta:float) -> void:
body.velocity.x *= delta * FRICTION
body.velocity.z *= delta * FRICTION
func _physics_process(delta:float) -> void:
if !body:
return
applyGravity()
applyFriction(delta)
applyMovement()
applyFacingDir()
body.move_and_slide()

View File

@@ -0,0 +1 @@
uid://b38dxsome4kiq

1
entity/MapCamera.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://csb0i132lcu0w

1
entity/NPC.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://jbarxyoib5a7

1
entity/Player.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://c0by5m1upv57h

6
entity/npc/NPC.gd Normal file
View File

@@ -0,0 +1,6 @@
class_name NPC extends CharacterBody3D
@export var interactEvent:EventResource
func _onInteract(playerEntity: Player) -> void:
pass

1
entity/npc/NPC.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://crw7ls7t8cwct

95
entity/npc/NPC.tscn Normal file
View File

@@ -0,0 +1,95 @@
[gd_scene load_steps=12 format=3 uid="uid://kabs7mopalmo"]
[ext_resource type="Script" uid="uid://crw7ls7t8cwct" path="res://entity/npc/NPC.gd" id="1_00k55"]
[ext_resource type="Script" uid="uid://b00rxpveu3v4m" path="res://InteractableArea.gd" id="2_x8luf"]
[ext_resource type="Script" uid="uid://tlfthv88ki0y" path="res://entity/npc/NPCMovement.gd" id="3_1seh5"]
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entity/player/Player.png" id="4_x8luf"]
[sub_resource type="BoxShape3D" id="BoxShape3D_1seh5"]
size = Vector3(16, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_rl6fg"]
atlas = ExtResource("4_x8luf")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_q57vx"]
atlas = ExtResource("4_x8luf")
region = Rect2(48, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_ak4un"]
atlas = ExtResource("4_x8luf")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_1ms0h"]
atlas = ExtResource("4_x8luf")
region = Rect2(32, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_1seh5"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_rl6fg")
}],
"loop": true,
"name": &"walk_east",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_q57vx")
}],
"loop": true,
"name": &"walk_north",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ak4un")
}],
"loop": true,
"name": &"walk_south",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_1ms0h")
}],
"loop": true,
"name": &"walk_west",
"speed": 5.0
}]
[sub_resource type="SphereShape3D" id="SphereShape3D_x8luf"]
radius = 8.5
[node name="NPC" type="CharacterBody3D"]
script = ExtResource("1_00k55")
[node name="Scripts" type="Node" parent="."]
[node name="NPCMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("body", "sprite")]
script = ExtResource("3_1seh5")
body = NodePath("../..")
sprite = NodePath("../../AnimatedSprite3D")
[node name="InteractableArea" type="Area3D" parent="."]
script = ExtResource("2_x8luf")
metadata/_custom_type_script = "uid://b00rxpveu3v4m"
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractableArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 0)
shape = SubResource("BoxShape3D_1seh5")
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="."]
pixel_size = 1.0
axis = 1
double_sided = false
texture_filter = 0
sprite_frames = SubResource("SpriteFrames_1seh5")
animation = &"walk_west"
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8.5, 0)
shape = SubResource("SphereShape3D_x8luf")
[connection signal="interactEvent" from="InteractableArea" to="." method="_onInteract"]

View File

@@ -0,0 +1 @@
uid://dda6r22r8eow2

View File

@@ -0,0 +1 @@
class_name NPCMovement extends "res://entities/EntityMovement.gd"

View File

@@ -0,0 +1 @@
uid://tlfthv88ki0y

5
entity/npc/NPCTest.gd Normal file
View File

@@ -0,0 +1,5 @@
class_name NPCTest extends Node
func onInteract(playerEntity: Player) -> void:
print("Player has interacted with the NPC.")
UI.TEXTBOX.setText("You have interacted with the NPC.")

View File

@@ -0,0 +1 @@
uid://cmwovncvo1n5o

1
entity/player/Player.gd Normal file
View File

@@ -0,0 +1 @@
class_name Player extends CharacterBody3D

View File

@@ -0,0 +1 @@
uid://ylmy3nvpirgr

BIN
entity/player/Player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

View File

@@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://xx3qp5xh7tgu"
path.s3tc="res://.godot/imported/Player.png-44a553acafadade6fc26fd4f7692a8d9.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://entity/player/Player.png"
dest_files=["res://.godot/imported/Player.png-44a553acafadade6fc26fd4f7692a8d9.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

114
entity/player/Player.tscn Normal file
View File

@@ -0,0 +1,114 @@
[gd_scene load_steps=14 format=3 uid="uid://2ch34sio36nv"]
[ext_resource type="Script" uid="uid://ylmy3nvpirgr" path="res://entity/player/Player.gd" id="1_24gqh"]
[ext_resource type="Script" uid="uid://bwxdv3kxrs4oj" path="res://entity/player/PlayerMovement.gd" id="2_o7et6"]
[ext_resource type="Script" uid="uid://b3nty7pvbo58d" path="res://entity/player/PlayerInteraction.gd" id="3_24gqh"]
[ext_resource type="Script" uid="uid://bdv1fj1pwknrs" path="res://entity/player/PlayerInput.gd" id="4_yjynp"]
[ext_resource type="Script" uid="uid://bdjgvyiacbg28" path="res://entity/player/PlayerCamera.gd" id="5_g3lhm"]
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entity/player/Player.png" id="7_fmb3c"]
[sub_resource type="SphereShape3D" id="SphereShape3D_4pwj0"]
radius = 8.5
[sub_resource type="AtlasTexture" id="AtlasTexture_rl6fg"]
atlas = ExtResource("7_fmb3c")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_q57vx"]
atlas = ExtResource("7_fmb3c")
region = Rect2(48, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_ak4un"]
atlas = ExtResource("7_fmb3c")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_1ms0h"]
atlas = ExtResource("7_fmb3c")
region = Rect2(32, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_2rv2u"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_rl6fg")
}],
"loop": true,
"name": &"walk_east",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_q57vx")
}],
"loop": true,
"name": &"walk_north",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ak4un")
}],
"loop": true,
"name": &"walk_south",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_1ms0h")
}],
"loop": true,
"name": &"walk_west",
"speed": 5.0
}]
[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
size = Vector3(10, 16, 8)
[node name="Player" type="CharacterBody3D"]
script = ExtResource("1_24gqh")
[node name="Scripts" type="Node" parent="."]
[node name="PlayerMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("body", "rotate", "sprite")]
script = ExtResource("2_o7et6")
body = NodePath("../..")
rotate = NodePath("../../PlayerRotated")
sprite = NodePath("../../AnimatedSprite3D")
[node name="PlayerInteraction" type="Node" parent="Scripts" node_paths=PackedStringArray("interactableArea", "player")]
script = ExtResource("3_24gqh")
interactableArea = NodePath("../../PlayerRotated/PlayerInteractableArea")
player = NodePath("../..")
[node name="PlayerInput" type="Node" parent="Scripts" node_paths=PackedStringArray("interaction", "movement")]
script = ExtResource("4_yjynp")
interaction = NodePath("../PlayerInteraction")
movement = NodePath("../PlayerMovement")
[node name="PlayerCamera" type="Node" parent="Scripts" node_paths=PackedStringArray("camera", "target")]
script = ExtResource("5_g3lhm")
camera = NodePath("../../PlayerCamera")
target = NodePath("../..")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8.5, 0)
shape = SubResource("SphereShape3D_4pwj0")
[node name="PlayerCamera" type="Camera3D" parent="."]
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0496178, 0, -0.00852585)
pixel_size = 1.0
axis = 1
double_sided = false
texture_filter = 0
sprite_frames = SubResource("SpriteFrames_2rv2u")
animation = &"walk_south"
[node name="PlayerRotated" type="Node3D" parent="."]
[node name="PlayerInteractableArea" type="Area3D" parent="PlayerRotated"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerRotated/PlayerInteractableArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 10)
shape = SubResource("BoxShape3D_g13of")

View File

@@ -0,0 +1,29 @@
class_name PlayerCamera extends Node
const CAMERA_PIXELS_PER_UNIT = 1.0
const CAMERA_PIXEL_SCALE = 1.0
@export var camera:Camera3D = null
@export var target:Node3D = null
@export var offset:Vector3 = Vector3(0, 0, 12)
func _process(delta: float) -> void:
# I tried a few things but this is most consistent for both backbuffer and
# framebuffer viewports.
var viewportHeight = get_viewport().get_visible_rect().size.y;
var unitScale = CAMERA_PIXEL_SCALE * CAMERA_PIXELS_PER_UNIT;
var z:float = (
tan((deg_to_rad(180) - deg_to_rad(camera.fov)) / 2.0) *
(viewportHeight / 2.0)
) / unitScale;
var look = target.global_position;
var position = offset + look;
camera.look_at_from_position(
Vector3(position.x, position.y + z, position.z),
look
);
pass

View File

@@ -0,0 +1 @@
uid://bdjgvyiacbg28

View File

@@ -0,0 +1,13 @@
class_name PlayerInput extends Node
@export var interaction:PlayerInteraction
@export var movement:PlayerMovement
func _process(delta: float) -> void:
if Input.is_action_just_pressed("pause"):
PAUSE.menuPause()
if Input.is_action_just_pressed("interact"):
interaction.interact()
movement.inputDir = Input.get_vector("move_left", "move_right", "move_back", "move_forward").normalized()

View File

@@ -0,0 +1 @@
uid://bdv1fj1pwknrs

View File

@@ -0,0 +1,27 @@
class_name PlayerInteraction extends Node
@export var interactableArea:Area3D
@export var player:CharacterBody3D
func canInteract() -> bool:
if PAUSE.isMovementPaused():
return false
return true
func interact() -> void:
if !canInteract():
return
var overlapping = interactableArea.get_overlapping_areas()
var interactable: InteractableArea = null
for node in overlapping:
if !(node is InteractableArea):
continue
interactable = node
break
if !interactable:
return
interactable.interactEvent.emit(player)

View File

@@ -0,0 +1 @@
uid://b3nty7pvbo58d

View File

@@ -0,0 +1,13 @@
[gd_resource type="ShaderMaterial" load_steps=3 format=3 uid="uid://cv8q4cbjyfauh"]
[ext_resource type="Shader" path="res://materials/EntityMaterialShader.gdshader" id="1_gsq3s"]
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entity/player/Player.png" id="2_awgof"]
[resource]
render_priority = 0
shader = ExtResource("1_gsq3s")
shader_parameter/text = ExtResource("2_awgof")
shader_parameter/tileColumnCount = 4
shader_parameter/tileRowCount = 1
shader_parameter/tile = 0
shader_parameter/color = Color(1, 1, 1, 1)

View File

@@ -0,0 +1,6 @@
class_name PlayerMovement extends "res://entities/EntityMovement.gd"
func canMove() -> bool:
if PAUSE.isMovementPaused():
return false
return true

View File

@@ -0,0 +1 @@
uid://bwxdv3kxrs4oj