Repository navigation
Expand file tree
/
Copy pathRules.cs
More file actions
143 lines (121 loc) · 3.36 KB
/
Copy pathRules.cs
File metadata and controls
143 lines (121 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Chess;
public class Rules : MonoBehaviour
{
DragAndDrop dad;
Chess.Chess chess; // Во имя отца и сына и святого духа, Аминь, живи!! <3 НЕ ТРОГАТЬ
// пиши пока работает Аминь
public Rules()
{
dad = new DragAndDrop();
chess = new Chess.Chess();
ShowFigures();
}
void Start()
{
}
void Update()
{
dad.Action();
}
void ShowFigures()
{
int nr = 0;
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
{
string figure = chess.GetFigureAt(x, y).ToString();
if (figure == ".") continue;
PlaceFigure("box" + nr, figure, x, y);
nr++;
}
for (; nr < 32; nr++)
PlaceFigure("box" + nr, "q", 9, 9);
}
void PlaceFigure (string box, string figure, int x, int y)
{
Debug.Log(box + " " + figure + " " + x + y);
GameObject goBox = GameObject.Find(box);
GameObject goFigure = GameObject.Find(figure); // K P R n b
GameObject goSquare = GameObject.Find("" + x + y);
var spriteFigure = goFigure.GetComponent<SpriteRenderer>();
var spriteBox = goBox.GetComponent<SpriteRenderer>();
spriteBox.sprite = spriteFigure.sprite;
}
}
//class Jesus
//{
// return Jesus;
//}
class DragAndDrop //пиздецовый класс умоляю не трогайте, устрою холокост
{
enum State
{
none,
drag,
}
State state;
GameObject item;
Vector2 offset;
public DragAndDrop()
{
state = State.none;
item = null;
}
public bool Action()
{
switch (state)
{
case State.none:
if (IsMouseButtonPressed())
PickUp();
break;
case State.drag:
if (IsMouseButtonPressed())
Drag();
else
{
Drop();
return true;
}
break;
}
return false;
}
bool IsMouseButtonPressed()
{
return Input.GetMouseButton(0);
}
void PickUp()
{
Vector2 clickPosition = GetClickPosition();
Transform clickedItem = GetItemAt(clickPosition);
if (clickedItem == null) return;
item = clickedItem.gameObject;
state = State.drag;
offset = (Vector2)clickedItem.position - clickPosition;
Debug.Log("Picked up" + item.name);
}
Vector2 GetClickPosition()
{
return Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
Transform GetItemAt(Vector2 position)
{
RaycastHit2D[] figures = Physics2D.RaycastAll(position, position, 0.5f); //захват коллайдера
if (figures.Length == 0)
return null;
return figures[0].transform;
}
void Drag()
{
item.transform.position = GetClickPosition() + offset;
}
void Drop()
{
state = State.none;
item = null;
}
}