sun_pos.gd 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. extends Spatial
  2. const mbtns=3
  3. const mgbtns=5
  4. var iTime=0.0
  5. var ocol=Array()
  6. var ogcol=[Array(),Array(),Array(),Array(),Array()]
  7. var angles=Vector3(-160,-80,-10)
  8. var agngles=[Vector3(-5,-70,-178),Vector3(-160,-80,-10),Vector3(-160,-80,-10),
  9. Vector3(-160,-80,-10),Vector3(-160,-80,-10)]
  10. var switcher=[false,false,false]
  11. var sgwitcher=[[false,false,false],[false,false,false],[false,false,false],[false,false,false],[false,false,false]]
  12. var smooth_vel=0.0
  13. const max_vel=5.0
  14. func _ready():
  15. for a in mbtns:
  16. ocol.append(get_node("b"+str(a)+"/glow").material_override.get("shader_param/colorx"))
  17. if(a!=0):get_node("b"+str(a)+"/glow").material_override.set("shader_param/colorx",Color.darkgray)
  18. for a in mgbtns:
  19. for b in mbtns:
  20. ogcol[a].append(get_node("../p"+str(a+1)+"/p"+str(a+1)+"/portals/a/sun_pos/"+"b"+str(b)+"/glow").material_override.get("shader_param/colorx"))
  21. if(b!=0):get_node("../p"+str(a+1)+"/p"+str(a+1)+"/portals/a/sun_pos/"+"b"+str(b)+"/glow").material_override.set("shader_param/colorx",Color.darkgray)
  22. func smooth_sun(delta):
  23. var c=angles[0]
  24. if(switcher[1]):c=angles[1]
  25. if(switcher[2]):c=angles[2]
  26. var cg=get_node("../DirectionalLight").rotation_degrees.x
  27. var val=lerp(cg,c,delta/7.5)
  28. get_node("../DirectionalLight").rotation_degrees.x=val
  29. var da=get_node("../DirectionalLight").rotation
  30. da = -Vector3(sin(da.z),-(sin(da.x) * cos(da.z)), cos(da.x) * cos(da.y))
  31. get_node("../main_player/Camera/sphere").material_override.set("shader_param/dir_angle",da)
  32. func smooth_g_sun(delta):
  33. for a in mgbtns:
  34. var c=agngles[a][0]
  35. if(sgwitcher[a][1]):c=agngles[a][1]
  36. if(sgwitcher[a][2]):c=agngles[a][2]
  37. var cg=get_node("../p"+str(a+1)+"/p"+str(a+1)+"/"+"DirectionalLight").rotation_degrees.x
  38. var val=lerp(cg,c,delta/7.5)
  39. get_node("../p"+str(a+1)+"/p"+str(a+1)+"/"+"DirectionalLight").rotation_degrees.x=val
  40. var da=get_node("../p"+str(a+1)+"/p"+str(a+1)+"/"+"DirectionalLight").rotation
  41. var oda=da
  42. da = -Vector3(sin(da.z),-(sin(da.x) * cos(da.z)), cos(da.x) * cos(da.y))
  43. get_node("../p"+str(a+1)+"/p"+str(a+1)+"/"+"Camera/sphere").material_override.set("shader_param/angle",oda)
  44. get_node("../p"+str(a+1)+"/p"+str(a+1)+"/"+"Camera/sphere").material_override.set("shader_param/dir_angle",da)
  45. get_node("../p"+str(a+1)+"/p"+str(a+1)+"/"+"Camera/sphere").material_override.set("shader_param/iTime",iTime)
  46. func _process(delta):
  47. smooth_sun(delta)
  48. smooth_g_sun(delta)
  49. iTime+=delta
  50. func _on_Area_btn_body_entered(body, idx, px):
  51. if(!body.is_in_group("player")):
  52. return
  53. if(px==0):
  54. get_node("b"+str(idx)+"/button").translation.y=-0.15
  55. get_node("b"+str(idx)+"/glow").material_override.set("shader_param/colorx",ocol[idx])
  56. switcher[idx]=true
  57. idx+=1
  58. for a in mbtns-1:
  59. if(idx>=mbtns):
  60. idx=0
  61. get_node("b"+str(idx)+"/button").translation.y=0
  62. get_node("b"+str(idx)+"/glow").material_override.set("shader_param/colorx",Color.darkgray)
  63. switcher[idx]=false
  64. idx+=1
  65. return
  66. #else
  67. get_node("../p"+str(px)+"/p"+str(px)+"/portals/a/sun_pos/"+"b"+str(idx)+"/button").translation.y=-0.15
  68. get_node("../p"+str(px)+"/p"+str(px)+"/portals/a/sun_pos/"+"b"+str(idx)+"/glow").material_override.set("shader_param/colorx",ogcol[px-1][idx])
  69. sgwitcher[px-1][idx]=true
  70. idx+=1
  71. for a in mbtns-1:
  72. if(idx>=mbtns):
  73. idx=0
  74. get_node("../p"+str(px)+"/p"+str(px)+"/portals/a/sun_pos/"+"b"+str(idx)+"/button").translation.y=0
  75. get_node("../p"+str(px)+"/p"+str(px)+"/portals/a/sun_pos/"+"b"+str(idx)+"/glow").material_override.set("shader_param/colorx",Color.darkgray)
  76. sgwitcher[px-1][idx]=false
  77. idx+=1
  78. return