Press your spacebar

This commit is contained in:
Eljakim Herrewijnen 2020-10-02 22:55:51 +02:00
parent 8999e2e4a8
commit 8a90a39292
5 changed files with 20 additions and 25 deletions

View File

@ -11,6 +11,8 @@ var velocity = Vector2()
#Moving buttons #Moving buttons
func _physics_process(delta): func _physics_process(delta):
if Input.is_key_pressed(KEY_SPACE):
_interaction_process()
velocity.y += delta * GRAVITY velocity.y += delta * GRAVITY
if Input.is_action_pressed("move_left"): if Input.is_action_pressed("move_left"):
velocity.x = -WALK_SPEED velocity.x = -WALK_SPEED
@ -20,15 +22,15 @@ func _physics_process(delta):
velocity.y = -WALK_SPEED velocity.y = -WALK_SPEED
elif Input.is_action_pressed("move_down"): elif Input.is_action_pressed("move_down"):
velocity.y = WALK_SPEED velocity.y = WALK_SPEED
# elif Input.is_action_pressed("map_interaction"):
# print("Interacted")
# print(InputEventMouseButton.position)
else: else:
velocity.x = 0 velocity.x = 0
velocity.y = 0 velocity.y = 0
move_and_slide(velocity, Vector2(0, -1)) move_and_slide(velocity, Vector2(0, -1))
func _interaction_process():
if Input.is_action_pressed("map_interaction") or Input.is_key_pressed((KEY_SPACE)):
background_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), -1)
func _input(event): func _input(event):
# Mouse in viewport coordinates. # Mouse in viewport coordinates.
if event is InputEventMouseButton: if event is InputEventMouseButton:
@ -36,8 +38,3 @@ func _input(event):
if Input.is_action_pressed("map_interaction"): if Input.is_action_pressed("map_interaction"):
pass pass
# elif event is InputEventMouseMotion:
# print("Mouse Motion at: ", event.position)
#
# # Print the size of the viewport.
# print("Viewport Resolution is: ", get_viewport_rect().size)

View File

@ -69,6 +69,3 @@ func CameraToPlayer():
if lockedPlayerCamera == false: if lockedPlayerCamera == false:
MoveCamera(player.position.x, player.position.y) MoveCamera(player.position.x, player.position.y)
func GetExactMapPosition_FromScreen(map_pos, target_pos):
pass

View File

@ -21,14 +21,3 @@ func _unhandled_input(event):
if(pl_tile != -1): if(pl_tile != -1):
set_cellv(pl_pos_tile, -1) set_cellv(pl_pos_tile, -1)
# var mouse_pos = get_viewport().get_mouse_position()
# var tile_pos = map_to_world(world_to_map(mouse_pos))
## print(tile_pos)
# #var tile = get_cell(32,32)
# var tile = get_cell(mouse_pos.x / cell_size.x, mouse_pos.y / cell_size.y)
# if(tile != -1):
# set_cell(mouse_pos.x / cell_size.x, mouse_pos.y / cell_size.y, -1)
## clear()
## print(tile)

View File

@ -35,6 +35,18 @@ enabled=PoolStringArray( "vnen.tiled_importer" )
[input] [input]
ui_accept={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777222,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_select={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
move_left={ move_left={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) "events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)

View File

@ -149,7 +149,7 @@ flip_h = true
shape = SubResource( 1 ) shape = SubResource( 1 )
one_way_collision_margin = 96.0 one_way_collision_margin = 96.0
[node name="MapInteraction" type="TouchScreenButton" parent="Player"] [node name="MapInteraction" type="TouchScreenButton" parent="Player/CollisionShape2D"]
show_behind_parent = true show_behind_parent = true
position = Vector2( -150, -150 ) position = Vector2( -150, -150 )
scale = Vector2( 15, 15 ) scale = Vector2( 15, 15 )
@ -161,5 +161,5 @@ action = "map_interaction"
[connection signal="pressed" from="Camera2D/MoveDown" to="Player" method="_on_TouchScreenButton_pressed"] [connection signal="pressed" from="Camera2D/MoveDown" to="Player" method="_on_TouchScreenButton_pressed"]
[connection signal="pressed" from="Camera2D/MoveRight" to="Player" method="_on_TouchScreenButton_pressed"] [connection signal="pressed" from="Camera2D/MoveRight" to="Player" method="_on_TouchScreenButton_pressed"]
[connection signal="pressed" from="Camera2D/MoveUp" to="Player" method="_on_TouchScreenButton_pressed"] [connection signal="pressed" from="Camera2D/MoveUp" to="Player" method="_on_TouchScreenButton_pressed"]
[connection signal="released" from="Player/MapInteraction" to="Player" method="_physics_process"] [connection signal="released" from="Player/CollisionShape2D/MapInteraction" to="Player" method="_interaction_process"]
[connection signal="tween_completed" from="Tween" to="Camera2D" method="_on_Tween_tween_completed"] [connection signal="tween_completed" from="Tween" to="Camera2D" method="_on_Tween_tween_completed"]