connect 'solved' signal
This commit is contained in:
		
							parent
							
								
									13f0663963
								
							
						
					
					
						commit
						d98ad5fd23
					
				
					 3 changed files with 29 additions and 5 deletions
				
			
		
							
								
								
									
										17
									
								
								game/src/Main.gd
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								game/src/Main.gd
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,17 @@
 | 
				
			||||||
 | 
					extends Control
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Declare member variables here. Examples:
 | 
				
			||||||
 | 
					# var a = 2
 | 
				
			||||||
 | 
					# var b = "text"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 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_Taquin_solved():
 | 
				
			||||||
 | 
						print("Solved!")
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,12 @@
 | 
				
			||||||
[gd_scene load_steps=2 format=2]
 | 
					[gd_scene load_steps=3 format=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ext_resource path="res://src/Taquin.tscn" type="PackedScene" id=1]
 | 
					[ext_resource path="res://src/Main.gd" type="Script" id=1]
 | 
				
			||||||
 | 
					[ext_resource path="res://src/Taquin.tscn" type="PackedScene" id=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Main" type="Control"]
 | 
					[node name="Main" type="Control"]
 | 
				
			||||||
anchor_right = 1.0
 | 
					anchor_right = 1.0
 | 
				
			||||||
anchor_bottom = 1.0
 | 
					anchor_bottom = 1.0
 | 
				
			||||||
 | 
					script = ExtResource( 1 )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Taquin" parent="." instance=ExtResource( 1 )]
 | 
					[node name="Taquin" parent="." instance=ExtResource( 2 )]
 | 
				
			||||||
 | 
					[connection signal="solved" from="Taquin" to="." method="_on_Taquin_solved"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,12 +2,16 @@ extends Node2D
 | 
				
			||||||
class_name Taquin
 | 
					class_name Taquin
 | 
				
			||||||
tool
 | 
					tool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					signal solved
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Piece = preload("res://src/Piece.tscn")
 | 
					var Piece = preload("res://src/Piece.tscn")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export var rows: int = 4
 | 
					export var rows: int = 4
 | 
				
			||||||
export var columns: int = 4
 | 
					export var columns: int = 4
 | 
				
			||||||
export var width: int = 512
 | 
					export var width: int = 512
 | 
				
			||||||
export var height: int = 512
 | 
					export var height: int = 512
 | 
				
			||||||
 | 
					export var difficulty: int = 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var interpiece: int = 5
 | 
					var interpiece: int = 5
 | 
				
			||||||
var padding = 10
 | 
					var padding = 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,7 +51,7 @@ func _ready() -> void:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pieces.append(pieces_row)
 | 
							pieces.append(pieces_row)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	shuffle(10)
 | 
						shuffle(difficulty)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func compute_piece_size() -> int:
 | 
					func compute_piece_size() -> int:
 | 
				
			||||||
	var w_size: int = (width - (2 * padding) - ((columns - 1) * interpiece)) / columns
 | 
						var w_size: int = (width - (2 * padding) - ((columns - 1) * interpiece)) / columns
 | 
				
			||||||
| 
						 | 
					@ -93,7 +97,7 @@ func move_piece(direction) -> bool:
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	update()
 | 
						update()
 | 
				
			||||||
	if check_solved():
 | 
						if check_solved():
 | 
				
			||||||
		print("solved")
 | 
							emit_signal("solved")
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	return true
 | 
						return true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue