Upload files to "/"

Prima zii de lucrat la jocul de sah, tabla este in dezvoltare, avem probleme cu modul de a altera mutarile playerilor
This commit is contained in:
Dragos Stefan Cirstian 2024-07-08 10:56:19 +03:00
commit c5b8b8ae0d
5 changed files with 120 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/

84
Node.gd Normal file
View File

@ -0,0 +1,84 @@
extends Node
var player : int
var turn_player : int
var board_size : int
var cell_size : int
var grid_pos : Vector2i
var grid_data : Array # matrice 8 pe 8
var start_pos : Vector2i # retine primul click dat / piesa pe care se doreste a muta
var start_piesa : int
# Called when the node enters the scene tree for the first time.
func _ready():
board_size = $Board.texture.get_width()
# imparte board_size la 8 pentru a obtine dimensiunea fiecarei celule
cell_size = board_size / 8
turn_player = 1
new_game()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _input(event):
if event is InputEventMouseButton :
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed :
#verifica daca mouse-ul e pe tabla de jo
if event.position.x < board_size:
#convertire pozitie mouse in locatie grid
grid_pos = Vector2i(event.position / cell_size) # grid_pos memoreza [coloana, linie]
#verificare daca in chenar este piesa player-ului care a dat click:
#pt player = 1
if grid_data[grid_pos.y][grid_pos.x] > 0 and player == 1 :
start_piesa = grid_data[grid_pos.y][grid_pos.x]
start_pos = grid_pos
print("player", player, "a apasat pe chenarul ", grid_pos )
print("a fost selectata piesa ", start_piesa)
turn_player = 2
# verificare daca al doi-Lea click este pe o pozitie libera
if grid_pos != start_pos and player == 1:
print("trece de primul if")
if grid_data[grid_pos.y][grid_pos.x] == 0:
#marcare noua pozitie a piesei
grid_data[grid_pos.y][grid_pos.x] = start_piesa
#demarcare vechea pozitie a piesei
grid_data[start_pos.y][start_pos.x] = 0
print(grid_pos)
print(grid_data)
turn_player = 3
# pt player 2
if player == -1 and grid_data[grid_pos.y][grid_pos.x] < 0 :
start_piesa = grid_data[grid_pos.y][grid_pos.x]
start_pos = grid_pos
print("player", player, "a apasat pe chenarul ", grid_pos )
print("a fost selectata piesa ", start_piesa)
# verificare daca al doi-Lea click este pe o pozitie libera
if grid_pos != start_pos and player == -1:
print("trece de primul if")
if grid_data[grid_pos.y][grid_pos.x] == 0:
#marcare noua pozitie a piesei
grid_data[grid_pos.y][grid_pos.x] = start_piesa
#demarcare vechea pozitie a piesei
grid_data[start_pos.y][start_pos.x] = 0
print(grid_pos)
print(grid_data)
#schimbare player
func new_game():
player = 1
grid_data = [
[0, 6, 0, 0, 0, 0, -6, 0],
[0, 6, 0, 0, 0, 0, -6, 0],
[0, 6, 0, 0, 0, 0, -6, 0],
[0, 6, 0, 0, 0, 0, -6, 0],
[0, 6, 0, 0, 0, 0, -6, 0],
[0, 6, 0, 0, 0, 0, -6, 0],
[0, 6, 0, 0, 0, 0, -6, 0],
[0, 6, 0, 0, 0, 0, -6, 0]
]

12
main.tscn Normal file
View File

@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://d3fe3x8i4thex"]
[ext_resource type="Script" path="res://Node.gd" id="1_ox6fu"]
[ext_resource type="Texture2D" uid="uid://c6uu24qr8n5qp" path="res://Asset/Tabla sah1 - Copy.jpg" id="2_erbmr"]
[node name="Main" type="Node"]
script = ExtResource("1_ox6fu")
[node name="Board" type="Sprite2D" parent="."]
position = Vector2(379, 386)
rotation = 1.5708
texture = ExtResource("2_erbmr")

20
project.godot Normal file
View File

@ -0,0 +1,20 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="Joc sah 1"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"
[display]
window/size/viewport_width=757
window/size/viewport_height=763