pieces can rotate while moving

whe can color pieces dynamically

pieces have collider and can kill each other
This commit is contained in:
francis 2026-03-06 22:46:34 +01:00
parent 3ea7bfd5dc
commit 026d634c3a
18 changed files with 283 additions and 263 deletions

View file

@ -1,14 +0,0 @@
[gd_scene format=3 uid="uid://dsc2tova7rvx7"]
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="2_bmony"]
[ext_resource type="Material" uid="uid://bxg7bjgiqfnru" path="res://Materials/piece_black.tres" id="2_r76xr"]
[ext_resource type="ArrayMesh" uid="uid://c67nw3hvqrkev" path="res://Models/bishop.obj" id="3_r76xr"]
[node name="Bishop" type="Node3D" unique_id=1605941411]
script = ExtResource("2_bmony")
color = ExtResource("2_r76xr")
[node name="mesh" type="MeshInstance3D" parent="." unique_id=830382749]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, 0, 0)
material_override = ExtResource("2_r76xr")
mesh = ExtResource("3_r76xr")

View file

@ -1,13 +0,0 @@
[gd_scene format=3 uid="uid://qjo2ij73xlok"]
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="1_ycl1t"]
[ext_resource type="Material" uid="uid://bxg7bjgiqfnru" path="res://Materials/piece_black.tres" id="2_5ys0t"]
[ext_resource type="ArrayMesh" uid="uid://bxtpbpxglphok" path="res://Models/king.obj" id="3_2gso2"]
[node name="King" type="Node3D" unique_id=1224931075]
script = ExtResource("1_ycl1t")
[node name="mesh" type="MeshInstance3D" parent="." unique_id=455294172]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 0, 0, 0)
material_override = ExtResource("2_5ys0t")
mesh = ExtResource("3_2gso2")

View file

@ -1,12 +0,0 @@
[gd_scene format=3 uid="uid://di3qg1qnmy0p2"]
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="1_qbtkq"]
[ext_resource type="Material" uid="uid://bxg7bjgiqfnru" path="res://Materials/piece_black.tres" id="2_cka4e"]
[ext_resource type="ArrayMesh" uid="uid://hnlwpehvi3ok" path="res://Models/kight.obj" id="3_0w1en"]
[node name="Knight" type="Node3D" unique_id=1333208927]
script = ExtResource("1_qbtkq")
[node name="mesh" type="MeshInstance3D" parent="." unique_id=515809374]
material_override = ExtResource("2_cka4e")
mesh = ExtResource("3_0w1en")

2
Scene/Pieces/pawn.tscn Executable file → Normal file
View file

@ -1,4 +1,4 @@
[gd_scene format=3 uid="uid://dkl8itq74sajx"]
[gd_scene format=3 uid="uid://b5qpodbykrgqw"]
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="1_nci4k"]
[ext_resource type="ArrayMesh" uid="uid://dn2vs5onakx6i" path="res://Models/pawn.obj" id="3_un5ic"]

View file

@ -4,18 +4,21 @@ extends Node3D
@export var piece_res : PieceRes
var is_moving : bool = false
var is_rotating: bool = false
var rotation_target: Vector3
var target : Vector2
var start_pos :Vector3
var start_coord: Vector2i
var mesh_instance_3d: MeshInstance3D
var possible_movements: Array[Vector2i]
#@export var color : StandardMaterial3D = preload("uid://brrbuo0i0e5bh") as StandardMaterial3D:
#set(material):
#color = material
#if Engine.is_editor_hint():
#mesh.material_override = color
#get:
#return color
@export var team: String = "us"
const PIECE_WHITE = preload("uid://brrbuo0i0e5bh")
const PIECE_RED = preload("uid://bekkxcgjt3hct")
const PIECE_BLACK = preload("uid://bxg7bjgiqfnru")
@onready var attack_area_3d: Area3D = $AttackArea3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for rule in piece_res.rules:
@ -23,9 +26,15 @@ func _ready() -> void:
print(piece_res.material)
var mesh_instance = MeshInstance3D.new()
mesh_instance.mesh = piece_res.mesh
mesh_instance.mesh.surface_set_material(0,piece_res.material)
add_child(mesh_instance)
mesh_instance_3d = mesh_instance
if team == "us":
add_to_group("PlayerPieces")
mesh_instance_3d.material_override = PIECE_WHITE
if team == "them":
print("dadwdawf<sef")
add_to_group("Enemy")
mesh_instance_3d.material_override = PIECE_RED
start_coord = to_coord()
@ -56,7 +65,11 @@ func _process(delta: float) -> void:
if position.z == target.y and position.x == target.x:
is_moving = false
pass
if is_rotating:
if rotation_target == rotation:
is_moving = true
pass
pass
func move_to(new_target: Vector2):
@ -66,12 +79,33 @@ func move_to(new_target: Vector2):
#possible_movements = [Vector2i(0,1)]
target = new_target * 2
start_pos = position
#var angle = atan2((position.z - target.y),(position.x- target.x))
#rotation.y = angle
#rotate_y(angle)
look_at(Vector3(target.x,0,target.y), Vector3.UP)
is_moving = true
pass
func rotate_to(new_rotation: Vector3):
is_rotating = true
rotation_target = new_rotation
pass
func to_coord() -> Vector2i:
return Vector2i(position.x / 2, position.z / 2)
return Vector2i(position.x / 2., position.z / 2.)
func die():
queue_free()
pass
func _on_attack_area_3d_body_entered(body: Node3D) -> void:
if body == self:
return
print("body entered")
if body.is_moving:
self.queue_free()
if is_moving:
body.queue_free()
pass # Replace with function body.

View file

@ -2,5 +2,27 @@
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="1_y1oan"]
[node name="Piece" type="Node3D" unique_id=410020425]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_y1oan"]
[sub_resource type="BoxShape3D" id="BoxShape3D_y1oan"]
size = Vector3(1, 1, 0.23034668)
[node name="Piece" type="CharacterBody3D" unique_id=537334881]
input_ray_pickable = false
script = ExtResource("1_y1oan")
team = null
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1993537939]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("CapsuleShape3D_y1oan")
[node name="AttackArea3D" type="Area3D" parent="." unique_id=1127558984]
collision_layer = 0
input_ray_pickable = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="AttackArea3D" unique_id=2114634494]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2023885, -0.5136469)
shape = SubResource("BoxShape3D_y1oan")
debug_color = Color(0.8610924, 0.33499888, 0.36550382, 0.41960785)
[connection signal="body_entered" from="AttackArea3D" to="." method="_on_attack_area_3d_body_entered"]

View file

@ -1,12 +0,0 @@
[gd_scene format=3 uid="uid://b5o0e01wkibu7"]
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="1_gmwly"]
[ext_resource type="Material" uid="uid://bxg7bjgiqfnru" path="res://Materials/piece_black.tres" id="2_uipd2"]
[ext_resource type="ArrayMesh" uid="uid://cbr1tmaelnbwv" path="res://Models/queen.obj" id="3_18v2x"]
[node name="Queen" type="Node3D" unique_id=1009873024]
script = ExtResource("1_gmwly")
color = ExtResource("2_uipd2")
[node name="mesh" type="MeshInstance3D" parent="." unique_id=1534534969]
mesh = ExtResource("3_18v2x")

View file

@ -1,12 +0,0 @@
[gd_scene format=3 uid="uid://dxh3jmv61jfp0"]
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="1_4uxm1"]
[ext_resource type="Material" uid="uid://bxg7bjgiqfnru" path="res://Materials/piece_black.tres" id="2_kqueb"]
[ext_resource type="ArrayMesh" uid="uid://bpi163efm64p2" path="res://Models/rook.obj" id="3_bs0i1"]
[node name="Rook" type="Node3D" unique_id=699678101]
script = ExtResource("1_4uxm1")
color = ExtResource("2_kqueb")
[node name="mesh" type="MeshInstance3D" parent="." unique_id=2043445377]
mesh = ExtResource("3_bs0i1")