Skip to content

Commit

Permalink
make simple chess
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeEntropy committed Jun 26, 2024
1 parent e407a5b commit 1ad9f7a
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 27 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Pinned",
"type": "godot",
"request": "launch",
"scene": "pinned"
}
]
}
Binary file added asset/image/chess/circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions asset/image/chess/circle.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cqyak7pqy6c1g"
path="res://.godot/imported/circle.png-6cc43df2c91e4b9e7ebcc7885c8fc2fb.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://asset/image/chess/circle.png"
dest_files=["res://.godot/imported/circle.png-6cc43df2c91e4b9e7ebcc7885c8fc2fb.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
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=1
Binary file added asset/image/chess/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions asset/image/chess/cross.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bwxsnu3vf8wvq"
path="res://.godot/imported/cross.png-a60c3d4b91550bb1353cfbb4cba3a0ff.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://asset/image/chess/cross.png"
dest_files=["res://.godot/imported/cross.png-a60c3d4b91550bb1353cfbb4cba3a0ff.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
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=1
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ run/main_scene="res://scene/sandbox.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://asset/image/icon.png"

[autoload]

Gameplay="*res://schema/manager/gameplay.gd"

[debug]

gdscript/warnings/integer_division=0
Expand Down
14 changes: 11 additions & 3 deletions scene/prefab/border.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
[gd_scene load_steps=2 format=3 uid="uid://dy5n38bh77hrq"]
[gd_scene load_steps=5 format=3 uid="uid://dy5n38bh77hrq"]

[ext_resource type="Script" path="res://schema/object/border.gd" id="1_dulgy"]
[ext_resource type="Script" path="res://schema/core/image_storage.gd" id="2_wj4id"]
[ext_resource type="Texture2D" uid="uid://cqyak7pqy6c1g" path="res://asset/image/chess/circle.png" id="3_vugjo"]
[ext_resource type="Texture2D" uid="uid://bwxsnu3vf8wvq" path="res://asset/image/chess/cross.png" id="4_mcky7"]

[node name="border" type="GridContainer"]
[node name="border" type="GridContainer" node_paths=PackedStringArray("image_storage")]
offset_left = 46.0
offset_top = 18.0
offset_right = 46.0
offset_bottom = 18.0
theme_override_constants/h_separation = 1
theme_override_constants/v_separation = 1
script = ExtResource("1_dulgy")
layout = Vector2i(5, 3)
image_storage = NodePath("images")
layout = Vector2i(3, 3)

[node name="images" type="Node" parent="."]
script = ExtResource("2_wj4id")
images = Array[Texture2D]([ExtResource("3_vugjo"), ExtResource("4_mcky7")])
6 changes: 3 additions & 3 deletions scene/prefab/cell.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ expand_margin_bottom = 1.0
custom_minimum_size = Vector2(16, 16)
offset_right = 16.0
offset_bottom = 16.0
pivot_offset = Vector2(8, 8)
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_6j4dm")
script = ExtResource("1_nxqe1")

[node name="centered" type="CenterContainer" parent="."]
layout_mode = 2

[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
18 changes: 3 additions & 15 deletions scene/prefab/chess.tscn
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
[gd_scene load_steps=5 format=3 uid="uid://cps2fs4o2djip"]
[gd_scene load_steps=2 format=3 uid="uid://cps2fs4o2djip"]

[ext_resource type="Texture2D" uid="uid://da5xqscem0k0e" path="res://asset/image/icon.png" id="1_i0k4x"]
[ext_resource type="Script" path="res://schema/core/image_storage.gd" id="2_e0i3g"]

[sub_resource type="AtlasTexture" id="AtlasTexture_hhqjk"]
atlas = ExtResource("1_i0k4x")
region = Rect2(25, 25, 14, 14)

[sub_resource type="AtlasTexture" id="AtlasTexture_4j7eb"]
atlas = ExtResource("1_i0k4x")
region = Rect2(40, 25, 14, 14)
[ext_resource type="Texture2D" uid="uid://cqyak7pqy6c1g" path="res://asset/image/chess/circle.png" id="1_ro3qq"]

[node name="chess" type="Sprite2D"]

[node name="images" type="Node" parent="."]
script = ExtResource("2_e0i3g")
images = Array[Texture2D]([SubResource("AtlasTexture_hhqjk"), SubResource("AtlasTexture_4j7eb")])
texture = ExtResource("1_ro3qq")
7 changes: 7 additions & 0 deletions schema/manager/gameplay.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Node

var is_player_control := false

func is_chess_inline(length:=3) -> bool:

return false
35 changes: 31 additions & 4 deletions schema/object/border.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,53 @@ extends GridContainer

var ENUMS := preload("res://schema/core/enum.gd").new()

@export_group('node')
@export var image_storage : Node

@export_group('data')
@export var layout := Vector2i.ZERO : set = set_layout

var cells := {}
var score := {}
var player := 0

#region overrides

func _ready() -> void:
pass

#endregion

#region events

func _on_cell_dropped_chess(cell:BoardCell) -> void:
score[cell.coords] = player
player = wrapi(player + 1, 0, image_storage.images.size())
pass

#endregion

#region tools

func set_layout(value:Vector2i) -> void:
func clear() -> void:
cells.clear()
score.clear()
for child in get_children():
child.queue_free()
pass

func set_layout(value:Vector2i) -> void:
clear()
layout = value
self.size = Vector2.ZERO
self.columns = value.x
for i in (value.x * value.y):
var cell := preload("res://scene/prefab/cell.tscn").instantiate()
add_child(cell)
for y in value.y:
for x in value.x:
var cell := preload("res://scene/prefab/cell.tscn").instantiate()
cell.dropped_chess.connect(_on_cell_dropped_chess)
cell.coords = Vector2i(x, y)
add_child(cell)
cells[cell.coords] = cell
pass

func hide_border() -> void:
Expand Down
29 changes: 27 additions & 2 deletions schema/object/cell.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
class_name BoardCell
extends PanelContainer

var ENUMS := preload("res://schema/core/enum.gd").new()

@export_group('data')
@export var coords : Vector2i

signal dropped_chess(cell:BoardCell)

#region overrides

func _gui_input(event: InputEvent) -> void:
if (event is InputEventMouseButton) and event.is_pressed():
match event.button_index:
MOUSE_BUTTON_LEFT : drop_chess()
pass

#endregion

#region events

func _on_mouse_entered() -> void:
change_content_color(Color.ORANGE_RED)
pass # Replace with function body.
pass

func _on_mouse_exited() -> void:
change_content_color(Color.TRANSPARENT)
pass # Replace with function body.
pass

#endregion

Expand All @@ -33,4 +49,13 @@ func change_border_width(border_flag:int, width:int) -> void:
ENUMS.CELL_BORDER_FLAGS.DOWN : style_box.border_width_bottom = width
pass

func drop_chess() -> void:
if get_child_count() < 1:
print('dropped')
var chess := preload("res://scene/prefab/chess.tscn").instantiate()
chess.position = pivot_offset
add_child(chess)
dropped_chess.emit(self)
pass

#endregion
4 changes: 4 additions & 0 deletions schema/object/player.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends Node

@export var nickname : String
@export var used_chess_image : Texture2D

0 comments on commit 1ad9f7a

Please sign in to comment.