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")

View file

@ -14,9 +14,10 @@ var possible_positions : Array[Vector2i] = []
func _ready() -> void:
#$SuperPawn2.move_to(Vector2(8,8))
#$SuperPawn.move_to(Vector2(0,0))
for child in get_node("Board").get_children():
child.is_clicked.connect(movement)
for tile in get_node("Board").get_children():
tile.is_clicked.connect(movement)
pass # Replace with function body.
func movement(coord:Vector2i):
if selected_piece:
if coord in possible_positions:

View file

@ -1,13 +1,17 @@
[gd_scene format=3 uid="uid://e7hyi2t7bejn"]
[ext_resource type="Script" uid="uid://40ykqd27yux" path="res://Scene/game.gd" id="1_8f6ah"]
[ext_resource type="Material" uid="uid://brrbuo0i0e5bh" path="res://Materials/piece_white.tres" id="4_yjs1f"]
[ext_resource type="Resource" uid="uid://cbwd1rtruemqj" path="res://Resources/Pieces/pawn.tres" id="5_sagxc"]
[ext_resource type="ArrayMesh" uid="uid://cbr1tmaelnbwv" path="res://Models/queen.obj" id="5_vyw1f"]
[ext_resource type="Script" uid="uid://by68phh60fpjr" path="res://Scripts/Rules/rook.gd" id="6_cvvdq"]
[ext_resource type="Resource" uid="uid://cah56vr1263v1" path="res://Resources/Pieces/knight.tres" id="6_h8jt7"]
[ext_resource type="PackedScene" uid="uid://2cqjdxpi6ave" path="res://Scene/board.tscn" id="6_thj8p"]
[ext_resource type="Resource" uid="uid://drhygbtu4bbiq" path="res://Resources/Pieces/bishop.tres" id="7_h8jt7"]
[ext_resource type="Script" uid="uid://cfwpyvuiwr1ph" path="res://Scripts/Rules/bishop.gd" id="7_m52p7"]
[ext_resource type="PackedScene" uid="uid://ci6k70kme7egj" path="res://Scene/Pieces/piece.tscn" id="7_sagxc"]
[ext_resource type="Resource" uid="uid://dpec03625gclm" path="res://Resources/Pieces/queen.tres" id="8_8f6ah"]
[ext_resource type="Resource" uid="uid://cso00cln3awgu" path="res://Resources/Pieces/rook.tres" id="8_sagxc"]
[ext_resource type="Script" uid="uid://c7dd1y3vdajk5" path="res://Resources/piece_res.gd" id="8_vy0et"]
[ext_resource type="Script" uid="uid://c11aaiot3b336" path="res://Scene/Pieces/piece.gd" id="9_8f6ah"]
[ext_resource type="Resource" uid="uid://ekgey785opq5" path="res://Resources/Pieces/king.tres" id="10_twwsd"]
@ -34,6 +38,15 @@ fog_sun_scatter = 0.3
fog_aerial_perspective = 0.113
adjustment_enabled = true
[sub_resource type="Resource" id="Resource_yjs1f"]
resource_local_to_scene = true
script = ExtResource("8_vy0et")
movement_speed = 10.0
mesh = ExtResource("5_vyw1f")
material = ExtResource("4_yjs1f")
rules = Array[Script]([ExtResource("6_cvvdq"), ExtResource("7_m52p7")])
metadata/_custom_type_script = "uid://c7dd1y3vdajk5"
[node name="Game" type="Node3D" unique_id=1842930265]
script = ExtResource("1_8f6ah")
@ -58,39 +71,53 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 26.254642, 0)
[node name="Queen" parent="Pieces" unique_id=410020425 groups=["Pieces", "PlayerPieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 4)
piece_res = ExtResource("8_8f6ah")
piece_res = SubResource("Resource_yjs1f")
team = "us"
[node name="Pawn5" parent="Pieces" unique_id=214368826 groups=["Pieces", "PlayerPieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 6, 0, 2)
piece_res = ExtResource("5_sagxc")
team = "us"
[node name="Pawn6" parent="Pieces" unique_id=353236800 groups=["Pieces", "PlayerPieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 4, 0, 2)
piece_res = ExtResource("5_sagxc")
team = "us"
[node name="Pawn7" parent="Pieces" unique_id=667979117 groups=["Pieces", "PlayerPieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 2, 0, 2)
piece_res = ExtResource("5_sagxc")
team = "us"
[node name="Pawn8" parent="Pieces" unique_id=279147143 groups=["Pieces", "PlayerPieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, 0, 8)
piece_res = ExtResource("5_sagxc")
team = "us"
[node name="Knight" parent="Pieces" unique_id=828740381 groups=["Enemy", "Pieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
piece_res = ExtResource("6_h8jt7")
team = "them"
[node name="Knight2" parent="Pieces" unique_id=905424274 groups=["Enemy", "Pieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 12, 0, 8)
piece_res = ExtResource("6_h8jt7")
team = "them"
[node name="Rook3" parent="Pieces" unique_id=537334881 groups=["Pieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, 8)
piece_res = ExtResource("8_sagxc")
team = "us"
[node name="Rook" parent="Pieces" unique_id=457900680 groups=["Pieces", "PlayerPieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4, 0, 8)
piece_res = ExtResource("8_sagxc")
team = "them"
[node name="Bishop" parent="Pieces" unique_id=839312457 groups=["Pieces", "PlayerPieces"] instance=ExtResource("7_sagxc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 8)
piece_res = ExtResource("7_h8jt7")
team = "them"
[node name="King" type="Node3D" parent="Pieces" unique_id=345844088 groups=["Pieces", "PlayerPieces"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, 2)