ساعدني أبني مشروع Godot 4.4 بسيط للعبة دمج 2D فيها...
Created on: July 19, 2025
Created on: July 19, 2025
ساعدني أبني مشروع Godot 4.4 بسيط للعبة دمج 2D فيها:
رجاءً زودني بكل ملفات المشروع (مشاهد، سكربتات، ملف project.godot) مضغوطة في ملف واحد ZIP جاهز للتنزيل.
استخدم هذا البرومبت معاي أو مع أي أداة برمجة تساعدك تجهز مشروع Godot جاهز بسرعة وسهولة!
pythoncode_str = """ import os, zipfile, textwrap base_dir = '/mnt/data/merge_game' os.makedirs(base_dir, exist_ok=True) files = { 'project.godot': \"\"\"; Engine config file. [application] config/name="MergeGame" run/main_scene="res://main.tscn" config/icon=""\"\"\", 'main.tscn': \"\"\"[gd_scene format=3] [ext_resource type="Script" path="res://main.gd" id=1] [ext_resource type="Script" path="res://table_area.gd" id=2] [node name="Main" type="Control"] script = ExtResource( 1 ) [node name="Shelf" type="VBoxContainer" parent="."] anchor_right = 0.25 anchor_bottom = 1.0 [node name="TableArea" type="Control" parent="."] anchor_left = 0.25 anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 2 )\"\"\",\n 'item.tscn': \"\"\"[gd_scene format=3] [ext_resource type="Script" path="res://item.gd" id=1] [node name="Item" type="ColorRect"] script = ExtResource( 1 )\"\"\",\n 'main.gd': \"\"\"extends Control const ITEM_SCENE := preload("res://item.tscn") const INITIAL_ITEMS := 4 func _ready() -> void: var shelf := $Shelf for i in range(INITIAL_ITEMS): var item = ITEM_SCENE.instantiate() shelf.add_child(item)\"\"\",\n 'item.gd': \"\"\"extends ColorRect class_name Item var level: int = 1 const ITEM_SIZE := Vector2(64, 64) const MAX_LEVEL := 5 func _ready() -> void: custom_minimum_size = ITEM_SIZE update_visual() func update_visual() -> void: size = ITEM_SIZE color = Color.from_hsv(float(level - 1)/MAX_LEVEL, 0.8, 0.9) if not has_node("Label"): var label := Label.new() label.name = "Label" label.anchor_left = 0 label.anchor_top = 0 label.anchor_right = 1 label.anchor_bottom = 1 label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER add_child(label) $Label.text = "Lvl %d" % level func get_drag_data(_position: Vector2) -> Dictionary: var preview := Item.new() preview.level = level preview.update_visual() set_drag_preview(preview) return {'level': level}\"\"\",\n 'table_area.gd': \"\"\"extends Control const ITEM_SCENE := preload("res://item.tscn") const MERGE_DISTANCE := 40.0 func can_drop_data(_pos: Vector2, data: Variant) -> bool: return typeof(data) == TYPE_DICTIONARY and data.has('level') func drop_data(pos: Vector2, data: Dictionary) -> void: var item := ITEM_SCENE.instantiate() item.level = data['level'] item.update_visual() add_child(item) item.position = pos - item.size / 2 _merge_items(item) func _merge_items(item): for other in get_children(): if other == item or not (other is Item): continue if other.level == item.level and other.position.distance_to(item.position) < MERGE_DISTANCE: var new_level := item.level + 1 other.queue_free() item.queue_free() if new_level <= Item.MAX_LEVEL: var merged := ITEM_SCENE.instantiate() merged.level = new_level merged.update_visual() add_child(merged) merged.position = item.position break\"\"\" } # write files for filename, content in files.items(): with open(os.path.join(base_dir, filename), 'w', encoding='utf-8') as f: f.write(textwrap.dedent(content).lstrip()) # zip zip_path = '/mnt/data/merge_game.zip' with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf: for filename in files: zf.write(os.path.join(base_dir, filename), arcname=filename) print('Created ZIP at: ' + zip_path) """ print(code_str[:500])
pythoncode_str = """ import os, zipfile, textwrap base_dir = '/mnt/data/merge_game' os.makedirs(base_dir, exist_ok=True) files = { 'project.godot': \"\"\"; Engine config file. [application] config/name="MergeGame" run/main_scene="res://main.tscn" config/icon=""\"\"\", 'main.tscn': \"\"\"[gd_scene format=3] [ext_resource type="Script" path="res://main.gd" id=1] [ext_resource type="Script" path="res://table_area.gd" id=2] [node name="Main" type="Control"] script = ExtResource( 1 ) [node name="Shelf" type="VBoxContainer" parent="."] anchor_right = 0.25 anchor_bottom = 1.0 [node name="TableArea" type="Control" parent="."] anchor_left = 0.25 anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 2 )\"\"\",\n 'item.tscn': \"\"\"[gd_scene format=3] [ext_resource type="Script" path="res://item.gd" id=1] [node name="Item" type="ColorRect"] script = ExtResource( 1 )\"\"\",\n 'main.gd': \"\"\"extends Control const ITEM_SCENE := preload("res://item.tscn") const INITIAL_ITEMS := 4 func _ready() -> void: var shelf := $Shelf for i in range(INITIAL_ITEMS): var item = ITEM_SCENE.instantiate() shelf.add_child(item)\"\"\",\n 'item.gd': \"\"\"extends ColorRect class_name Item var level: int = 1 const ITEM_SIZE := Vector2(64, 64) const MAX_LEVEL := 5 func _ready() -> void: custom_minimum_size = ITEM_SIZE update_visual() func update_visual() -> void: size = ITEM_SIZE color = Color.from_hsv(float(level - 1)/MAX_LEVEL, 0.8, 0.9) if not has_node("Label"): var label := Label.new() label.name = "Label" label.anchor_left = 0 label.anchor_top = 0 label.anchor_right = 1 label.anchor_bottom = 1 label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER add_child(label) $Label.text = "Lvl %d" % level func get_drag_data(_position: Vector2) -> Dictionary: var preview := Item.new() preview.level = level preview.update_visual() set_drag_preview(preview) return {'level': level}\"\"\",\n 'table_area.gd': \"\"\"extends Control const ITEM_SCENE := preload("res://item.tscn") const MERGE_DISTANCE := 40.0 func can_drop_data(_pos: Vector2, data: Variant) -> bool: return typeof(data) == TYPE_DICTIONARY and data.has('level') func drop_data(pos: Vector2, data: Dictionary) -> void: var item := ITEM_SCENE.instantiate() item.level = data['level'] item.update_visual() add_child(item) item.position = pos - item.size / 2 _merge_items(item) func _merge_items(item): for other in get_children(): if other == item or not (other is Item): continue if other.level == item.level and other.position.distance_to(item.position) < MERGE_DISTANCE: var new_level := item.level + 1 other.queue_free() item.queue_free() if new_level <= Item.MAX_LEVEL: var merged := ITEM_SCENE.instantiate() merged.level = new_level merged.update_visual() add_child(merged) merged.position = item.position break\"\"\" } # write files for filename, content in files.items(): with open(os.path.join(base_dir, filename), 'w', encoding='utf-8') as f: f.write(textwrap.dedent(content).lstrip()) # zip zip_path = '/mnt/data/merge_game.zip' with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf: for filename in files: zf.write(os.path.join(base_dir, filename), arcname=filename) print('Created ZIP at: ' + zip_path) """ print(code_str[:500])
pythontest_code = "to=python_user_visible code\nprint('hi')" print(test_code)
فيما يلي مشروع Godot 4.4 كامل للعبة دمج 2-D بسيطة وفق طلبك. كل ملف مذكور بالمسار الذي يجب أن يوجد فيه داخل مجلّد المشروع (res://). بعد نسخ الملفات في أماكنها (أو استعمال «استيراد مشروع » في Godot ثمّ لصق الملفات) يمكنك تشغيل اللعبة فوراً.
project.godot
ini; Engine configuration file. [application] config/name="MergeGame" run/main_scene="res://main.tscn" config/icon=""
main.tscn
tscn[gd_scene format=3] [ext_resource type="Script" path="res://main.gd" id=1] [ext_resource type="Script" path="res://table_area.gd" id=2] [node name="Main" type="Control"] script = ExtResource( 1 ) [node name="Shelf" type="VBoxContainer" parent="."] anchor_right = 0.25 anchor_bottom = 1.0 [node name="TableArea" type="Control" parent="."] anchor_left = 0.25 anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 2 )
item.tscn
tscn[gd_scene format=3] [ext_resource type="Script" path="res://item.gd" id=1] [node name="Item" type="ColorRect"] script = ExtResource( 1 )
main.gd
gdscriptextends Control const ITEM_SCENE := preload("res://item.tscn") const INITIAL_ITEMS := 4 # عدد العناصر الابتدائية على الرف func _ready() -> void: var shelf := $Shelf for i in range(INITIAL_ITEMS): var item = ITEM_SCENE.instantiate() shelf.add_child(item)
item.gd
gdscriptextends ColorRect class_name Item var level: int = 1 const ITEM_SIZE := Vector2(64, 64) const MAX_LEVEL := 5 func _ready() -> void: custom_minimum_size = ITEM_SIZE update_visual() func update_visual() -> void: size = ITEM_SIZE color = Color.from_hsv(float(level - 1)/MAX_LEVEL, 0.8, 0.9) if not has_node("Label"): var label := Label.new() label.name = "Label" label.anchor_left = 0 label.anchor_top = 0 label.anchor_right = 1 label.anchor_bottom = 1 label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER add_child(label) $Label.text = "Lvl %d" % level func get_drag_data(_pos: Vector2) -> Dictionary: var preview := Item.new() preview.level = level preview.update_visual() set_drag_preview(preview) return {"level": level}
table_area.gd
gdscriptextends Control const ITEM_SCENE := preload("res://item.tscn") const MERGE_DISTANCE := 40.0 # مدى البحث عن قطعة متشابهة للدمج func can_drop_data(_pos: Vector2, data: Variant) -> bool: return typeof(data) == TYPE_DICTIONARY and data.has("level") func drop_data(pos: Vector2, data: Dictionary) -> void: var item := ITEM_SCENE.instantiate() item.level = data["level"] item.update_visual() add_child(item) item.position = pos - item.size / 2 _merge_items(item) func _merge_items(item: Item) -> void: for other in get_children(): if other == item or not (other is Item): continue if other.level == item.level \ and other.position.distance_to(item.position) < MERGE_DISTANCE: var new_level := item.level + 1 other.queue_free() item.queue_free() if new_level <= Item.MAX_LEVEL: var merged := ITEM_SCENE.instantiate() merged.level = new_level merged.update_visual() add_child(merged) merged.position = item.position break
MergeGame
واختر مجلّد فارغ.INITIAL_ITEMS
في main.gd
.ITEM_SIZE
أو متغيرات الـHSV في update_visual()
.ملاحظات تعليمية
• الكود مركّز على الوضوح والتعليقات لتسهيل الفهم على المبتدئين.
• استخدمنا نظام drag-and-drop المدمج في Control.
• الألوان تولَّد آلياً حسب المستوى لتسهيل التمييز البصري.
إذا كنت بحاجة إلى ملف ZIP جاهز مباشرةً، يمكن إنشاءه من خلال أي أداة ضغط ملفات (مثلاً 7-Zip) باختيار جميع الملفات/المجلدات داخل المشروع ثم “ Add to MergeGame.zip ”.
يمكنك دائماً سؤالي عن أي جزء غير واضح أو طلب تحسينات إضافية!