diff options
author | David <david003@gmx.net> | 2022-07-17 14:15:28 +0200 |
---|---|---|
committer | David <david003@gmx.net> | 2022-07-17 14:15:28 +0200 |
commit | 78db85704fc13f3bde69fdad196f6701a4d5e7c9 (patch) | |
tree | 61ec986bbac133bfa4f05303d457a4782fecd1b3 /godot/scenes/Die.gd | |
parent | 9cb0b053b337742aae96517a8c5c4700698faa03 (diff) | |
download | 2022-78db85704fc13f3bde69fdad196f6701a4d5e7c9.tar.gz 2022-78db85704fc13f3bde69fdad196f6701a4d5e7c9.tar.bz2 2022-78db85704fc13f3bde69fdad196f6701a4d5e7c9.zip |
add arrow for charging shot
Diffstat (limited to '')
-rw-r--r-- | godot/scenes/Die.gd | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/godot/scenes/Die.gd b/godot/scenes/Die.gd index 0d11d73..0cee70a 100644 --- a/godot/scenes/Die.gd +++ b/godot/scenes/Die.gd @@ -7,7 +7,8 @@ var camrot_v = 0 var camrot_v_locked_val = 0 var cam_v_min = -90 var cam_v_max = 90 -var sensitivity = 0.5 +var sensitivity_cam = 0.5 +var sensitivity_charge = 2 var dice_is_moving = false var last_frame_position = Vector3(1.0,1.0,1.0) var mouse_origin = Vector2(0,0) @@ -18,7 +19,7 @@ var die_launch_force_multiplier = 0.05 var die_launch_force_magnitude_max = 1000 var left_pressed = false var mat -var target_bounce = 10 +var target_bounce = 1 var default_gravity = 2 var default_bounciness = 0 @@ -40,10 +41,12 @@ func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) $CamRoot/Horizontal/Vertical/Camera.add_exception(self) $CamRoot.set_as_toplevel(true) + $PowerUI3D.set_as_toplevel(true) _game = get_node("/root/Game") mat = get_physics_material_override() mat.friction = 1 gravity_scale = default_gravity + $PowerUI3D/Arrow.hide() $PowerUI/PowerBar.hide() $PowerUI/PowerBar.max_value = die_launch_force_magnitude_max @@ -71,6 +74,8 @@ func _input(event): #mouse_origin = event.global_position die_launch_force_magnitude = 0 $PowerUI/PowerBar.show() + draw_arrow() + $PowerUI3D/Arrow.show() else: left_pressed = false @@ -82,18 +87,20 @@ func _input(event): if curr_buff != buff.ball: self.apply_torque_impulse(die_launch_force) $PowerUI/PowerBar.hide() + $PowerUI3D/Arrow.hide() _game.add_stroke() #Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) # add one to counter if event is InputEventMouseMotion: - camrot_h += -event.relative.x * sensitivity + camrot_h += -event.relative.x * sensitivity_cam if left_pressed: camrot_v = camrot_v_locked_val - die_launch_force_magnitude += event.relative.y * sensitivity + die_launch_force_magnitude += event.relative.y * sensitivity_charge $PowerUI/PowerBar.value = die_launch_force_magnitude + draw_arrow() else: - camrot_v += -event.relative.y * sensitivity + camrot_v += -event.relative.y * sensitivity_cam func _physics_process(delta): @@ -104,6 +111,9 @@ func _physics_process(delta): $CamRoot.translation.x = translation.x $CamRoot.translation.y = translation.y + 5 $CamRoot.translation.z = translation.z + $PowerUI3D.translation.x = translation.x + $PowerUI3D.translation.y = translation.y + $PowerUI3D.translation.z = translation.z if dice_is_moving == true and angular_velocity.length() < 0.1 and linear_velocity.length() < 0.1: if curr_buff != buff.ball: @@ -120,9 +130,40 @@ func _physics_process(delta): # Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass - +func _process(delta): + var rot = $CamRoot/Horizontal/Vertical/Camera.get_global_transform().basis.get_euler() + $PowerUI3D.rotation_degrees.y = rad2deg(rot.y) + 180 + print(rot.y) + +func draw_arrow(): + var l = 1 + 5 * clamp(die_launch_force_magnitude, 0, die_launch_force_magnitude_max) / die_launch_force_magnitude_max + var vertices = PoolVector3Array([ + # base left + Vector3( 0.2, 0, 0), + Vector3( 0.2, 0, l), + Vector3(-0.2, 0, l), + # base right + Vector3( 0.2, 0, 0), + Vector3(-0.2, 0, l), + Vector3(-0.2, 0, 0), + # tip + Vector3( 0.4, 0, l), + Vector3(-0.0, 0, l + 0.4), + Vector3(-0.4, 0, l), + ]) + var st = SurfaceTool.new() + var m = SpatialMaterial.new() + var color = Color(0.9, 0.1, 0.1) + m.albedo_color = color + st.begin(Mesh.PRIMITIVE_TRIANGLES) + st.set_material(m) + for v in vertices.size(): + st.add_color(color) + st.add_uv(Vector2(0,0)) + st.add_vertex(vertices[v]) + var tmpMesh = Mesh.new() + st.commit(tmpMesh) + $PowerUI3D/Arrow.mesh = tmpMesh """ BUFFS |