This commit is contained in:
Felipe M. 2023-10-04 21:22:10 +02:00
parent 2f2d8d33c9
commit ccf436c007
Signed by: fmartingr
GPG Key ID: CCFBC5637D4000A8
15 changed files with 248 additions and 70 deletions

56
elements/cylinder.gd Normal file
View File

@ -0,0 +1,56 @@
extends Area3D
var disks: Array
const disk_separation: float = 0.1
signal clicked
signal released
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_click(camera: Node, event: InputEvent, position: Vector3, normal: Vector3, shape_idx: int):
if event is InputEventMouseButton and event.is_action_pressed("click"):
clicked.emit(self)
print("mouse button eventon cylinder: ", name)
func _on_release(camera: Node, event: InputEvent, position: Vector3, normal: Vector3, shape_idx: int):
if event is InputEventMouseButton and event.is_action_released("click"):
released.emit(self)
print("mouse button released on cylinder: ", name)
# append_disk will append a new disk to this cylinder if the disk being appended is smaller than
# the frontmost in this cylinder
func append_disk(disk) -> bool:
if can_append_disk(disk):
disks.append(disk)
_position_disk(disk)
return true
return false
func can_append_disk(disk):
return len(disks) == 0 or disks.back().size > disk.size
# pop_disks will return the backmost disk in this cylinder (the one at the top)
func pop_top_disk():
if len(disks) > 0:
return disks.pop_back()
for n in disks:
_position_disk(disks[n])
return null
func get_top_disk():
if len(disks) > 0:
return disks.back()
return null
func _position_disk(disk):
disk.position = Vector3(self.position.x, disk_separation * len(disks) + (0.1*len(disks)) + 0.2, 0)

25
elements/cylinder.tscn Normal file
View File

@ -0,0 +1,25 @@
[gd_scene load_steps=5 format=3 uid="uid://d1o4ogmoluo21"]
[ext_resource type="Texture2D" uid="uid://coq374a4vgh7x" path="res://textures/wood1.jpg" id="1_kuq38"]
[ext_resource type="Script" path="res://elements/cylinder.gd" id="2_j1nqm"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ota7e"]
albedo_texture = ExtResource("1_kuq38")
[sub_resource type="CylinderShape3D" id="CylinderShape3D_rtwa2"]
height = 1.77652
radius = 0.704142
[node name="cylinder" type="Area3D"]
script = ExtResource("2_j1nqm")
[node name="shape" type="CSGCylinder3D" parent="."]
transform = Transform3D(0.1, 0, 0, 0, 1, 0, 0, 0, 0.1, 2.08165e-12, 1, 2.08165e-12)
material_override = SubResource("StandardMaterial3D_ota7e")
[node name="collision" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.11327, 0)
shape = SubResource("CylinderShape3D_rtwa2")
[connection signal="input_event" from="." to="." method="_on_release"]
[connection signal="input_event" from="." to="." method="_on_click"]

View File

@ -1,27 +1,32 @@
extends Node3D
var size: int = 1
var DiskShape = preload("res://elements/disk.tscn")
@export var size: int = 1
var follow_mouse: bool = false
const radius_multiplier: float = 0.08
const base_size: float = 0.2
func _init(disk_size: int):
size = disk_size
var shape = DiskShape.instantiate()
shape.get_node("shape").set_radius(base_size + (radius_multiplier*disk_size))
add_child(shape)
func get_size() -> int:
return size
#func _init(disk_size: int):
# size = disk_size
#get_node("shape").set_radius(base_size + (radius_multiplier*disk_size))
func can_put_on_top(disk_size: int) -> bool:
return disk_size < size
# Called when the node enters the scene tree for the first time.
func _ready():
pass
get_node("shape").set_radius(base_size + (radius_multiplier*size))
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _input(event):
if follow_mouse and event.is_action_pressed("click"):
var mouse_pos = get_viewport().get_mouse_position()
var camera = get_viewport().get_camera_3d()
var new_pos = camera.project_position(mouse_pos, camera.position.z)
set_position(new_pos)
func set_follow_mouse(value: bool):
follow_mouse = value

View File

@ -1,11 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://bs577fxvbvuva"]
[gd_scene load_steps=4 format=3 uid="uid://bs577fxvbvuva"]
[ext_resource type="Script" path="res://elements/disk.gd" id="1_c6kjy"]
[ext_resource type="Texture2D" uid="uid://dcgeev7872167" path="res://textures/Stone Texture 4.jpg" id="1_eekfu"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_y6ljk"]
albedo_texture = ExtResource("1_eekfu")
[node name="disk" type="Node3D"]
script = ExtResource("1_c6kjy")
metadata/size = 7
[node name="shape" type="CSGCylinder3D" parent="."]

View File

@ -1,34 +1,39 @@
extends Node3D
var Disk = preload("res://elements/disk.gd")
var Disk = preload("res://elements/disk.tscn")
var disks = Dictionary()
@onready var left_column = get_node("cylinders/left")
@export var disk_count: int = 7
func v2_to_v3(vector:Vector2)->Vector3:
return Vector3.FORWARD.rotated(Vector3.UP, Vector2(vector.x, -vector.y).angle())
var selected_disk
var origin_cylinder
func _init_disks(number: int):
for n in range(1, number+1):
disks[n] = Disk.new(n)
for disk_size in disks:
var disk = disks[disk_size]
if disk != null:
disk.set_position(disk.get_position() + Vector3(0, 0.2, 0))
add_child(disk)
func _init_disks():
for n in range(disk_count, 0, -1):
var disk = Disk.instantiate()
disk.size = n
left_column.append_disk(disk)
add_child(disk)
# Called when the node enters the scene tree for the first time.
func _ready():
_init_disks(1)
_init_disks()
var was_pressing_button: bool = false
func cylinder_clicked(cylinder):
print("cylinder clicked: ", cylinder)
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
was_pressing_button = true
var mouse_pos = get_viewport().get_mouse_position()
var camera = get_node("../Camera")
var new_pos = camera.project_position(mouse_pos, camera.position.z)
disks[1].set_position(new_pos)
func _on_cylinder_clicked(cylinder):
print("Cylinder clicked: ", cylinder.name)
var disk = cylinder.get_top_disk()
# TODO: Shadow disk follows mouse?
if disk != null:
origin_cylinder = cylinder
func _on_cylinder_released(cylinder):
print("Cylinder released: ", cylinder.name)
if origin_cylinder != null:
var disk = origin_cylinder.get_top_disk()
if cylinder.can_append_disk(disk):
cylinder.append_disk(origin_cylinder.pop_top_disk())
origin_cylinder = null

View File

@ -1,20 +1,12 @@
[gd_scene load_steps=7 format=3 uid="uid://dlhvv8pl2cpxr"]
[gd_scene load_steps=5 format=3 uid="uid://dlhvv8pl2cpxr"]
[ext_resource type="Script" path="res://elements/game board.gd" id="1_4lf6t"]
[ext_resource type="Texture2D" uid="uid://coq374a4vgh7x" path="res://textures/wood1.jpg" id="1_8hp8a"]
[ext_resource type="PackedScene" uid="uid://d1o4ogmoluo21" path="res://elements/cylinder.tscn" id="3_qo4i0"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gpic3"]
albedo_texture = ExtResource("1_8hp8a")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_udkd6"]
albedo_texture = ExtResource("1_8hp8a")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ota7e"]
albedo_texture = ExtResource("1_8hp8a")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_hpve8"]
albedo_texture = ExtResource("1_8hp8a")
[node name="game board" type="Node3D"]
script = ExtResource("1_4lf6t")
metadata/disks_number = 7
@ -25,16 +17,17 @@ material_override = SubResource("StandardMaterial3D_gpic3")
[node name="cylinders" type="Node" parent="."]
[node name="left" type="CSGCylinder3D" parent="cylinders"]
transform = Transform3D(0.1, 0, 0, 0, 1, 0, 0, 0, 0.1, -1.8, 1, 2.08165e-12)
material_override = SubResource("StandardMaterial3D_udkd6")
[node name="left" parent="cylinders" instance=ExtResource("3_qo4i0")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.75, 2.08165e-12, 2.08165e-12)
[node name="middle" type="CSGCylinder3D" parent="cylinders"]
transform = Transform3D(0.1, 0, 0, 0, 1, 0, 0, 0, 0.1, 2.08165e-12, 1, 2.08165e-12)
material_override = SubResource("StandardMaterial3D_ota7e")
[node name="middle" parent="cylinders" instance=ExtResource("3_qo4i0")]
[node name="right" type="CSGCylinder3D" parent="cylinders"]
transform = Transform3D(0.1, 0, 0, 0, 1, 0, 0, 0, 0.1, 1.8, 1, 2.08165e-12)
material_override = SubResource("StandardMaterial3D_hpve8")
[node name="right" parent="cylinders" instance=ExtResource("3_qo4i0")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.75, 2.08165e-12, 2.08165e-12)
[node name="disks" type="Node" parent="."]
[connection signal="clicked" from="cylinders/left" to="." method="_on_cylinder_clicked"]
[connection signal="released" from="cylinders/left" to="." method="_on_cylinder_released"]
[connection signal="clicked" from="cylinders/middle" to="." method="_on_cylinder_clicked"]
[connection signal="released" from="cylinders/middle" to="." method="_on_cylinder_released"]
[connection signal="clicked" from="cylinders/right" to="." method="_on_cylinder_clicked"]
[connection signal="released" from="cylinders/right" to="." method="_on_cylinder_released"]

72
export_presets.cfg Normal file
View File

@ -0,0 +1,72 @@
[preset.0]
name="iOS"
platform="iOS"
runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../Desktop/godot-hanoi.ipa"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
[preset.0.options]
custom_template/debug=""
custom_template/release=""
architectures/arm64=true
application/app_store_team_id="com.fmartingr"
application/code_sign_identity_debug=""
application/export_method_debug=1
application/code_sign_identity_release=""
application/export_method_release=0
application/targeted_device_family=2
application/bundle_identifier="com.fmartingr.hanoi"
application/signature=""
application/short_version="1.0"
application/version="1.0"
application/icon_interpolation=4
application/launch_screens_interpolation=4
capabilities/access_wifi=false
capabilities/push_notifications=false
user_data/accessible_from_files_app=false
user_data/accessible_from_itunes_sharing=false
privacy/camera_usage_description=""
privacy/camera_usage_description_localized={}
privacy/microphone_usage_description=""
privacy/microphone_usage_description_localized={}
privacy/photolibrary_usage_description=""
privacy/photolibrary_usage_description_localized={}
icons/iphone_120x120=""
icons/iphone_180x180=""
icons/ipad_76x76=""
icons/ipad_152x152=""
icons/ipad_167x167=""
icons/app_store_1024x1024=""
icons/spotlight_40x40=""
icons/spotlight_80x80=""
icons/settings_58x58=""
icons/settings_87x87=""
icons/notification_40x40=""
icons/notification_60x60=""
storyboard/use_launch_screen_storyboard=false
storyboard/image_scale_mode=0
storyboard/custom_image@2x=""
storyboard/custom_image@3x=""
storyboard/use_custom_bg_color=false
storyboard/custom_bg_color=Color(0, 0, 0, 1)
landscape_launch_screens/iphone_2436x1125=""
landscape_launch_screens/iphone_2208x1242=""
landscape_launch_screens/ipad_1024x768=""
landscape_launch_screens/ipad_2048x1536=""
portrait_launch_screens/iphone_640x960=""
portrait_launch_screens/iphone_640x1136=""
portrait_launch_screens/iphone_750x1334=""
portrait_launch_screens/iphone_1125x2436=""
portrait_launch_screens/ipad_768x1024=""
portrait_launch_screens/ipad_1536x2048=""
portrait_launch_screens/iphone_1242x2208=""

View File

@ -15,6 +15,19 @@ run/main_scene="res://scenes/game.tscn"
config/features=PackedStringArray("4.1", "Mobile")
config/icon="res://icon.svg"
[input]
click={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
, null]
}
[input_devices]
pointing/emulate_touch_from_mouse=true
[rendering]
renderer/rendering_method="mobile"
textures/vram_compression/import_etc2_astc=true

View File

@ -4,15 +4,16 @@ importer="texture"
type="CompressedTexture2D"
uid="uid://bbjx5x4721tis"
path.s3tc="res://.godot/imported/Stone Texture 1.jpg-55410c3852d24662faa86bfa29665190.s3tc.ctex"
path.etc2="res://.godot/imported/Stone Texture 1.jpg-55410c3852d24662faa86bfa29665190.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://textures/Stone Texture 1.jpg"
dest_files=["res://.godot/imported/Stone Texture 1.jpg-55410c3852d24662faa86bfa29665190.s3tc.ctex"]
dest_files=["res://.godot/imported/Stone Texture 1.jpg-55410c3852d24662faa86bfa29665190.s3tc.ctex", "res://.godot/imported/Stone Texture 1.jpg-55410c3852d24662faa86bfa29665190.etc2.ctex"]
[params]

View File

@ -4,15 +4,16 @@ importer="texture"
type="CompressedTexture2D"
uid="uid://bs2bgbao4pd4k"
path.s3tc="res://.godot/imported/Stone Texture 2.jpg-8e62ff83ae5f153b3086e87ea96dcdc9.s3tc.ctex"
path.etc2="res://.godot/imported/Stone Texture 2.jpg-8e62ff83ae5f153b3086e87ea96dcdc9.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://textures/Stone Texture 2.jpg"
dest_files=["res://.godot/imported/Stone Texture 2.jpg-8e62ff83ae5f153b3086e87ea96dcdc9.s3tc.ctex"]
dest_files=["res://.godot/imported/Stone Texture 2.jpg-8e62ff83ae5f153b3086e87ea96dcdc9.s3tc.ctex", "res://.godot/imported/Stone Texture 2.jpg-8e62ff83ae5f153b3086e87ea96dcdc9.etc2.ctex"]
[params]

View File

@ -4,15 +4,16 @@ importer="texture"
type="CompressedTexture2D"
uid="uid://mttywqo218qg"
path.s3tc="res://.godot/imported/Stone Texture 3.jpg-fd6bed01b8ecf1c07b3e3735d377935d.s3tc.ctex"
path.etc2="res://.godot/imported/Stone Texture 3.jpg-fd6bed01b8ecf1c07b3e3735d377935d.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://textures/Stone Texture 3.jpg"
dest_files=["res://.godot/imported/Stone Texture 3.jpg-fd6bed01b8ecf1c07b3e3735d377935d.s3tc.ctex"]
dest_files=["res://.godot/imported/Stone Texture 3.jpg-fd6bed01b8ecf1c07b3e3735d377935d.s3tc.ctex", "res://.godot/imported/Stone Texture 3.jpg-fd6bed01b8ecf1c07b3e3735d377935d.etc2.ctex"]
[params]

View File

@ -4,15 +4,16 @@ importer="texture"
type="CompressedTexture2D"
uid="uid://dcgeev7872167"
path.s3tc="res://.godot/imported/Stone Texture 4.jpg-ba73b618076b21f1987fb4f68bd8f5e9.s3tc.ctex"
path.etc2="res://.godot/imported/Stone Texture 4.jpg-ba73b618076b21f1987fb4f68bd8f5e9.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://textures/Stone Texture 4.jpg"
dest_files=["res://.godot/imported/Stone Texture 4.jpg-ba73b618076b21f1987fb4f68bd8f5e9.s3tc.ctex"]
dest_files=["res://.godot/imported/Stone Texture 4.jpg-ba73b618076b21f1987fb4f68bd8f5e9.s3tc.ctex", "res://.godot/imported/Stone Texture 4.jpg-ba73b618076b21f1987fb4f68bd8f5e9.etc2.ctex"]
[params]

View File

@ -4,15 +4,16 @@ importer="texture"
type="CompressedTexture2D"
uid="uid://dv2jygjq2cgwb"
path.s3tc="res://.godot/imported/Stone Texture 5.jpg-9683af8840e7567d7f013c34e51af9b6.s3tc.ctex"
path.etc2="res://.godot/imported/Stone Texture 5.jpg-9683af8840e7567d7f013c34e51af9b6.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://textures/Stone Texture 5.jpg"
dest_files=["res://.godot/imported/Stone Texture 5.jpg-9683af8840e7567d7f013c34e51af9b6.s3tc.ctex"]
dest_files=["res://.godot/imported/Stone Texture 5.jpg-9683af8840e7567d7f013c34e51af9b6.s3tc.ctex", "res://.godot/imported/Stone Texture 5.jpg-9683af8840e7567d7f013c34e51af9b6.etc2.ctex"]
[params]

View File

@ -4,15 +4,16 @@ importer="texture"
type="CompressedTexture2D"
uid="uid://coq374a4vgh7x"
path.s3tc="res://.godot/imported/wood1.jpg-7474f75ae91f1b0154e8699395ca3e39.s3tc.ctex"
path.etc2="res://.godot/imported/wood1.jpg-7474f75ae91f1b0154e8699395ca3e39.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://textures/wood1.jpg"
dest_files=["res://.godot/imported/wood1.jpg-7474f75ae91f1b0154e8699395ca3e39.s3tc.ctex"]
dest_files=["res://.godot/imported/wood1.jpg-7474f75ae91f1b0154e8699395ca3e39.s3tc.ctex", "res://.godot/imported/wood1.jpg-7474f75ae91f1b0154e8699395ca3e39.etc2.ctex"]
[params]

View File

@ -4,15 +4,16 @@ importer="texture"
type="CompressedTexture2D"
uid="uid://coqtn2vr1nwl4"
path.s3tc="res://.godot/imported/wood2.jpg-41426b016c41a7fe80b7df1d7392cbb6.s3tc.ctex"
path.etc2="res://.godot/imported/wood2.jpg-41426b016c41a7fe80b7df1d7392cbb6.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://textures/wood2.jpg"
dest_files=["res://.godot/imported/wood2.jpg-41426b016c41a7fe80b7df1d7392cbb6.s3tc.ctex"]
dest_files=["res://.godot/imported/wood2.jpg-41426b016c41a7fe80b7df1d7392cbb6.s3tc.ctex", "res://.godot/imported/wood2.jpg-41426b016c41a7fe80b7df1d7392cbb6.etc2.ctex"]
[params]