Input now works with touch screens
This commit is contained in:
parent
5bc56ee648
commit
34a254b12c
@ -11,6 +11,7 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="Minesweeper"
|
||||
run/main_scene="uid://b8ewc3373b0t2"
|
||||
config/features=PackedStringArray("4.4", "GL Compatibility")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
@ -28,8 +29,26 @@ window/stretch/aspect="expand"
|
||||
|
||||
project/assembly_name="Minesweeper"
|
||||
|
||||
[input]
|
||||
|
||||
reveal={
|
||||
"deadzone": 0.2,
|
||||
"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":1,"position":Vector2(179, 17),"global_position":Vector2(188, 65),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
flag={
|
||||
"deadzone": 0.2,
|
||||
"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":2,"position":Vector2(98, 20),"global_position":Vector2(107, 68),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[input_devices]
|
||||
|
||||
pointing/android/enable_long_press_as_right_click=true
|
||||
|
||||
[rendering]
|
||||
|
||||
textures/canvas_textures/default_texture_filter=0
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
||||
textures/vram_compression/import_etc2_astc=true
|
||||
|
@ -14,10 +14,9 @@ texture = ExtResource("2_r3gf4")
|
||||
|
||||
[node name="layer2" type="Sprite2D" parent="."]
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
input_pickable = true
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource("RectangleShape2D_xpffi")
|
||||
|
||||
[connection signal="input_event" from="StaticBody2D" to="." method="_on_static_body_2d_input_event"]
|
||||
[connection signal="input_event" from="Area2D" to="." method="_on_area_2d_input_event"]
|
||||
|
@ -8,6 +8,7 @@ static var instance: Minefield
|
||||
@export var width: int = 10
|
||||
@export var height: int = 10
|
||||
@export var mineCount: int = 10
|
||||
@export var startingSafeZone: int = 2
|
||||
|
||||
var tiles: Array[Tile]
|
||||
var spriteWidth: int = 16
|
||||
@ -35,7 +36,7 @@ func initField(coord: Vector2i) -> void:
|
||||
var pick: Tile = pickPool.pick_random()
|
||||
while (true):
|
||||
pickPool.erase(pick)
|
||||
if (abs(coord - pick.coord) >= Vector2i(1, 1)):
|
||||
if (abs(coord - pick.coord) >= Vector2i(startingSafeZone, startingSafeZone)):
|
||||
pick.type = Tile.TileTypes.MINE
|
||||
break
|
||||
pick = pickPool.pick_random()
|
||||
|
@ -34,6 +34,7 @@ enum TileTypes{
|
||||
var type: TileTypes
|
||||
var coord: Vector2i
|
||||
var revealed: bool = false
|
||||
var flagged: bool = false
|
||||
|
||||
func evaluateType() -> void:
|
||||
if (type == TileTypes.MINE): return
|
||||
@ -64,9 +65,15 @@ func reveal() -> void:
|
||||
_:
|
||||
layer2.texture = nums[type as int - 1]
|
||||
|
||||
func _on_static_body_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if (event.is_pressed()):
|
||||
print("Pressed " + str(coord))
|
||||
if (!Minefield.instance.fieldInitialized):
|
||||
Minefield.instance.initField(coord)
|
||||
reveal()
|
||||
func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if (event.is_released()):
|
||||
if (event.is_action_released("reveal") && !flagged):
|
||||
if (!Minefield.instance.fieldInitialized):
|
||||
Minefield.instance.initField(coord)
|
||||
reveal()
|
||||
elif (event.is_action_released("flag") && !revealed):
|
||||
flagged = !flagged
|
||||
if (flagged):
|
||||
layer2.texture = flag
|
||||
else:
|
||||
layer2.texture = null
|
||||
|
Loading…
x
Reference in New Issue
Block a user