extends RigidBody const Game = preload("res://scenes/Game.gd") var camrot_h = 0 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 dice_is_moving = false var last_frame_position = Vector3(1.0,1.0,1.0) var mouse_origin = Vector2(0,0) var die_launch_force_magnitude = 0 var die_launch_force_direction = Vector3(0,0,0) var die_launch_force = Vector3(0,0,0) var die_launch_force_multiplier = 0.05 var die_launch_force_magnitude_max = 500 var left_pressed = false var mat var target_bounce = 1 var previous_bounciness = 0 var _game: Game = null enum buff { none, stroke, bounce, phase, ball } # Called when the node enters the scene tree for the first time. func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) $CamRoot/Horizontal/Vertical/Camera.add_exception(self) $CamRoot.set_as_toplevel(true) _game = get_node("/root/Game") mat = get_physics_material_override() previous_bounciness = mat.get_bounce() $PowerUI/PowerBar.hide() $PowerUI/PowerBar.max_value = die_launch_force_magnitude_max func _input(event): if _game.is_post_game(): if event is InputEventMouseButton || event is InputEventKey: _game.next_level() return if event is InputEventKey: if event.scancode == KEY_TAB: if event.is_pressed(): _game.open_scoreboard() else: _game.close_scoreboard() return if event is InputEventMouseButton and dice_is_moving == false: if event.is_pressed() and left_pressed == false: left_pressed = true camrot_v_locked_val = camrot_v #Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) #mouse_origin = event.global_position die_launch_force_magnitude = 0 $PowerUI/PowerBar.show() else: left_pressed = false #die_launch_force_magnitude = -(mouse_origin.y - event.global_position.y) die_launch_force_direction = $CamRoot/Horizontal/Vertical/Camera.get_global_transform().basis die_launch_force_direction = -die_launch_force_direction.z die_launch_force = die_launch_force_direction * clamp(die_launch_force_magnitude, 0, die_launch_force_magnitude_max) * die_launch_force_multiplier self.apply_central_impulse(die_launch_force) $PowerUI/PowerBar.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 if left_pressed: camrot_v = camrot_v_locked_val die_launch_force_magnitude += event.relative.y * sensitivity $PowerUI/PowerBar.value = die_launch_force_magnitude else: camrot_v += -event.relative.y * sensitivity func _physics_process(delta): camrot_v = clamp(camrot_v, cam_v_min, cam_v_max) $CamRoot/Horizontal.rotation_degrees.y = camrot_h $CamRoot/Horizontal/Vertical.rotation_degrees.x = camrot_v $CamRoot.translation.x = translation.x $CamRoot.translation.y = translation.y + 5 $CamRoot.translation.z = translation.z if dice_is_moving == true and angular_velocity.length() < 0.01 and linear_velocity.length() < 0.01: dice_is_moving = false get_buff_from_upwards_side() elif dice_is_moving == false and angular_velocity.length() >= 0.01 and linear_velocity.length() >= 0.01: dice_is_moving = true # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): # pass """ BUFFS """ func get_buff_from_upwards_side(): if $Plus1.get_overlapping_areas().size() > 0 || $Plus2.get_overlapping_areas().size() > 0: return buff.stroke if $Ball1.get_overlapping_areas().size() > 0 || $Ball2.get_overlapping_areas().size() > 0: return buff.ball if $Bounce1.get_overlapping_areas().size() > 0 || $Bounce2.get_overlapping_areas().size() > 0: return buff.bounce if $Phase1.get_overlapping_areas().size() > 0 || $Phase2.get_overlapping_areas().size() > 0: return buff.phase return buff.none func extra_stroke(): _game.revoke_stroke() func bounciness(): mat.set_bounce(target_bounce) func bounciness_revert(): mat.set_bounce(previous_bounciness) func phase(): set_collision_layer_bit(2, false) func phase_revert(): set_collision_layer_bit(2, true) func ball(): $BallShape.show() $BallShape.set_process(true) $BallShape.disabled = false func ball_revert(): $BallShape.hide() $BallShape.set_process(false) $BallShape.disabled = true