day 4-5
This commit is contained in:
parent
ccf436c007
commit
deaacb3076
|
@ -4,33 +4,24 @@ var disks: Array
|
|||
|
||||
const disk_separation: float = 0.1
|
||||
|
||||
signal clicked
|
||||
signal released
|
||||
signal entered
|
||||
signal exited
|
||||
|
||||
# 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):
|
||||
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)
|
||||
#reposition_disks()
|
||||
disk.tween_to(self.get_position_for_disk(disk))
|
||||
return true
|
||||
return false
|
||||
|
||||
|
@ -41,16 +32,41 @@ func can_append_disk(disk):
|
|||
func pop_top_disk():
|
||||
if len(disks) > 0:
|
||||
return disks.pop_back()
|
||||
|
||||
for n in disks:
|
||||
_position_disk(disks[n])
|
||||
|
||||
return null
|
||||
|
||||
# get_top_disk returns the disk object that is currently at the top
|
||||
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)
|
||||
# reposition_disks will iterate over all disks and reposition them
|
||||
func reposition_disks():
|
||||
for n in range(disks.size()):
|
||||
disks[n].position = Vector3(self.position.x, disk_separation * n + (0.1*n + 0.2), 0)
|
||||
|
||||
func get_position_for_disk(disk) -> Vector3:
|
||||
for n in range(disks.size()):
|
||||
if disks[n].size == disk.size:
|
||||
return Vector3(self.position.x, disk_separation * n + (0.1*n + 0.2), 0)
|
||||
return Vector3.ZERO
|
||||
|
||||
func _on_mouse_entered():
|
||||
entered.emit(self)
|
||||
|
||||
func _on_mouse_exited():
|
||||
exited.emit(self)
|
||||
|
||||
|
||||
func _on_area_entered(area):
|
||||
print("area entered")
|
||||
|
||||
|
||||
func _on_area_exited(area):
|
||||
print("area exited")
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _on_body_shape_entered(body_rid, body, body_shape_index, local_shape_index):
|
||||
print(body) # Replace with function body.
|
||||
|
|
|
@ -3,23 +3,28 @@
|
|||
[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
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ota7e"]
|
||||
albedo_texture = ExtResource("1_kuq38")
|
||||
|
||||
[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)
|
||||
[node name="shape" type="CollisionShape3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1.1, 0, 0, 0, 1.1, 0, 0, 0, 1.1, 2.08165e-12, 1, 2.08165e-12)
|
||||
shape = SubResource("CylinderShape3D_rtwa2")
|
||||
|
||||
[connection signal="input_event" from="." to="." method="_on_release"]
|
||||
[connection signal="input_event" from="." to="." method="_on_click"]
|
||||
[node name="object" 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")
|
||||
use_collision = true
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
[connection signal="area_exited" from="." to="." method="_on_area_exited"]
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_shape_entered"]
|
||||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
extends Node3D
|
||||
|
||||
@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
|
||||
#get_node("shape").set_radius(base_size + (radius_multiplier*disk_size))
|
||||
|
||||
# Enable to let the disk follow the mouse
|
||||
var follow_mouse: bool = false
|
||||
|
||||
# Set to a position to make the disk move to there automatically
|
||||
var move_to: Vector3
|
||||
|
||||
func can_put_on_top(disk_size: int) -> bool:
|
||||
return disk_size < size
|
||||
|
||||
|
@ -19,14 +20,25 @@ func _ready():
|
|||
|
||||
# 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"):
|
||||
if follow_mouse:
|
||||
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)
|
||||
return
|
||||
|
||||
func tween_to_position(destination: Vector3):
|
||||
var tween = get_tree().create_tween()
|
||||
tween.tween_property(
|
||||
self,
|
||||
"position",
|
||||
destination,
|
||||
0.2,
|
||||
)
|
||||
tween.play()
|
||||
|
||||
func tween_to(destination: Vector3):
|
||||
tween_to_position(destination)
|
||||
|
||||
func set_follow_mouse(value: bool):
|
||||
follow_mouse = value
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_y6ljk"]
|
||||
albedo_texture = ExtResource("1_eekfu")
|
||||
|
||||
[node name="disk" type="Node3D"]
|
||||
[node name="disk" type="StaticBody3D"]
|
||||
script = ExtResource("1_c6kjy")
|
||||
metadata/size = 7
|
||||
|
||||
|
|
|
@ -5,35 +5,54 @@ var Disk = preload("res://elements/disk.tscn")
|
|||
@onready var left_column = get_node("cylinders/left")
|
||||
@export var disk_count: int = 7
|
||||
|
||||
var selected_disk
|
||||
var origin_cylinder
|
||||
var hovering_cylinder
|
||||
|
||||
func _init_disks():
|
||||
for n in range(disk_count, 0, -1):
|
||||
var disk = Disk.instantiate()
|
||||
disk.size = n
|
||||
left_column.append_disk(disk)
|
||||
disk.position.x = left_column.position.x
|
||||
disk.position.y = 3
|
||||
add_child(disk)
|
||||
left_column.append_disk(disk)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
_init_disks()
|
||||
|
||||
func cylinder_clicked(cylinder):
|
||||
print("cylinder clicked: ", cylinder)
|
||||
pass
|
||||
|
||||
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:
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton and event.is_action_pressed("click"):
|
||||
if hovering_cylinder:
|
||||
var disk = hovering_cylinder.get_top_disk()
|
||||
if disk:
|
||||
disk.set_follow_mouse(true)
|
||||
origin_cylinder = hovering_cylinder
|
||||
|
||||
if event is InputEventMouseButton and event.is_action_released("click"):
|
||||
if not origin_cylinder:
|
||||
return
|
||||
|
||||
if not hovering_cylinder:
|
||||
var disk = origin_cylinder.get_top_disk()
|
||||
if disk:
|
||||
disk.set_follow_mouse(false)
|
||||
disk.tween_to(origin_cylinder.get_position_for_disk(disk))
|
||||
origin_cylinder = null
|
||||
return
|
||||
|
||||
var disk = origin_cylinder.get_top_disk()
|
||||
if cylinder.can_append_disk(disk):
|
||||
cylinder.append_disk(origin_cylinder.pop_top_disk())
|
||||
origin_cylinder = null
|
||||
if disk:
|
||||
disk.set_follow_mouse(false)
|
||||
if hovering_cylinder.can_append_disk(disk):
|
||||
hovering_cylinder.append_disk(origin_cylinder.pop_top_disk())
|
||||
else:
|
||||
disk.tween_to(origin_cylinder.get_position_for_disk(disk))
|
||||
origin_cylinder = null
|
||||
|
||||
func _on_cylinder_entered(cylinder):
|
||||
print("Cylinder entered: " + cylinder.name)
|
||||
hovering_cylinder = cylinder
|
||||
|
||||
func _on_cylinder_exited(cylinder):
|
||||
print("Cylinder exited: " + cylinder.name)
|
||||
hovering_cylinder = null
|
||||
|
|
|
@ -25,9 +25,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.75, 2.08165e-12, 2.08165e-
|
|||
[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)
|
||||
|
||||
[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"]
|
||||
[connection signal="entered" from="cylinders/left" to="." method="_on_cylinder_entered"]
|
||||
[connection signal="exited" from="cylinders/left" to="." method="_on_cylinder_exited"]
|
||||
[connection signal="entered" from="cylinders/middle" to="." method="_on_cylinder_entered"]
|
||||
[connection signal="exited" from="cylinders/middle" to="." method="_on_cylinder_exited"]
|
||||
[connection signal="entered" from="cylinders/right" to="." method="_on_cylinder_entered"]
|
||||
[connection signal="exited" from="cylinders/right" to="." method="_on_cylinder_exited"]
|
||||
|
|
|
@ -8,7 +8,7 @@ custom_features=""
|
|||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path="../../Desktop/godot-hanoi.ipa"
|
||||
export_path="../../Desktop/Hanoi/godot-hanoi.ipa"
|
||||
encryption_include_filters=""
|
||||
encryption_exclude_filters=""
|
||||
encrypt_pck=false
|
||||
|
@ -19,13 +19,13 @@ encrypt_directory=false
|
|||
custom_template/debug=""
|
||||
custom_template/release=""
|
||||
architectures/arm64=true
|
||||
application/app_store_team_id="com.fmartingr"
|
||||
application/code_sign_identity_debug=""
|
||||
application/app_store_team_id="CRST3ZYAHK"
|
||||
application/code_sign_identity_debug="Felipe Martin"
|
||||
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/export_method_release=1
|
||||
application/targeted_device_family=0
|
||||
application/bundle_identifier="com.fmartingr.hanoi3d"
|
||||
application/signature=""
|
||||
application/short_version="1.0"
|
||||
application/version="1.0"
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bn1p237fqssam"
|
||||
path="res://.godot/imported/icon.jpg-4a7f64b346e42b67f360ae423f9eb5cc.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.jpg"
|
||||
dest_files=["res://.godot/imported/icon.jpg-4a7f64b346e42b67f360ae423f9eb5cc.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
|
|
@ -13,7 +13,7 @@ config_version=5
|
|||
config/name="godot-hanoi"
|
||||
run/main_scene="res://scenes/game.tscn"
|
||||
config/features=PackedStringArray("4.1", "Mobile")
|
||||
config/icon="res://icon.svg"
|
||||
config/icon="res://icon.jpg"
|
||||
|
||||
[input]
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@ func _ready():
|
|||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
func _process(_delta):
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue