mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 10:09:47 +03:00
Merge pull request #397 from aaronfranke/misc
Update and improve misc demos for Godot 3.1.2
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node
|
||||
|
||||
signal purchase_success(item_name)
|
||||
@@ -24,16 +23,16 @@ func _ready():
|
||||
print("GodotPayment singleton is only available on Android devices.")
|
||||
|
||||
if payment:
|
||||
# set callback with this script instance
|
||||
# Set callback with this script instance.
|
||||
payment.setPurchaseCallbackId(get_instance_id())
|
||||
|
||||
# set consume purchased item automatically after purchase, defulat value is true
|
||||
# Set consume purchased item automatically after purchase, default value is true.
|
||||
func set_auto_consume(auto):
|
||||
if payment:
|
||||
payment.setAutoConsume(auto)
|
||||
|
||||
|
||||
# request user owned item, callback : has_purchased
|
||||
# Request user owned item, callback: has_purchased.
|
||||
func request_purchased():
|
||||
if payment:
|
||||
payment.requestPurchased()
|
||||
@@ -54,49 +53,57 @@ func purchase(item_name):
|
||||
# transaction_id could be any string that used for validation internally in java
|
||||
payment.purchase(item_name, "transaction_id")
|
||||
|
||||
|
||||
func purchase_success(_receipt, _signature, sku):
|
||||
print("purchase_success : ", sku)
|
||||
emit_signal("purchase_success", sku)
|
||||
|
||||
|
||||
func purchase_fail():
|
||||
print("purchase_fail")
|
||||
emit_signal("purchase_fail")
|
||||
|
||||
|
||||
func purchase_cancel():
|
||||
print("purchase_cancel")
|
||||
emit_signal("purchase_cancel")
|
||||
|
||||
|
||||
func purchase_owned(sku):
|
||||
print("purchase_owned : ", sku)
|
||||
emit_signal("purchase_owned", sku)
|
||||
|
||||
|
||||
# consume purchased item
|
||||
# callback : consume_success, consume_fail
|
||||
# Consume purchased item.
|
||||
# Callback: consume_success, consume_fail
|
||||
func consume(item_name):
|
||||
if payment:
|
||||
payment.consume(item_name)
|
||||
|
||||
# consume all purchased items
|
||||
|
||||
# Consume all purchased items.
|
||||
func consume_all():
|
||||
if payment:
|
||||
payment.consumeUnconsumedPurchases()
|
||||
|
||||
|
||||
func consume_success(_receipt, _signature, sku):
|
||||
print("consume_success : ", sku)
|
||||
emit_signal("consume_success", sku)
|
||||
|
||||
# if consume fail, need to call request_purchased() to get purchase token from google
|
||||
# then try to consume again
|
||||
|
||||
# If consume fails, need to call request_purchased() to get purchase token from Google.
|
||||
# Then try to consume again.
|
||||
func consume_fail():
|
||||
emit_signal("consume_fail")
|
||||
|
||||
# no purchased item to consume
|
||||
|
||||
# No purchased item to consume.
|
||||
func consume_not_required():
|
||||
emit_signal("consume_not_required")
|
||||
|
||||
|
||||
# detail info of IAP items
|
||||
# Detail info of IAP items:
|
||||
# sku_details = {
|
||||
# product_id (String) : {
|
||||
# type (String),
|
||||
@@ -111,19 +118,21 @@ func consume_not_required():
|
||||
# }
|
||||
var sku_details = {}
|
||||
|
||||
# query for details of IAP items
|
||||
# callback : sku_details_complete
|
||||
# Query for details of IAP items.
|
||||
# Callback: sku_details_complete
|
||||
func sku_details_query(list):
|
||||
if payment:
|
||||
var sku_list = PoolStringArray(list)
|
||||
payment.querySkuDetails(sku_list)
|
||||
|
||||
|
||||
func sku_details_complete(result):
|
||||
print("sku_details_complete : ", result)
|
||||
for key in result.keys():
|
||||
sku_details[key] = result[key]
|
||||
emit_signal("sku_details_complete")
|
||||
|
||||
|
||||
func sku_details_error(error_message):
|
||||
print("error_sku_details = ", error_message)
|
||||
emit_signal("sku_details_error")
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Control
|
||||
|
||||
onready var alert = get_node("alert")
|
||||
@@ -24,47 +23,56 @@ func on_purchase_success(item_name):
|
||||
alert.set_text("Purchase success : " + item_name)
|
||||
alert.popup()
|
||||
|
||||
|
||||
func on_purchase_fail():
|
||||
alert.set_text("Purchase fail")
|
||||
alert.popup()
|
||||
|
||||
|
||||
func on_purchase_cancel():
|
||||
alert.set_text("Purchase cancel")
|
||||
alert.popup()
|
||||
|
||||
|
||||
func on_purchase_owned(item_name):
|
||||
alert.set_text("Purchase owned : " + item_name)
|
||||
alert.set_text("Purchase owned: " + item_name)
|
||||
alert.popup()
|
||||
|
||||
|
||||
func on_has_purchased(item_name):
|
||||
if item_name == null:
|
||||
alert.set_text("Don't have purchased item")
|
||||
else:
|
||||
alert.set_text("Has purchased : " + item_name)
|
||||
alert.set_text("Has purchased: " + item_name)
|
||||
alert.popup()
|
||||
|
||||
|
||||
func on_consume_success(item_name):
|
||||
alert.set_text("Consume success : " + item_name)
|
||||
alert.set_text("Consume success: " + item_name)
|
||||
alert.popup()
|
||||
|
||||
|
||||
func on_consume_fail():
|
||||
alert.set_text("Try to request purchased first")
|
||||
alert.popup()
|
||||
|
||||
|
||||
func on_sku_details_complete():
|
||||
alert.set_text("Got detail info : " + to_json(iap.sku_details["item_test_a"]))
|
||||
alert.set_text("Got detail info: " + to_json(iap.sku_details["item_test_a"]))
|
||||
alert.popup()
|
||||
|
||||
|
||||
func button_purchase():
|
||||
iap.purchase("item_tess")
|
||||
|
||||
|
||||
func button_consume():
|
||||
iap.consume("item_tess")
|
||||
|
||||
|
||||
func button_request():
|
||||
iap.request_purchased()
|
||||
|
||||
|
||||
func button_query():
|
||||
iap.sku_details_query(["item_test_a", "item_test_b"])
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -19,7 +19,7 @@ modules="org/godotengine/godot/GodotPaymentV3"
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Android IAP"
|
||||
config/name="Android in-app purchases"
|
||||
run/main_scene="res://main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
|
||||
@@ -8,12 +8,11 @@ bounce = 0.4
|
||||
[sub_resource type="CircleShape2D" id=2]
|
||||
radius = 30.0
|
||||
|
||||
[node name="ball" type="RigidBody2D"]
|
||||
[node name="Ball" type="RigidBody2D"]
|
||||
physics_material_override = SubResource( 1 )
|
||||
|
||||
[node name="sprite" type="Sprite" parent="."]
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="collision" type="CollisionShape2D" parent="."]
|
||||
[node name="Collision" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 2 )
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Position2D
|
||||
extends Node2D
|
||||
|
||||
export (PackedScene) var ball_scene = preload("res://ball.tscn")
|
||||
export(PackedScene) var ball_scene = preload("res://ball.tscn")
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event.is_echo():
|
||||
@@ -10,7 +10,7 @@ func _unhandled_input(event):
|
||||
spawn(get_global_mouse_position())
|
||||
|
||||
|
||||
func spawn(spawn_global_position = global_position):
|
||||
func spawn(spawn_global_position):
|
||||
var instance = ball_scene.instance()
|
||||
instance.global_position = spawn_global_position
|
||||
add_child(instance)
|
||||
|
||||
@@ -16,7 +16,7 @@ _global_script_class_icons={
|
||||
[application]
|
||||
|
||||
config/name="Scene Instancing Demo"
|
||||
run/main_scene="res://container.tscn"
|
||||
run/main_scene="res://scene_instancing.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[display]
|
||||
@@ -35,4 +35,4 @@ singletons=[ ]
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_clear_color=Color( 0.290196, 0.160784, 0.160784, 1 )
|
||||
environment/default_clear_color=Color( 0.301961, 0.301961, 0.301961, 1 )
|
||||
|
||||
@@ -33,57 +33,57 @@ bounce = 0.4
|
||||
[sub_resource type="PhysicsMaterial" id=10]
|
||||
bounce = 0.4
|
||||
|
||||
[node name="container" type="Node"]
|
||||
[node name="SceneInstancing" type="Node2D"]
|
||||
|
||||
[node name="ball_factory" type="Position2D" parent="."]
|
||||
[node name="BallFactory" type="Node2D" parent="."]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="static" type="StaticBody2D" parent="."]
|
||||
[node name="Static" type="StaticBody2D" parent="."]
|
||||
|
||||
[node name="collision" type="CollisionPolygon2D" parent="static"]
|
||||
[node name="Collision" type="CollisionPolygon2D" parent="Static"]
|
||||
polygon = PoolVector2Array( 8.68994, 22.1976, 50.4445, 556.656, 292.621, 501.54, 335.36, 550.855, 510.039, 563.135, 542.137, 526.368, 567.463, 515.822, 612.463, 506.822, 667.291, 495.079, 747.553, 553.575, 793.806, 6.70509, 802.465, 601.097, 4.43558, 596.186 )
|
||||
|
||||
[node name="polygon2d" type="Polygon2D" parent="static"]
|
||||
[node name="Polygon2D" type="Polygon2D" parent="Static"]
|
||||
color = Color( 1, 0.266667, 0.419608, 1 )
|
||||
polygon = PoolVector2Array( 8.68994, 22.1976, 50.4445, 556.656, 292.621, 501.54, 335.36, 550.855, 510.039, 563.135, 542.137, 526.368, 567.463, 515.822, 612.463, 506.822, 667.291, 495.079, 747.553, 553.575, 793.806, 6.70509, 802.465, 601.097, 4.43558, 596.186 )
|
||||
|
||||
[node name="ball 1" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball1" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 223.823, 161.773 )
|
||||
physics_material_override = SubResource( 1 )
|
||||
|
||||
[node name="ball 2" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball2" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 388.078, 213.215 )
|
||||
physics_material_override = SubResource( 2 )
|
||||
|
||||
[node name="ball 3" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball3" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 439.52, 104.013 )
|
||||
physics_material_override = SubResource( 3 )
|
||||
|
||||
[node name="ball 4" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball4" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 235.555, 336.858 )
|
||||
physics_material_override = SubResource( 4 )
|
||||
|
||||
[node name="ball 5" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball5" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 509.555, 362.858 )
|
||||
physics_material_override = SubResource( 5 )
|
||||
|
||||
[node name="ball 6" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball6" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 635.555, 147.858 )
|
||||
physics_material_override = SubResource( 6 )
|
||||
|
||||
[node name="ball 7" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball7" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 631.872, 325.88 )
|
||||
physics_material_override = SubResource( 7 )
|
||||
|
||||
[node name="ball 8" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball8" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 529.97, 205.561 )
|
||||
physics_material_override = SubResource( 8 )
|
||||
|
||||
[node name="ball 9" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball9" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 101.489, 167.502 )
|
||||
physics_material_override = SubResource( 9 )
|
||||
|
||||
[node name="ball 10" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Ball10" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 143.756, 295.139 )
|
||||
physics_material_override = SubResource( 10 )
|
||||
|
||||
@@ -7,26 +7,30 @@ extends Control
|
||||
#
|
||||
# Licensed under the MIT license
|
||||
|
||||
# Member variables
|
||||
const DEADZONE = 0.2
|
||||
|
||||
var joy_num
|
||||
var cur_joy = -1
|
||||
var axis_value
|
||||
|
||||
const DEADZONE = 0.2
|
||||
func _ready():
|
||||
set_physics_process(true)
|
||||
Input.connect("joy_connection_changed", self, "_on_joy_connection_changed")
|
||||
|
||||
|
||||
func _physics_process(_delta):
|
||||
# Get the joypad device number from the spinbox
|
||||
# Get the joypad device number from the spinbox.
|
||||
joy_num = get_node("device_info/joy_num").get_value()
|
||||
|
||||
# Display the name of the joypad if we haven't already
|
||||
# Display the name of the joypad if we haven't already.
|
||||
if joy_num != cur_joy:
|
||||
cur_joy = joy_num
|
||||
get_node("device_info/joy_name").set_text(Input.get_joy_name(joy_num))
|
||||
|
||||
# Loop through the axes and show their current values
|
||||
# Loop through the axes and show their current values.
|
||||
for axis in range(JOY_AXIS_0, JOY_AXIS_MAX):
|
||||
axis_value = Input.get_joy_axis(joy_num, axis)
|
||||
get_node("axes/axis_prog" + str(axis)).set_value(100*axis_value)
|
||||
get_node("axes/axis_prog" + str(axis)).set_value(100 * axis_value)
|
||||
get_node("axes/axis_val" + str(axis)).set_text(str(axis_value))
|
||||
# Show joypad direction indicators
|
||||
if axis <= JOY_ANALOG_RY:
|
||||
@@ -40,20 +44,17 @@ func _physics_process(_delta):
|
||||
get_node("diagram/axes/" + str(axis) + "+").hide()
|
||||
get_node("diagram/axes/" + str(axis) + "-").show()
|
||||
|
||||
# Loop through the buttons and highlight the ones that are pressed
|
||||
# Loop through the buttons and highlight the ones that are pressed.
|
||||
for btn in range(JOY_BUTTON_0, JOY_BUTTON_MAX):
|
||||
if Input.is_joy_button_pressed(joy_num, btn):
|
||||
get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1))
|
||||
get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color.white)
|
||||
get_node("diagram/buttons/" + str(btn)).show()
|
||||
else:
|
||||
get_node("buttons/btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1))
|
||||
get_node("diagram/buttons/" + str(btn)).hide()
|
||||
|
||||
func _ready():
|
||||
set_physics_process(true)
|
||||
Input.connect("joy_connection_changed", self, "_on_joy_connection_changed")
|
||||
|
||||
#Called whenever a joypad has been connected or disconnected.
|
||||
# Called whenever a joypad has been connected or disconnected.
|
||||
func _on_joy_connection_changed(device_id, connected):
|
||||
if device_id == cur_joy:
|
||||
if connected:
|
||||
@@ -61,12 +62,13 @@ func _on_joy_connection_changed(device_id, connected):
|
||||
else:
|
||||
get_node("device_info/joy_name").set_text("")
|
||||
|
||||
|
||||
func _on_start_vibration_pressed():
|
||||
var weak = get_node("vibration/vibration_weak_value").get_value()
|
||||
var strong = get_node("vibration/vibration_strong_value").get_value()
|
||||
var duration = get_node("vibration/vibration_duration_value").get_value()
|
||||
|
||||
Input.start_joy_vibration(cur_joy, weak, strong, duration)
|
||||
|
||||
|
||||
func _on_stop_vibration_pressed():
|
||||
Input.stop_joy_vibration(cur_joy)
|
||||
|
||||
@@ -27,4 +27,3 @@ near = 0.1
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = ExtResource( 1 )
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ var curr_state
|
||||
|
||||
var target_node
|
||||
|
||||
# We keep here a copy of the state before the number of fingers changed to avoid accumulation errors
|
||||
# We keep here a copy of the state before the number of fingers changed to avoid accumulation errors.
|
||||
var base_xform
|
||||
|
||||
func _ready():
|
||||
@@ -21,8 +21,9 @@ func _ready():
|
||||
curr_state = {}
|
||||
target_node = get_node(target)
|
||||
|
||||
|
||||
func _gui_input(event):
|
||||
# We must start touching inside, but we can drag or unpress outside
|
||||
# We must start touching inside, but we can drag or unpress outside.
|
||||
# if !(event is InputEventScreenDrag ||
|
||||
# (event is InputEventScreenTouch && (!event.pressed || get_global_rect().has_point(event.position)))):
|
||||
# return
|
||||
@@ -30,101 +31,96 @@ func _gui_input(event):
|
||||
var finger_count = base_state.size()
|
||||
|
||||
if finger_count == 0:
|
||||
# No fingers => Accept press
|
||||
|
||||
# No fingers => Accept press.
|
||||
if event is InputEventScreenTouch:
|
||||
if event.pressed:
|
||||
# A finger started touching
|
||||
# A finger started touching.
|
||||
|
||||
base_state = {
|
||||
event.index: event.position,
|
||||
}
|
||||
|
||||
elif finger_count == 1:
|
||||
# One finger => For rotating around X and Y
|
||||
# Accept one more press, unpress or drag
|
||||
|
||||
# One finger => For rotating around X and Y.
|
||||
# Accept one more press, unpress or drag.
|
||||
if event is InputEventScreenTouch:
|
||||
if event.pressed:
|
||||
# One more finger started touching
|
||||
# One more finger started touching.
|
||||
|
||||
# Reset the base state to the only current and the new fingers
|
||||
# Reset the base state to the only current and the new fingers.
|
||||
base_state = {
|
||||
curr_state.keys()[0]: curr_state.values()[0],
|
||||
event.index: event.position,
|
||||
}
|
||||
else:
|
||||
if base_state.has(event.index):
|
||||
# Only touching finger released
|
||||
# Only touching finger released.
|
||||
|
||||
base_state.clear()
|
||||
|
||||
elif event is InputEventScreenDrag:
|
||||
if curr_state.has(event.index):
|
||||
# Touching finger dragged
|
||||
|
||||
# Touching finger dragged.
|
||||
var unit_drag = _px2unit(base_state[base_state.keys()[0]] - event.position)
|
||||
if one_finger_rot_x:
|
||||
target_node.global_rotate(Vector3(0, 1, 0), deg2rad(180.0 * unit_drag.x))
|
||||
target_node.global_rotate(Vector3.UP, deg2rad(180.0 * unit_drag.x))
|
||||
if one_finger_rot_y:
|
||||
target_node.global_rotate(Vector3(1, 0, 0), deg2rad(180.0 * unit_drag.y))
|
||||
# Since rotating around two axes, we have to reset the base constantly
|
||||
target_node.global_rotate(Vector3.RIGHT, deg2rad(180.0 * unit_drag.y))
|
||||
# Since rotating around two axes, we have to reset the base constantly.
|
||||
curr_state[event.index] = event.position
|
||||
base_state[event.index] = event.position
|
||||
base_xform = target_node.get_transform()
|
||||
|
||||
elif finger_count == 2:
|
||||
# Two fingers => To pinch-zoom and rotate around Z
|
||||
# Accept unpress or drag
|
||||
|
||||
# Two fingers => To pinch-zoom and rotate around Z.
|
||||
# Accept unpress or drag.
|
||||
if event is InputEventScreenTouch:
|
||||
if !event.pressed && base_state.has(event.index):
|
||||
# Some known touching finger released
|
||||
# Some known touching finger released.
|
||||
|
||||
# Remove released finger from the base state
|
||||
# Remove released finger from the base state.
|
||||
base_state.erase(event.index)
|
||||
# Reset the base state to the now only toyching finger
|
||||
# Reset the base state to the now only toyching finger.
|
||||
base_state = {
|
||||
curr_state.keys()[0]: curr_state.values()[0],
|
||||
}
|
||||
|
||||
elif event is InputEventScreenDrag:
|
||||
if curr_state.has(event.index):
|
||||
# Some known touching finger dragged
|
||||
|
||||
# Update
|
||||
# Some known touching finger dragged.
|
||||
curr_state[event.index] = event.position
|
||||
|
||||
# Compute base and current inter-finger vectors
|
||||
# Compute base and current inter-finger vectors.
|
||||
var base_segment = base_state[base_state.keys()[0]] - base_state[base_state.keys()[1]]
|
||||
var new_segment = curr_state[curr_state.keys()[0]] - curr_state[curr_state.keys()[1]]
|
||||
|
||||
# Get the base scale from the base matrix
|
||||
# Get the base scale from the base matrix.
|
||||
var base_scale = Vector3(base_xform.basis.x.x, base_xform.basis.y.y, base_xform.basis.z.z).length()
|
||||
|
||||
if two_fingers_zoom:
|
||||
# Compute the new scale limiting it and taking into account the base scale
|
||||
# Compute the new scale limiting it and taking into account the base scale.
|
||||
var new_scale = clamp(base_scale * (new_segment.length() / base_segment.length()), min_scale, max_scale) / base_scale
|
||||
target_node.set_transform(base_xform.scaled(new_scale * Vector3(1, 1, 1)))
|
||||
target_node.set_transform(base_xform.scaled(new_scale * Vector3.ONE))
|
||||
else:
|
||||
target_node.set_transform(base_xform)
|
||||
|
||||
if two_fingers_rot_z:
|
||||
# Apply rotation between base inter-finger vector and the current one
|
||||
# Apply rotation between base inter-finger vector and the current one.
|
||||
var rot = new_segment.angle_to(base_segment)
|
||||
target_node.global_rotate(Vector3(0, 0, 1), rot)
|
||||
target_node.global_rotate(Vector3.BACK, rot)
|
||||
|
||||
# Finger count changed?
|
||||
if base_state.size() != finger_count:
|
||||
# Copy new base state to the current state
|
||||
# Copy new base state to the current state.
|
||||
curr_state = {}
|
||||
for idx in base_state.keys():
|
||||
curr_state[idx] = base_state[idx]
|
||||
# Remember the base transform
|
||||
# Remember the base transform.
|
||||
base_xform = target_node.get_transform()
|
||||
|
||||
|
||||
# Converts a vector in pixels to a unitary magnitude,
|
||||
# considering the number of pixels of the shorter axis is the unit
|
||||
# considering the number of pixels of the shorter axis is the unit.
|
||||
func _px2unit(v):
|
||||
var shortest = min(get_size().x, get_size().y)
|
||||
return v * (1.0 / shortest)
|
||||
|
||||
@@ -37,9 +37,6 @@ render_target_update_mode = 3
|
||||
|
||||
[node name="Spatial" parent="HBoxContainer/ViewportContainer/Viewport" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="DirectionalLight" parent="HBoxContainer/ViewportContainer/Viewport/Spatial" index="1"]
|
||||
light_cull_mask = 4294967295
|
||||
|
||||
[node name="Camera" parent="HBoxContainer/ViewportContainer/Viewport/Spatial" index="2"]
|
||||
current = true
|
||||
|
||||
@@ -72,9 +69,6 @@ render_target_update_mode = 3
|
||||
|
||||
[node name="Spatial" parent="HBoxContainer/ViewportContainer2/Viewport" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="DirectionalLight" parent="HBoxContainer/ViewportContainer2/Viewport/Spatial" index="1"]
|
||||
light_cull_mask = 4294967295
|
||||
|
||||
[node name="Camera" parent="HBoxContainer/ViewportContainer2/Viewport/Spatial" index="2"]
|
||||
current = true
|
||||
|
||||
@@ -112,9 +106,6 @@ render_target_update_mode = 3
|
||||
|
||||
[node name="Spatial" parent="HBoxContainer2/ViewportContainer/Viewport" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="DirectionalLight" parent="HBoxContainer2/ViewportContainer/Viewport/Spatial" index="1"]
|
||||
light_cull_mask = 4294967295
|
||||
|
||||
[node name="Camera" parent="HBoxContainer2/ViewportContainer/Viewport/Spatial" index="2"]
|
||||
current = true
|
||||
|
||||
@@ -145,9 +136,6 @@ render_target_update_mode = 3
|
||||
|
||||
[node name="Spatial" parent="HBoxContainer2/ViewportContainer2/Viewport" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="DirectionalLight" parent="HBoxContainer2/ViewportContainer2/Viewport/Spatial" index="1"]
|
||||
light_cull_mask = 4294967295
|
||||
|
||||
[node name="Camera" parent="HBoxContainer2/ViewportContainer2/Viewport/Spatial" index="2"]
|
||||
current = true
|
||||
|
||||
@@ -158,7 +146,6 @@ margin_right = 279.0
|
||||
margin_bottom = 23.0
|
||||
text = "One-finger X/Y, two-finger Z + pinch"
|
||||
|
||||
|
||||
[editable path="HBoxContainer/ViewportContainer/Viewport/Spatial"]
|
||||
|
||||
[editable path="HBoxContainer/ViewportContainer2/Viewport/Spatial"]
|
||||
|
||||
@@ -2,4 +2,3 @@
|
||||
|
||||
[resource]
|
||||
ambient_light_color = Color( 0.307434, 0.362682, 0.539063, 1 )
|
||||
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
extends Node2D
|
||||
|
||||
func _process(_delta):
|
||||
# To keep redrawing on every frame
|
||||
# Keep redrawing on every frame.
|
||||
update()
|
||||
|
||||
|
||||
func _draw():
|
||||
# Get the touch helper singleton
|
||||
# Get the touch helper singleton.
|
||||
var touch_helper = get_node("/root/TouchHelper")
|
||||
# Draw every pointer as a circle
|
||||
# Draw every pointer as a circle.
|
||||
for ptr_id in touch_helper.state.keys():
|
||||
var pos = touch_helper.state[ptr_id]
|
||||
var color = _get_color_for_ptr_id(ptr_id)
|
||||
color.a = 0.75
|
||||
draw_circle(pos, 40.0, color)
|
||||
|
||||
# Just a way of getting different colors
|
||||
|
||||
# Just a way of getting different colors.
|
||||
func _get_color_for_ptr_id(id):
|
||||
var x = (id % 7) + 1
|
||||
return Color(float(bool(x & 1)), float(bool(x & 2)), float(bool(x & 4)))
|
||||
|
||||
@@ -4,4 +4,3 @@
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ ground_curve = 0.01
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
|
||||
@@ -1,108 +1,91 @@
|
||||
extends Control
|
||||
|
||||
#The OpenSimplexNoise object
|
||||
# The OpenSimplexNoise object.
|
||||
var noise = OpenSimplexNoise.new()
|
||||
var noise_texture = NoiseTexture.new()
|
||||
|
||||
#Various noise parameters
|
||||
var noise_size = 500
|
||||
# Various noise parameters.
|
||||
var min_noise = -1
|
||||
var max_noise = 1
|
||||
|
||||
#Are we using a NoiseTexture instead?
|
||||
#Noise textures automatically grab and apply the noise data to an ImageTexture, instead of manually
|
||||
# Are we using a NoiseTexture instead?
|
||||
# Noise textures automatically grab and apply the noise data to an ImageTexture, instead of manually.
|
||||
const use_noise_texture = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
||||
#Set up noise with basic info
|
||||
# Set up noise with basic info.
|
||||
$ParameterContainer/SeedSpinBox.value = noise.seed
|
||||
$ParameterContainer/LacunaritySpinBox.value = noise.lacunarity
|
||||
$ParameterContainer/OctavesSpinBox.value = noise.octaves
|
||||
$ParameterContainer/PeriodSpinBox.value = noise.period
|
||||
$ParameterContainer/PersistenceSpinBox.value = noise.persistence
|
||||
|
||||
#Render the noise
|
||||
# Render the noise.
|
||||
_refresh_noise_images()
|
||||
|
||||
#Do we need to set up a noise texture?
|
||||
# Do we need to set up a noise texture?
|
||||
if use_noise_texture:
|
||||
noise_texture.noise = noise
|
||||
$SeamlessNoiseTexture.texture = noise_texture
|
||||
|
||||
|
||||
func _refresh_noise_images():
|
||||
|
||||
#Adjust min/max for shader
|
||||
# Adjust min/max for shader.
|
||||
var _min = ((min_noise + 1)/2)
|
||||
var _max = ((max_noise + 1)/2)
|
||||
var _material = $SeamlessNoiseTexture.material
|
||||
_material.set_shader_param("min_value", _min)
|
||||
_material.set_shader_param("max_value", _max)
|
||||
|
||||
#Are we using noise textures instead?
|
||||
# Are we using noise textures instead?
|
||||
if use_noise_texture:
|
||||
return
|
||||
|
||||
#Get a new image if we aren't using a NoiseTexture
|
||||
# Get a new image if we aren't using a NoiseTexture.
|
||||
var image = noise.get_seamless_image(500)
|
||||
var image_texture = ImageTexture.new()
|
||||
|
||||
#Draw it
|
||||
# Draw it.
|
||||
image_texture.create_from_image(image)
|
||||
$SeamlessNoiseTexture.texture = image_texture
|
||||
|
||||
|
||||
func _on_DocumentationButton_pressed():
|
||||
#warning-ignore:return_value_discarded
|
||||
OS.shell_open("https://docs.godotengine.org/en/latest/classes/class_opensimplexnoise.html")
|
||||
|
||||
|
||||
func _on_SeedSpinBox_value_changed(value):
|
||||
|
||||
#Update the noise seed
|
||||
noise.seed = value
|
||||
_refresh_noise_images()
|
||||
|
||||
|
||||
func _on_LacunaritySpinBox_value_changed(value):
|
||||
|
||||
#Update noise
|
||||
noise.lacunarity = value
|
||||
_refresh_noise_images()
|
||||
|
||||
|
||||
func _on_OctavesSpinBox_value_changed(value):
|
||||
|
||||
#Update noise
|
||||
noise.octaves = value
|
||||
_refresh_noise_images()
|
||||
|
||||
|
||||
func _on_PeriodSpinBox_value_changed(value):
|
||||
|
||||
#Update noise
|
||||
noise.period = value
|
||||
_refresh_noise_images()
|
||||
|
||||
|
||||
func _on_PersistenceSpinBox_value_changed(value):
|
||||
|
||||
#Update noise
|
||||
noise.persistence = value
|
||||
_refresh_noise_images()
|
||||
|
||||
|
||||
func _on_MinClipSpinBox_value_changed(value):
|
||||
|
||||
#Just refresh
|
||||
min_noise = value
|
||||
_refresh_noise_images()
|
||||
|
||||
|
||||
func _on_MaxClipSpinBox_value_changed(value):
|
||||
|
||||
#Just refresh
|
||||
max_noise = value
|
||||
_refresh_noise_images()
|
||||
|
||||
|
||||
@@ -4,18 +4,17 @@ uniform float min_value = -1;
|
||||
uniform float max_value = 1;
|
||||
|
||||
void fragment() {
|
||||
|
||||
//Get the color
|
||||
// Get the color.
|
||||
vec4 color = texture(TEXTURE, UV);
|
||||
|
||||
//Compare the value
|
||||
// Compare the value.
|
||||
float gray = color.x;
|
||||
if (gray < min_value){
|
||||
if (gray < min_value) {
|
||||
color = vec4(0, 0, 0, 1);
|
||||
}else if (gray > max_value) {
|
||||
} else if (gray > max_value) {
|
||||
color = vec4(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
//Write back the color
|
||||
// Write back the color.
|
||||
COLOR = color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
extends Button
|
||||
|
||||
func _ready():
|
||||
#This ensures that this Node won't be paused, allowing it to
|
||||
#process even when the SceneTree is paused. Without that it would
|
||||
#not be able to unpause the game. Note that you can set this through
|
||||
#the inspector as well
|
||||
# This ensures that this Node won't be paused, allowing it to
|
||||
# process even when the SceneTree is paused. Without that it would
|
||||
# not be able to unpause the game. Note that you can set this through
|
||||
# the inspector as well.
|
||||
pause_mode = Node.PAUSE_MODE_PROCESS
|
||||
|
||||
|
||||
func _toggled(button_pressed):
|
||||
#Pause or unpause the SceneTree based on whether the button is
|
||||
#toggled on or off
|
||||
# Pause or unpause the SceneTree based on whether the button is
|
||||
# toggled on or off.
|
||||
get_tree().paused = button_pressed
|
||||
if button_pressed:
|
||||
text = "Unpause"
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
extends Spatial
|
||||
|
||||
func _on_pause_pressed():
|
||||
get_node("pause_popup").set_exclusive(true)
|
||||
get_node("pause_popup").popup()
|
||||
get_tree().set_pause(true)
|
||||
|
||||
func _on_unpause_pressed():
|
||||
get_node("pause_popup").hide()
|
||||
get_tree().set_pause(false)
|
||||
@@ -8,7 +8,7 @@
|
||||
length = 10.0
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("cube:rotation_degrees")
|
||||
tracks/0/path = NodePath("Cube:rotation_degrees")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
@@ -20,26 +20,26 @@ tracks/0/keys = {
|
||||
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, -360, 0 ) ]
|
||||
}
|
||||
|
||||
[node name="pause_scene" type="Spatial"]
|
||||
[node name="PauseScene" type="Spatial"]
|
||||
|
||||
[node name="cube" type="MeshInstance" parent="."]
|
||||
[node name="Cube" type="MeshInstance" parent="."]
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = null
|
||||
|
||||
[node name="camera" type="Camera" parent="."]
|
||||
[node name="Camera" type="Camera" parent="."]
|
||||
transform = Transform( 0.571594, 0.275303, -0.772974, 0, 0.942035, 0.335515, 0.820537, -0.191779, 0.538461, -5.59754, 2.75935, 4.01344 )
|
||||
fov = 74.0
|
||||
near = 0.1
|
||||
|
||||
[node name="anim" type="AnimationPlayer" parent="."]
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
autoplay = "spin"
|
||||
anims/spin = SubResource( 2 )
|
||||
|
||||
[node name="spot" type="SpotLight" parent="."]
|
||||
[node name="SpotLight" type="SpotLight" parent="."]
|
||||
transform = Transform( 0.792992, 0.251051, -0.555101, 0, 0.911149, 0.412078, 0.609232, -0.326775, 0.722534, -3.05357, 1.80053, 3.64099 )
|
||||
spot_range = 6.0
|
||||
|
||||
[node name="pause_button" type="Button" parent="."]
|
||||
[node name="PauseButton" type="Button" parent="."]
|
||||
pause_mode = 2
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
extends VBoxContainer
|
||||
|
||||
# Member variables
|
||||
var regex = RegEx.new()
|
||||
|
||||
func _ready():
|
||||
$Text.set_text("They asked me \"What's going on \\\"in the manor\\\"?\"")
|
||||
update_expression($Expression.text)
|
||||
|
||||
|
||||
func update_expression(text):
|
||||
regex.compile(text)
|
||||
update_text()
|
||||
|
||||
|
||||
func update_text():
|
||||
for child in $List.get_children():
|
||||
child.queue_free()
|
||||
@@ -17,7 +22,3 @@ func update_text():
|
||||
var label = Label.new()
|
||||
label.text = result
|
||||
$List.add_child(label)
|
||||
|
||||
func _ready():
|
||||
$Text.set_text("They asked me \"What's going on \\\"in the manor\\\"?\"")
|
||||
update_expression($Expression.text)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource path="res://regex.gd" type="Script" id=1]
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer"]
|
||||
[node name="Regex" type="VBoxContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 14.0
|
||||
|
||||
@@ -1,45 +1,54 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# Member variables
|
||||
var trans = ["linear", "sine", "quint", "quart", "quad", "expo", "elastic", "cubic", "circ", "bounce", "back"]
|
||||
var eases = ["in", "out", "in_out", "out_in"]
|
||||
var modes = ["move", "color", "scale", "rotate", "callback", "follow", "repeat", "pause"]
|
||||
const trans_list = ["Linear", "Sine", "Quint", "Quart", "Quad", "Expo", "Elastic", "Cubic", "Circ", "Bounce", "Back"]
|
||||
const eases_list = ["In", "Out", "InOut", "OutIn"]
|
||||
const modes_list = ["Move", "Color", "Scale", "Rotate", "Callback", "Follow", "Repeat", "Pause"]
|
||||
|
||||
var state = {
|
||||
trans = Tween.TRANS_LINEAR,
|
||||
eases = Tween.EASE_IN,
|
||||
}
|
||||
|
||||
onready var trans = $Trans
|
||||
onready var eases = $Eases
|
||||
onready var modes = $Modes
|
||||
onready var tween = $Tween
|
||||
onready var timeline = $Timeline
|
||||
onready var color_from_picker = $Colors/ColorFrom/Picker
|
||||
onready var color_to_picker = $Colors/ColorTo/Picker
|
||||
onready var sprite = $Tween/Area/Sprite
|
||||
onready var follow = $Tween/Area/Follow
|
||||
onready var follow_2 = $Tween/Area/Follow2
|
||||
onready var size = $Tween/Area.get_size()
|
||||
|
||||
func _ready():
|
||||
for index in range(trans.size()):
|
||||
get_node("trans/" + trans[index]).connect("pressed", self, "on_trans_changed", [trans[index], index])
|
||||
for index in range(trans_list.size()):
|
||||
trans.get_node(trans_list[index]).connect("pressed", self, "on_trans_changed", [trans_list[index], index])
|
||||
|
||||
for index in range(eases.size()):
|
||||
get_node("eases/" + eases[index]).connect("pressed", self, "on_eases_changed", [eases[index], index])
|
||||
for index in range(eases_list.size()):
|
||||
eases.get_node(eases_list[index]).connect("pressed", self, "on_eases_changed", [eases_list[index], index])
|
||||
|
||||
for index in range(modes.size()):
|
||||
get_node("modes/" + modes[index]).connect("pressed", self, "on_modes_changed", [modes[index]])
|
||||
for index in range(modes_list.size()):
|
||||
modes.get_node(modes_list[index]).connect("pressed", self, "on_modes_changed", [modes_list[index]])
|
||||
|
||||
get_node("colors/color_from/picker").set_pick_color(Color(1, 0, 0, 1))
|
||||
get_node("colors/color_from/picker").connect("color_changed", self, "on_color_changed")
|
||||
color_from_picker.set_pick_color(Color.red)
|
||||
color_from_picker.connect("color_changed", self, "on_color_changed")
|
||||
|
||||
get_node("colors/color_to/picker").set_pick_color(Color(0, 1, 1, 1))
|
||||
get_node("colors/color_to/picker").connect("color_changed", self, "on_color_changed")
|
||||
color_to_picker.set_pick_color(Color.cyan)
|
||||
color_to_picker.connect("color_changed", self, "on_color_changed")
|
||||
|
||||
get_node("trans/linear").set_pressed(true)
|
||||
get_node("eases/in").set_pressed(true)
|
||||
get_node("modes/move").set_pressed(true)
|
||||
get_node("modes/repeat").set_pressed(true)
|
||||
$Trans/Linear.set_pressed(true)
|
||||
$Eases/In.set_pressed(true)
|
||||
$Modes/Move.set_pressed(true)
|
||||
$Modes/Repeat.set_pressed(true)
|
||||
|
||||
reset_tween()
|
||||
|
||||
|
||||
func on_trans_changed(trans_name, index):
|
||||
for index in range(trans.size()):
|
||||
var pressed = trans[index] == trans_name
|
||||
var btn = get_node("trans/" + trans[index])
|
||||
for index in range(trans_list.size()):
|
||||
var pressed = trans_list[index] == trans_name
|
||||
var btn = trans.get_node(trans_list[index])
|
||||
|
||||
btn.set_pressed(pressed)
|
||||
set_mouse_filter(Control.MOUSE_FILTER_IGNORE if pressed else Control.MOUSE_FILTER_PASS)
|
||||
@@ -49,9 +58,9 @@ func on_trans_changed(trans_name, index):
|
||||
|
||||
|
||||
func on_eases_changed(ease_name, index):
|
||||
for index in range(eases.size()):
|
||||
var pressed = eases[index] == ease_name
|
||||
var btn = get_node("eases/" + eases[index])
|
||||
for index in range(eases_list.size()):
|
||||
var pressed = eases_list[index] == ease_name
|
||||
var btn = eases.get_node(eases_list[index])
|
||||
|
||||
btn.set_pressed(pressed)
|
||||
set_mouse_filter(Control.MOUSE_FILTER_IGNORE if pressed else Control.MOUSE_FILTER_PASS)
|
||||
@@ -61,14 +70,13 @@ func on_eases_changed(ease_name, index):
|
||||
|
||||
|
||||
func on_modes_changed(mode_name):
|
||||
var tween = get_node("tween")
|
||||
if mode_name == "pause":
|
||||
if get_node("modes/pause").is_pressed():
|
||||
if $Modes/Pause.is_pressed():
|
||||
tween.stop_all()
|
||||
get_node("timeline").set_mouse_filter(Control.MOUSE_FILTER_PASS)
|
||||
timeline.set_mouse_filter(Control.MOUSE_FILTER_PASS)
|
||||
else:
|
||||
tween.resume_all()
|
||||
get_node("timeline").set_mouse_filter(Control.MOUSE_FILTER_IGNORE)
|
||||
timeline.set_mouse_filter(Control.MOUSE_FILTER_IGNORE)
|
||||
else:
|
||||
reset_tween()
|
||||
|
||||
@@ -78,41 +86,35 @@ func on_color_changed(_color):
|
||||
|
||||
|
||||
func reset_tween():
|
||||
var tween = get_node("tween")
|
||||
var pos = tween.tell()
|
||||
tween.reset_all()
|
||||
tween.remove_all()
|
||||
|
||||
var sprite = get_node("tween/area/sprite")
|
||||
var follow = get_node("tween/area/follow")
|
||||
var follow_2 = get_node("tween/area/follow_2")
|
||||
var size = get_node("tween/area").get_size()
|
||||
|
||||
if get_node("modes/move").is_pressed():
|
||||
if $Modes/Move.is_pressed():
|
||||
tween.interpolate_method(sprite, "set_position", Vector2(0, 0), Vector2(size.x, size.y), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "position", Vector2(size.x, size.y), Vector2(0, 0), 2, state.trans, state.eases, 2)
|
||||
|
||||
if get_node("modes/color").is_pressed():
|
||||
tween.interpolate_method(sprite, "set_modulate", get_node("colors/color_from/picker").get_pick_color(), get_node("colors/color_to/picker").get_pick_color(), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "modulate", get_node("colors/color_to/picker").get_pick_color(), get_node("colors/color_from/picker").get_pick_color(), 2, state.trans, state.eases, 2)
|
||||
if $Modes/Color.is_pressed():
|
||||
tween.interpolate_method(sprite, "set_modulate", color_from_picker.get_pick_color(), color_to_picker.get_pick_color(), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "modulate", color_to_picker.get_pick_color(), color_from_picker.get_pick_color(), 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
sprite.set_modulate(Color(1, 1, 1, 1))
|
||||
sprite.set_modulate(Color.white)
|
||||
|
||||
if get_node("modes/scale").is_pressed():
|
||||
if $Modes/Scale.is_pressed():
|
||||
tween.interpolate_method(sprite, "set_scale", Vector2(0.5, 0.5), Vector2(1.5, 1.5), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "scale", Vector2(1.5, 1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
sprite.set_scale(Vector2(1, 1))
|
||||
sprite.set_scale(Vector2.ONE)
|
||||
|
||||
if get_node("modes/rotate").is_pressed():
|
||||
if $Modes/Rotate.is_pressed():
|
||||
tween.interpolate_method(sprite, "set_rotation_degrees", 0, 360, 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "rotation_degrees", 360, 0, 2, state.trans, state.eases, 2)
|
||||
|
||||
if get_node("modes/callback").is_pressed():
|
||||
if $Modes/Callback.is_pressed():
|
||||
tween.interpolate_callback(self, 0.5, "on_callback", "0.5 second's after")
|
||||
tween.interpolate_callback(self, 0.2, "on_callback", "1.2 second's after")
|
||||
|
||||
if get_node("modes/follow").is_pressed():
|
||||
if $Modes/Follow.is_pressed():
|
||||
follow.show()
|
||||
follow_2.show()
|
||||
|
||||
@@ -125,38 +127,31 @@ func reset_tween():
|
||||
follow.hide()
|
||||
follow_2.hide()
|
||||
|
||||
tween.set_repeat(get_node("modes/repeat").is_pressed())
|
||||
tween.set_repeat($Modes/Repeat.is_pressed())
|
||||
tween.start()
|
||||
tween.seek(pos)
|
||||
|
||||
if get_node("modes/pause").is_pressed():
|
||||
if $Modes/Pause.is_pressed():
|
||||
tween.stop_all()
|
||||
#get_node("timeline").set_ignore_mouse(false)
|
||||
get_node("timeline").set_value(0)
|
||||
timeline.set_value(0)
|
||||
else:
|
||||
tween.resume_all()
|
||||
#get_node("timeline").set_ignore_mouse(true)
|
||||
|
||||
|
||||
func _on_tween_step(_object, _key, elapsed, _value):
|
||||
var timeline = get_node("timeline")
|
||||
|
||||
var tween = get_node("tween")
|
||||
var runtime = tween.get_runtime()
|
||||
|
||||
var ratio = 100 * (elapsed / runtime)
|
||||
timeline.set_value(ratio)
|
||||
|
||||
|
||||
func _on_timeline_value_changed(value):
|
||||
if !get_node("modes/pause").is_pressed():
|
||||
if !$Modes/Pause.is_pressed():
|
||||
return
|
||||
|
||||
var tween = get_node("tween")
|
||||
var runtime = tween.get_runtime()
|
||||
tween.seek(runtime * value / 100)
|
||||
|
||||
|
||||
func on_callback(arg):
|
||||
var label = get_node("tween/area/label")
|
||||
label.add_text("on_callback -> " + arg + "\n")
|
||||
$Tween/Area/Label.add_text("on_callback -> " + arg + "\n")
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[ext_resource path="res://main.gd" type="Script" id=1]
|
||||
[ext_resource path="res://godot.png" type="Texture" id=2]
|
||||
|
||||
[node name="main" type="Control"]
|
||||
[node name="Main" type="Control"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
@@ -19,7 +19,7 @@ __meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="trans" type="VBoxContainer" parent="."]
|
||||
[node name="Trans" type="VBoxContainer" parent="."]
|
||||
margin_left = 56.0
|
||||
margin_top = 288.0
|
||||
margin_right = 129.0
|
||||
@@ -27,7 +27,7 @@ margin_bottom = 614.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="linear" type="Button" parent="trans"]
|
||||
[node name="Linear" type="Button" parent="Trans"]
|
||||
margin_right = 48.0
|
||||
margin_bottom = 20.0
|
||||
size_flags_horizontal = 2
|
||||
@@ -35,7 +35,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "linear"
|
||||
|
||||
[node name="sine" type="Button" parent="trans"]
|
||||
[node name="Sine" type="Button" parent="Trans"]
|
||||
margin_top = 30.0
|
||||
margin_right = 39.0
|
||||
margin_bottom = 50.0
|
||||
@@ -44,7 +44,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "sine"
|
||||
|
||||
[node name="quint" type="Button" parent="trans"]
|
||||
[node name="Quint" type="Button" parent="Trans"]
|
||||
margin_top = 60.0
|
||||
margin_right = 45.0
|
||||
margin_bottom = 80.0
|
||||
@@ -53,7 +53,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "quint"
|
||||
|
||||
[node name="quart" type="Button" parent="trans"]
|
||||
[node name="Quart" type="Button" parent="Trans"]
|
||||
margin_top = 90.0
|
||||
margin_right = 45.0
|
||||
margin_bottom = 110.0
|
||||
@@ -62,7 +62,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "quart"
|
||||
|
||||
[node name="quad" type="Button" parent="trans"]
|
||||
[node name="Quad" type="Button" parent="Trans"]
|
||||
margin_top = 120.0
|
||||
margin_right = 43.0
|
||||
margin_bottom = 140.0
|
||||
@@ -71,7 +71,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "quad"
|
||||
|
||||
[node name="expo" type="Button" parent="trans"]
|
||||
[node name="Expo" type="Button" parent="Trans"]
|
||||
margin_top = 150.0
|
||||
margin_right = 43.0
|
||||
margin_bottom = 170.0
|
||||
@@ -80,7 +80,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "expo"
|
||||
|
||||
[node name="elastic" type="Button" parent="trans"]
|
||||
[node name="Elastic" type="Button" parent="Trans"]
|
||||
margin_top = 180.0
|
||||
margin_right = 54.0
|
||||
margin_bottom = 200.0
|
||||
@@ -89,7 +89,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "elastic"
|
||||
|
||||
[node name="cubic" type="Button" parent="trans"]
|
||||
[node name="Cubic" type="Button" parent="Trans"]
|
||||
margin_top = 210.0
|
||||
margin_right = 46.0
|
||||
margin_bottom = 230.0
|
||||
@@ -98,7 +98,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "cubic"
|
||||
|
||||
[node name="circ" type="Button" parent="trans"]
|
||||
[node name="Circ" type="Button" parent="Trans"]
|
||||
margin_top = 240.0
|
||||
margin_right = 35.0
|
||||
margin_bottom = 260.0
|
||||
@@ -107,7 +107,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "circ"
|
||||
|
||||
[node name="bounce" type="Button" parent="trans"]
|
||||
[node name="Bounce" type="Button" parent="Trans"]
|
||||
margin_top = 270.0
|
||||
margin_right = 59.0
|
||||
margin_bottom = 290.0
|
||||
@@ -116,7 +116,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "bounce"
|
||||
|
||||
[node name="back" type="Button" parent="trans"]
|
||||
[node name="Back" type="Button" parent="Trans"]
|
||||
margin_top = 300.0
|
||||
margin_right = 41.0
|
||||
margin_bottom = 320.0
|
||||
@@ -125,7 +125,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "back"
|
||||
|
||||
[node name="eases" type="VBoxContainer" parent="."]
|
||||
[node name="Eases" type="VBoxContainer" parent="."]
|
||||
margin_left = 152.0
|
||||
margin_top = 288.0
|
||||
margin_right = 215.0
|
||||
@@ -133,7 +133,7 @@ margin_bottom = 404.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="in" type="Button" parent="eases"]
|
||||
[node name="In" type="Button" parent="Eases"]
|
||||
margin_right = 24.0
|
||||
margin_bottom = 20.0
|
||||
size_flags_horizontal = 2
|
||||
@@ -141,7 +141,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "in"
|
||||
|
||||
[node name="out" type="Button" parent="eases"]
|
||||
[node name="Out" type="Button" parent="Eases"]
|
||||
margin_top = 30.0
|
||||
margin_right = 33.0
|
||||
margin_bottom = 50.0
|
||||
@@ -150,7 +150,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "out"
|
||||
|
||||
[node name="in_out" type="Button" parent="eases"]
|
||||
[node name="InOut" type="Button" parent="Eases"]
|
||||
margin_top = 60.0
|
||||
margin_right = 51.0
|
||||
margin_bottom = 80.0
|
||||
@@ -159,7 +159,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "in_out"
|
||||
|
||||
[node name="out_in" type="Button" parent="eases"]
|
||||
[node name="OutIn" type="Button" parent="Eases"]
|
||||
margin_top = 90.0
|
||||
margin_right = 51.0
|
||||
margin_bottom = 110.0
|
||||
@@ -168,7 +168,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "out_in"
|
||||
|
||||
[node name="modes" type="VBoxContainer" parent="."]
|
||||
[node name="Modes" type="VBoxContainer" parent="."]
|
||||
margin_left = 240.0
|
||||
margin_top = 288.0
|
||||
margin_right = 317.0
|
||||
@@ -176,7 +176,7 @@ margin_bottom = 524.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="move" type="Button" parent="modes"]
|
||||
[node name="Move" type="Button" parent="Modes"]
|
||||
margin_right = 48.0
|
||||
margin_bottom = 20.0
|
||||
size_flags_horizontal = 2
|
||||
@@ -184,7 +184,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "move"
|
||||
|
||||
[node name="color" type="Button" parent="modes"]
|
||||
[node name="Color" type="Button" parent="Modes"]
|
||||
margin_top = 30.0
|
||||
margin_right = 44.0
|
||||
margin_bottom = 50.0
|
||||
@@ -193,7 +193,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "color"
|
||||
|
||||
[node name="scale" type="Button" parent="modes"]
|
||||
[node name="Scale" type="Button" parent="Modes"]
|
||||
margin_top = 60.0
|
||||
margin_right = 45.0
|
||||
margin_bottom = 80.0
|
||||
@@ -202,7 +202,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "scale"
|
||||
|
||||
[node name="rotate" type="Button" parent="modes"]
|
||||
[node name="Rotate" type="Button" parent="Modes"]
|
||||
margin_top = 90.0
|
||||
margin_right = 50.0
|
||||
margin_bottom = 110.0
|
||||
@@ -211,7 +211,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "rotate"
|
||||
|
||||
[node name="callback" type="Button" parent="modes"]
|
||||
[node name="Callback" type="Button" parent="Modes"]
|
||||
margin_top = 120.0
|
||||
margin_right = 63.0
|
||||
margin_bottom = 140.0
|
||||
@@ -220,7 +220,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "callback"
|
||||
|
||||
[node name="follow" type="Button" parent="modes"]
|
||||
[node name="Follow" type="Button" parent="Modes"]
|
||||
margin_top = 150.0
|
||||
margin_right = 50.0
|
||||
margin_bottom = 170.0
|
||||
@@ -229,7 +229,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "follow"
|
||||
|
||||
[node name="repeat" type="Button" parent="modes"]
|
||||
[node name="Repeat" type="Button" parent="Modes"]
|
||||
margin_top = 180.0
|
||||
margin_right = 53.0
|
||||
margin_bottom = 200.0
|
||||
@@ -238,7 +238,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "repeat"
|
||||
|
||||
[node name="pause" type="Button" parent="modes"]
|
||||
[node name="Pause" type="Button" parent="Modes"]
|
||||
margin_top = 210.0
|
||||
margin_right = 50.0
|
||||
margin_bottom = 230.0
|
||||
@@ -247,7 +247,7 @@ size_flags_vertical = 2
|
||||
toggle_mode = true
|
||||
text = "pause"
|
||||
|
||||
[node name="colors" type="HBoxContainer" parent="."]
|
||||
[node name="Colors" type="HBoxContainer" parent="."]
|
||||
margin_left = 352.0
|
||||
margin_top = 273.0
|
||||
margin_right = 1008.0
|
||||
@@ -259,56 +259,56 @@ __meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="color_from" type="VBoxContainer" parent="colors"]
|
||||
margin_right = 308.0
|
||||
[node name="ColorFrom" type="VBoxContainer" parent="Colors"]
|
||||
margin_right = 290.0
|
||||
margin_bottom = 480.0
|
||||
rect_min_size = Vector2( 0, 320 )
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="label" type="Label" parent="colors/color_from"]
|
||||
[node name="Label" type="Label" parent="Colors/ColorFrom"]
|
||||
margin_right = 74.0
|
||||
margin_bottom = 14.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 0
|
||||
text = "Color From:"
|
||||
|
||||
[node name="picker" type="ColorPicker" parent="colors/color_from"]
|
||||
[node name="Picker" type="ColorPicker" parent="Colors/ColorFrom"]
|
||||
margin_top = 18.0
|
||||
margin_right = 308.0
|
||||
margin_right = 290.0
|
||||
margin_bottom = 480.0
|
||||
rect_min_size = Vector2( 0, 320 )
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="color_to" type="VBoxContainer" parent="colors"]
|
||||
[node name="ColorTo" type="VBoxContainer" parent="Colors"]
|
||||
margin_left = 348.0
|
||||
margin_right = 656.0
|
||||
margin_right = 638.0
|
||||
margin_bottom = 480.0
|
||||
rect_min_size = Vector2( 0, 320 )
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="label" type="Label" parent="colors/color_to"]
|
||||
[node name="Label" type="Label" parent="Colors/ColorTo"]
|
||||
margin_right = 56.0
|
||||
margin_bottom = 14.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 0
|
||||
text = "Color To:"
|
||||
|
||||
[node name="picker" type="ColorPicker" parent="colors/color_to"]
|
||||
[node name="Picker" type="ColorPicker" parent="Colors/ColorTo"]
|
||||
margin_top = 18.0
|
||||
margin_right = 308.0
|
||||
margin_right = 290.0
|
||||
margin_bottom = 480.0
|
||||
rect_min_size = Vector2( 0, 320 )
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="tween" type="Tween" parent="."]
|
||||
[node name="Tween" type="Tween" parent="."]
|
||||
repeat = true
|
||||
playback/repeat = true
|
||||
|
||||
[node name="area" type="Panel" parent="tween"]
|
||||
[node name="Area" type="Panel" parent="Tween"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
@@ -320,7 +320,7 @@ margin_bottom = -152.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="label" type="RichTextLabel" parent="tween/area"]
|
||||
[node name="Label" type="RichTextLabel" parent="Tween/Area"]
|
||||
margin_left = 176.0
|
||||
margin_top = 24.0
|
||||
margin_right = 552.0
|
||||
@@ -328,18 +328,18 @@ margin_bottom = 160.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="sprite" type="Sprite" parent="tween/area"]
|
||||
[node name="Sprite" type="Sprite" parent="Tween/Area"]
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="follow" type="Sprite" parent="tween/area"]
|
||||
[node name="Follow" type="Sprite" parent="Tween/Area"]
|
||||
position = Vector2( 0, 184 )
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="follow_2" type="Sprite" parent="tween/area"]
|
||||
[node name="Follow2" type="Sprite" parent="Tween/Area"]
|
||||
position = Vector2( 736, 0 )
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="timeline" type="HSlider" parent="."]
|
||||
[node name="Timeline" type="HSlider" parent="."]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
@@ -350,8 +350,9 @@ margin_right = 416.0
|
||||
margin_bottom = -128.0
|
||||
size_flags_horizontal = 2
|
||||
value = 1.0
|
||||
ticks_on_borders = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="tween_step" from="tween" to="." method="_on_tween_step"]
|
||||
[connection signal="value_changed" from="timeline" to="." method="_on_timeline_value_changed"]
|
||||
[connection signal="tween_step" from="Tween" to="." method="_on_tween_step"]
|
||||
[connection signal="value_changed" from="Timeline" to="." method="_on_timeline_value_changed"]
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
extends Control
|
||||
|
||||
# Member variables
|
||||
var mousepos
|
||||
|
||||
onready var observer = $"../Observer"
|
||||
|
||||
func _ready():
|
||||
if not check_wm_api():
|
||||
set_physics_process(false)
|
||||
set_process_input(false)
|
||||
|
||||
|
||||
func _physics_process(_delta):
|
||||
var modetext = "Mode:\n"
|
||||
|
||||
if OS.is_window_fullscreen():
|
||||
modetext += "Fullscreen\n"
|
||||
else:
|
||||
modetext += "Windowed\n"
|
||||
|
||||
if !OS.is_window_resizable():
|
||||
modetext += "FixedSize\n"
|
||||
|
||||
if OS.is_window_minimized():
|
||||
modetext += "Minimized\n"
|
||||
|
||||
if OS.is_window_maximized():
|
||||
modetext += "Maximized\n"
|
||||
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
modetext += "MouseGrab\n"
|
||||
$Label_MouseModeCaptured_KeyInfo.show()
|
||||
@@ -63,73 +63,6 @@ func _physics_process(_delta):
|
||||
$Button_MouseModeCaptured.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
|
||||
func check_wm_api():
|
||||
var s = ""
|
||||
if !OS.has_method("get_screen_count"):
|
||||
s += " - get_screen_count()\n"
|
||||
|
||||
if !OS.has_method("get_current_screen"):
|
||||
s += " - get_current_screen()\n"
|
||||
|
||||
if !OS.has_method("set_current_screen"):
|
||||
s += " - set_current_screen()\n"
|
||||
|
||||
if !OS.has_method("get_screen_position"):
|
||||
s += " - get_screen_position()\n"
|
||||
|
||||
if !OS.has_method("get_screen_size"):
|
||||
s += " - get_screen_size()\n"
|
||||
|
||||
if !OS.has_method("get_window_position"):
|
||||
s += " - get_window_position()\n"
|
||||
|
||||
if !OS.has_method("set_window_position"):
|
||||
s += " - set_window_position()\n"
|
||||
|
||||
if !OS.has_method("get_window_size"):
|
||||
s += " - get_window_size()\n"
|
||||
|
||||
if !OS.has_method("set_window_size"):
|
||||
s += " - set_window_size()\n"
|
||||
|
||||
if !OS.has_method("set_window_fullscreen"):
|
||||
s += " - set_window_fullscreen()\n"
|
||||
|
||||
if !OS.has_method("is_window_fullscreen"):
|
||||
s += " - is_window_fullscreen()\n"
|
||||
|
||||
if !OS.has_method("set_window_resizable"):
|
||||
s += " - set_window_resizable()\n"
|
||||
|
||||
if !OS.has_method("is_window_resizable"):
|
||||
s += " - is_window_resizable()\n"
|
||||
|
||||
if !OS.has_method("set_window_minimized"):
|
||||
s += " - set_window_minimized()\n"
|
||||
|
||||
if !OS.has_method("is_window_minimized"):
|
||||
s += " - is_window_minimized()\n"
|
||||
|
||||
if !OS.has_method("set_window_maximized"):
|
||||
s += " - set_window_maximized()\n"
|
||||
|
||||
if !OS.has_method("is_window_maximized"):
|
||||
s += " - is_window_maximized()\n"
|
||||
|
||||
if s.length() == 0:
|
||||
return true
|
||||
else:
|
||||
$"ImplementationDialog/Text".text += s
|
||||
$ImplementationDialog.show()
|
||||
return false
|
||||
|
||||
|
||||
func _ready():
|
||||
if not check_wm_api():
|
||||
set_physics_process(false)
|
||||
set_process_input(false)
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
mousepos = event.position
|
||||
@@ -147,6 +80,51 @@ func _input(event):
|
||||
_on_Button_MouseModeCaptured_pressed()
|
||||
|
||||
|
||||
func check_wm_api():
|
||||
var s = ""
|
||||
if !OS.has_method("get_screen_count"):
|
||||
s += " - get_screen_count()\n"
|
||||
if !OS.has_method("get_current_screen"):
|
||||
s += " - get_current_screen()\n"
|
||||
if !OS.has_method("set_current_screen"):
|
||||
s += " - set_current_screen()\n"
|
||||
if !OS.has_method("get_screen_position"):
|
||||
s += " - get_screen_position()\n"
|
||||
if !OS.has_method("get_screen_size"):
|
||||
s += " - get_screen_size()\n"
|
||||
if !OS.has_method("get_window_position"):
|
||||
s += " - get_window_position()\n"
|
||||
if !OS.has_method("set_window_position"):
|
||||
s += " - set_window_position()\n"
|
||||
if !OS.has_method("get_window_size"):
|
||||
s += " - get_window_size()\n"
|
||||
if !OS.has_method("set_window_size"):
|
||||
s += " - set_window_size()\n"
|
||||
if !OS.has_method("set_window_fullscreen"):
|
||||
s += " - set_window_fullscreen()\n"
|
||||
if !OS.has_method("is_window_fullscreen"):
|
||||
s += " - is_window_fullscreen()\n"
|
||||
if !OS.has_method("set_window_resizable"):
|
||||
s += " - set_window_resizable()\n"
|
||||
if !OS.has_method("is_window_resizable"):
|
||||
s += " - is_window_resizable()\n"
|
||||
if !OS.has_method("set_window_minimized"):
|
||||
s += " - set_window_minimized()\n"
|
||||
if !OS.has_method("is_window_minimized"):
|
||||
s += " - is_window_minimized()\n"
|
||||
if !OS.has_method("set_window_maximized"):
|
||||
s += " - set_window_maximized()\n"
|
||||
if !OS.has_method("is_window_maximized"):
|
||||
s += " - is_window_maximized()\n"
|
||||
|
||||
if s.length() == 0:
|
||||
return true
|
||||
else:
|
||||
$"ImplementationDialog/Text".text += s
|
||||
$ImplementationDialog.show()
|
||||
return false
|
||||
|
||||
|
||||
func _on_Button_MoveTo_pressed():
|
||||
OS.set_window_position(Vector2(100, 100))
|
||||
|
||||
@@ -200,4 +178,5 @@ func _on_Button_MouseModeHidden_pressed():
|
||||
|
||||
|
||||
func _on_Button_MouseModeCaptured_pressed():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
observer.state = observer.STATE_GRAB
|
||||
|
||||
@@ -1,56 +1,33 @@
|
||||
extends KinematicBody
|
||||
|
||||
# Constants
|
||||
const STATE_MENU = 0
|
||||
const STATE_GRAB = 1
|
||||
|
||||
# Member variables
|
||||
var r_pos = Vector2()
|
||||
var state = STATE_MENU
|
||||
|
||||
onready var camera = $Camera
|
||||
|
||||
func direction(vector):
|
||||
var v = $Camera.get_global_transform().basis * vector
|
||||
v = v.normalized()
|
||||
return v
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
if (state != STATE_GRAB):
|
||||
func _process(delta):
|
||||
if state != STATE_GRAB:
|
||||
return
|
||||
|
||||
if (Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED):
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
var dir = Vector3()
|
||||
if (Input.is_action_pressed("move_forward")):
|
||||
dir += direction(Vector3(0, 0, -1))
|
||||
if (Input.is_action_pressed("move_backwards")):
|
||||
dir += direction(Vector3(0, 0, 1))
|
||||
if (Input.is_action_pressed("move_left")):
|
||||
dir += direction(Vector3(-1, 0, 0))
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
dir += direction(Vector3(1, 0, 0))
|
||||
|
||||
dir = dir.normalized()
|
||||
|
||||
move_and_collide(dir * 10 * delta)
|
||||
var d = delta * 0.1
|
||||
|
||||
# set yaw
|
||||
rotate(Vector3(0, 1, 0), d*r_pos.x)
|
||||
|
||||
# set pitch
|
||||
var pitch = $Camera.get_transform().rotated(Vector3(1, 0, 0), d * r_pos.y)
|
||||
$Camera.set_transform(pitch)
|
||||
|
||||
r_pos = Vector2()
|
||||
|
||||
var x_movement = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
|
||||
var z_movement = Input.get_action_strength("move_backwards") - Input.get_action_strength("move_forward")
|
||||
var dir = direction(Vector3(x_movement, 0, z_movement))
|
||||
transform.origin += dir * 10 * delta
|
||||
|
||||
var d = delta * 0.1 # Scale the input, easiest to do by scaling the delta.
|
||||
rotate(Vector3.UP, d * r_pos.x) # Yaw
|
||||
camera.transform = camera.transform.rotated(Vector3.RIGHT, d * r_pos.y) # Pitch
|
||||
|
||||
r_pos = Vector2.ZERO # We've dealt with all the input, so set it to zero.
|
||||
|
||||
|
||||
func _input(event):
|
||||
if (event is InputEventMouseMotion):
|
||||
r_pos = -event.relative
|
||||
|
||||
|
||||
if (event.is_action("ui_cancel") and event.is_pressed() and !event.is_echo()):
|
||||
if (state == STATE_GRAB):
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
@@ -58,3 +35,8 @@ func _input(event):
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
state = STATE_GRAB
|
||||
|
||||
|
||||
func direction(vector):
|
||||
var v = camera.get_global_transform().basis * vector
|
||||
return v.normalized()
|
||||
|
||||
@@ -16,4 +16,4 @@ near = 0.1
|
||||
far = 1000.0
|
||||
|
||||
[node name="OmniLight" type="OmniLight" parent="."]
|
||||
|
||||
omni_range = 8.0
|
||||
|
||||
@@ -51,20 +51,24 @@ mouse_mode_visible={
|
||||
move_backwards={
|
||||
"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":83,"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":16777234,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_forward={
|
||||
"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":87,"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":16777232,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_left={
|
||||
"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":65,"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":16777231,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_right={
|
||||
"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":68,"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":16777233,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ albedo_color = Color( 0.835294, 0.133333, 0.133333, 1 )
|
||||
material = SubResource( 1 )
|
||||
size = Vector3( 5, 5, 5 )
|
||||
|
||||
[node name="Spatial" type="Spatial"]
|
||||
[node name="WindowManagement" type="Spatial"]
|
||||
|
||||
[node name="Observer" parent="." instance=ExtResource( 1 )]
|
||||
transform = Transform( 0.910685, 0, -0.4131, 0, 1, 0, 0.4131, 0, 0.910685, -4.81287, -0.152566, 9.90641 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||
[node name="TestCube" type="MeshInstance" parent="."]
|
||||
mesh = SubResource( 2 )
|
||||
material/0 = null
|
||||
|
||||
@@ -292,9 +292,9 @@ margin_right = 286.0
|
||||
margin_bottom = -63.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 0
|
||||
text = "F1: activate MOUSE_MODE_VISIBLE
|
||||
F2: activate MOUSE_MODE_HIDDEN
|
||||
F3: activate MOUSE_MODE_CAPTURED"
|
||||
text = "F1: Activate MOUSE_MODE_VISIBLE
|
||||
F2: Activate MOUSE_MODE_HIDDEN
|
||||
F3: Activate MOUSE_MODE_CAPTURED"
|
||||
valign = 2
|
||||
|
||||
[node name="Label_MouseModeCaptured_KeyInfo" type="Label" parent="Control"]
|
||||
@@ -306,9 +306,9 @@ margin_right = 286.0
|
||||
margin_bottom = -11.0
|
||||
size_flags_horizontal = 2
|
||||
size_flags_vertical = 0
|
||||
text = "ESC: deactivate MOUSE_MODE_CAPTURED
|
||||
W, S: move forward, backward
|
||||
A, D: strafe left, right"
|
||||
text = "ESC: Deactivate MOUSE_MODE_CAPTURED
|
||||
W, S: Move forward, backward
|
||||
A, D: Strafe left, right"
|
||||
valign = 2
|
||||
|
||||
[node name="Label_MouseModes" type="Label" parent="Control"]
|
||||
|
||||
Reference in New Issue
Block a user