sevivon-prototype

[RADIOACTIVE] a concept version of sevivon
git clone git://git.figbert.com/sevivon-prototype.git
Log | Files | Refs | README | LICENSE

sevivon.gd (1355B)


      1 extends RigidBody
      2 
      3 const ACCEL_THRESHOLD := 3
      4 const MIN_ANGLE := 0.0
      5 const MAX_ANGLE := 0.1
      6 const MIN_FORCE := 5
      7 const MAX_FORCE := 12
      8 var has_spun := false
      9 var displayed_results := false
     10 
     11 func _physics_process(_delta):
     12 	var accel := Input.get_accelerometer()
     13 	if accel.length() > ACCEL_THRESHOLD:
     14 		spin(accel)
     15 	elif has_spun && !displayed_results && is_zero_approx(angular_velocity.length()):
     16 		print(spin_result())
     17 		displayed_results = true
     18 	elif displayed_results:
     19 		get_tree().reload_current_scene()
     20 
     21 func spin(accel: Vector3):
     22 	randomize()
     23 	angular_velocity = Vector3(rand_range(MIN_ANGLE, MAX_ANGLE), 0, rand_range(MIN_ANGLE, MAX_ANGLE))
     24 	apply_torque_impulse(Vector3.UP * accel.length() * rand_range(MIN_FORCE, MAX_FORCE))
     25 	has_spun = true
     26 
     27 func spin_result() -> String:
     28 	var nun_pos: float = $Body/Nun.global_transform.origin.y
     29 	var gimel_pos: float = $Body/Gimel.global_transform.origin.y
     30 	var hey_pos: float = $Body/Hey.global_transform.origin.y
     31 	var pey_shin_pos: float
     32 	if $Body/Pey.visible:
     33 		pey_shin_pos = $Body/Pey.global_transform.origin.y
     34 	else:
     35 		pey_shin_pos = $Body/Shin.global_transform.origin.y
     36 	var biggest = max(nun_pos, max(gimel_pos, (max(hey_pos, pey_shin_pos))))
     37 	match biggest:
     38 		nun_pos:
     39 			return "NUN"
     40 		gimel_pos:
     41 			return "GIMEL"
     42 		hey_pos:
     43 			return "HEY"
     44 		pey_shin_pos:
     45 			return "PEY_SHIN"
     46 		_:
     47 			return "ERROR"