player.gd 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. extends "res://scripts/ship_base.gd"
  2. var weapon_group_selected = 0
  3. var shake = 0.0
  4. var shake_disable = 0.0
  5. var nav_point = load("res://scenes/hud/nav.tscn")
  6. func destroyed():
  7. set_process_input(false)
  8. func damaged(pos,type,dmg,disable,heat):
  9. shake += 100.0*dmg/hp_max
  10. shake_disable += 0.1*min(disable,sp_max/10.0)/max(sp,sp_max/4.0)
  11. func select_missile(m):
  12. if (missile_selected==m):
  13. return
  14. HUD.get_node("Target").hide()
  15. if (num_missiles<=m):
  16. missile_selected = -1
  17. missile_locked = false
  18. missile_lock = 0.0
  19. missile_target = null
  20. return
  21. missile_selected = m
  22. missile_locked = false
  23. missile_lock = missile_tt[missile_selected]
  24. missile_cd = missile_st[missile_selected]
  25. for i in range(missile_selected)+range(missile_selected+1,num_missiles):
  26. HUD.get_node("Weapons/VBoxContainer/Missile"+str(i+1)+"/Selected").hide()
  27. HUD.get_node("Weapons/VBoxContainer/Missile"+str(i+1)+"/Targetting").set_value(0.0)
  28. HUD.get_node("Weapons/VBoxContainer/Missile"+str(i+1)+"/Time").set_value(0.0)
  29. HUD.get_node("Weapons/VBoxContainer/Missile"+str(missile_selected+1)+"/Selected").show()
  30. func change_weapon_group():
  31. for i in range(num_weapons):
  32. if (Player.weapon_group[weapon_group_selected][i]):
  33. HUD.get_node("Weapons/VBoxContainer/Weapon"+str(i+1)+"/Selected").show()
  34. else:
  35. HUD.get_node("Weapons/VBoxContainer/Weapon"+str(i+1)+"/Selected").hide()
  36. for i in range(num_turrets):
  37. var active = Player.weapon_group[weapon_group_selected][num_weapons+i]
  38. get_node("Turret"+str(i+1)+"/Turret").active = active
  39. if (active):
  40. HUD.get_node("Weapons/VBoxContainer/Turret"+str(i+1)+"/Selected").show()
  41. else:
  42. HUD.get_node("Weapons/VBoxContainer/Turret"+str(i+1)+"/Selected").hide()
  43. func start_boarding():
  44. if (boarding):
  45. return
  46. HUD.get_node("Boarding").enemy = board_target
  47. HUD.get_node("Boarding")._start(true)
  48. boarding = true
  49. func enable_autopilot():
  50. if (nav.size()<1):
  51. return
  52. ap = true
  53. last_collider = null
  54. evading = false
  55. Player.time_speedup = true
  56. func disable_autopilot():
  57. ap = false
  58. for n in nav:
  59. n.queue_free()
  60. nav.clear()
  61. last_collider = null
  62. evading = false
  63. Player.time_speedup = false
  64. func autopilot(delta):
  65. # auto pilot
  66. if (ap):
  67. var tpos = nav[0].global_position
  68. var tlv = nav[0].get_lv()
  69. get_node("/root/Main/Pos").position = tpos
  70. var pos = global_position
  71. var lv = get_linear_velocity()-tlv
  72. var d = (tpos-pos).length()
  73. var v = lv.dot((tpos-pos)/d)
  74. var t = d/max(v,d/10.0)
  75. if (v<0):
  76. t += abs(v)/la
  77. var damp = max(1-damping*t,0)
  78. var s = (t-damp*abs(v)/la-PI/ts)
  79. var target_lv = s*(tpos-pos)/t-t*(lv-abs(v)*(tpos-pos)/d)
  80. var ang = Vector2(0,-1).rotated(rotation).angle_to(target_lv)
  81. if (abs(ang)<0.01):
  82. thrust = true
  83. else:
  84. thrust = false
  85. rotate = -min(abs(ang)/(ts*delta),1)*sign(ang)
  86. if (s<0):
  87. Player.time_speedup = false
  88. if (dock>=0):
  89. if (d<50 && abs(v)<20 && nav.size()<2):
  90. disable_autopilot()
  91. Stations.player_land(station,dock)
  92. thrust = false
  93. rotate = 0
  94. return
  95. elif (d<125 && abs(v)<30):
  96. nav[0].queue_free()
  97. nav.remove(0)
  98. if (nav.size()<1):
  99. disable_autopilot()
  100. else:
  101. if (!HUD.map && !disabled):
  102. var ang = get_local_mouse_position().angle()
  103. rotate = 1.0*sign(ang)
  104. ang = PI-ang
  105. rotate *= min(min(abs(ang),abs(abs(ang)-2*PI)),1)
  106. else:
  107. rotate = 0
  108. func hud(delta):
  109. var zoom = (Input.is_action_pressed("zoom_out") or Input.is_action_pressed("zoom_in")) and not (Input.is_action_pressed("zoom_out") and Input.is_action_pressed("zoom_in"))
  110. var shake_pos = shake*sin(100.0*time)*Vector2(1,0).rotated(rotation)
  111. var shake_width = shake_disable*cos(45.7*time)*Vector2(0,1).rotated(rotation)
  112. var noise_alpha = 0.75*max(0.75-hp/hp_max,0.0)
  113. var bw_alpha = 2.0*max(0.5-hp/hp_max,0.0)
  114. noise_alpha *= noise_alpha
  115. shake -= 100.0*delta
  116. if (shake<0.0):
  117. shake = 0.0
  118. shake_disable -= 0.1*delta
  119. if (shake_disable<0.005*(1.0-sp/sp_max)+0.001*(1.0-hp/hp_max)):
  120. shake_disable = 0.005*(1.0-sp/sp_max)+0.001*(1.0-hp/hp_max)
  121. get_node("/root/Main/Camera").position = global_position+shake_pos
  122. get_node("/root/Main/Camera").set_zoom(clamp(get_node("/root/Main/Camera").get_zoom().x*(1.0+delta*zoom),1.0,10.0)*Vector2(1.0,1.0))
  123. get_node("/root/Main/Camera/BackBufferCopy").set_rect(Rect2(-OS.get_video_mode_size()/2.0*get_node("/root/Main/Camera").get_zoom(),OS.get_video_mode_size()/2.0*get_node("/root/Main/Camera").get_zoom()))
  124. get_node("/root/Main/Camera/BackBufferCopy/Sprite").get_material().set_shader_param("offset_r", shake_width)
  125. get_node("/root/Main/Camera/BackBufferCopy/Sprite").get_material().set_shader_param("offset_b",-shake_width)
  126. get_node("/root/Main/Camera/BackBufferCopy/Sprite").get_material().set_shader_param("noise_alpha",noise_alpha)
  127. get_node("/root/Main/Camera/BackBufferCopy/Sprite").position = -OS.get_video_mode_size()/2.0*get_node("/root/Main/Camera").get_zoom()
  128. get_node("/root/Main/Camera/BackBufferCopy/Sprite").set_size(OS.get_video_mode_size()*get_node("/root/Main/Camera").get_zoom())
  129. get_node("/root/Main/Camera/BackBufferCopy/Sprite").get_material().set_shader_param("bw_alpha",bw_alpha)
  130. for i in range(num_weapons):
  131. HUD.get_node("Weapons/VBoxContainer/Weapon"+str(i+1)+"/SP").set_value(weapon_sp[i])
  132. HUD.get_node("Weapons/VBoxContainer/Weapon"+str(i+1)+"/Time").set_value(weapon_st[i]-weapon_cd[i])
  133. HUD.get_node("Weapons/VBoxContainer/Weapon"+str(i+1)+"/Temp").set_value(weapon_temp[i])
  134. for i in range(num_turrets):
  135. var turret = get_node("Turret"+str(i+1)+"/Turret")
  136. HUD.get_node("Weapons/VBoxContainer/Turret"+str(i+1)+"/SP").set_value(turret.sp)
  137. HUD.get_node("Weapons/VBoxContainer/Turret"+str(i+1)+"/Time").set_value(turret.st-turret.cd)
  138. HUD.get_node("Weapons/VBoxContainer/Turret"+str(i+1)+"/Temp").set_value(turret.temp)
  139. for i in range(num_missiles):
  140. if (missile_selected==i):
  141. HUD.get_node("Weapons/VBoxContainer/Missile"+str(i+1)+"/Targetting").set_value(missile_tt[i]-missile_lock)
  142. HUD.get_node("Weapons/VBoxContainer/Missile"+str(i+1)+"/Time").set_value(missile_st[i]-missile_cd)
  143. HUD.get_node("Weapons/VBoxContainer/Missile"+str(i+1)+"/Ammo").set_value(missile_ammo[i])
  144. HUD.get_node("Status/Outlines/Base").set_modulate(Color(disabled,1-disabled,0.0))
  145. if (ep+steering_power<0.0):
  146. HUD.get_node("Status/Outlines/Base/Energy").show()
  147. else:
  148. HUD.get_node("Status/Outlines/Base/Energy").hide()
  149. for i in range(num_reactors):
  150. if (!reactor_disabled[i]):
  151. HUD.get_node("Status/Outlines/Reactor"+str(i+1)+"/Disabled").hide()
  152. if (reactor_overheating[i]):
  153. HUD.get_node("Status/Outlines/Reactor"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  154. HUD.get_node("Status/Outlines/Reactor"+str(i+1)+"/Temp").show()
  155. else:
  156. HUD.get_node("Status/Outlines/Reactor"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  157. HUD.get_node("Status/Outlines/Reactor"+str(i+1)+"/Temp").hide()
  158. else:
  159. HUD.get_node("Status/Outlines/Reactor"+str(i+1)).set_modulate(Color(1.0,0.0,0.0))
  160. HUD.get_node("Status/Outlines/Reactor"+str(i+1)+"/Disabled").show()
  161. HUD.get_node("Status/Outlines/Reactor"+str(i+1)+"/Temp").hide()
  162. for i in range(num_internal):
  163. if (!internal_disabled[i]):
  164. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Disabled").hide()
  165. if (internal_overheating[i]):
  166. HUD.get_node("Status/Outlines/Internal"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  167. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Temp").show()
  168. else:
  169. HUD.get_node("Status/Outlines/Internal"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  170. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Temp").hide()
  171. if (internal_no_power[i]):
  172. HUD.get_node("Status/Outlines/Internal"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  173. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Energy").show()
  174. else:
  175. if (!internal_overheating[i]):
  176. HUD.get_node("Status/Outlines/Internal"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  177. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Energy").hide()
  178. else:
  179. HUD.get_node("Status/Outlines/Internal"+str(i+1)).set_modulate(Color(1.0,0.0,0.0))
  180. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Disabled").show()
  181. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Energy").hide()
  182. HUD.get_node("Status/Outlines/Internal"+str(i+1)+"/Temp").hide()
  183. for i in range(num_external):
  184. if (!external_disabled[i]):
  185. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Disabled").hide()
  186. if (external_overheating[i]):
  187. HUD.get_node("Status/Outlines/External"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  188. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Temp").show()
  189. else:
  190. HUD.get_node("Status/Outlines/External"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  191. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Temp").hide()
  192. if (external_no_power[i]):
  193. HUD.get_node("Status/Outlines/External"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  194. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Energy").show()
  195. else:
  196. if (!external_overheating[i]):
  197. HUD.get_node("Status/Outlines/External"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  198. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Energy").hide()
  199. else:
  200. HUD.get_node("Status/Outlines/External"+str(i+1)).set_modulate(Color(1.0,0.0,0.0))
  201. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Disabled").show()
  202. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Energy").hide()
  203. HUD.get_node("Status/Outlines/External"+str(i+1)+"/Temp").hide()
  204. for i in range(num_engines):
  205. if (!engine_disabled[i]):
  206. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Disabled").hide()
  207. if (temp+delta*thrust_heat>temp_max):
  208. HUD.get_node("Status/Outlines/Engine"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  209. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Temp").show()
  210. else:
  211. HUD.get_node("Status/Outlines/Engine"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  212. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Temp").hide()
  213. if (ep+delta*thrust_power<0.0):
  214. HUD.get_node("Status/Outlines/Engine"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  215. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Energy").show()
  216. else:
  217. if (temp+delta*thrust_heat<temp_max):
  218. HUD.get_node("Status/Outlines/Engine"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  219. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Energy").hide()
  220. else:
  221. HUD.get_node("Status/Outlines/Engine"+str(i+1)).set_modulate(Color(1.0,0.0,0.0))
  222. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Disabled").show()
  223. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Energy").hide()
  224. HUD.get_node("Status/Outlines/Engine"+str(i+1)+"/Temp").hide()
  225. for i in range(num_weapons):
  226. if (!weapon_disabled[i]):
  227. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Disabled").hide()
  228. if (ep+weapon_ep[i]<0.0):
  229. HUD.get_node("Status/Outlines/Weapon"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  230. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Energy").show()
  231. else:
  232. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Energy").hide()
  233. HUD.get_node("Status/Outlines/Weapon"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  234. if (weapon_temp[i]+weapon_heat[i]>weapon_max_temp[i] || temp+weapon_heat[i]>temp_max):
  235. HUD.get_node("Status/Outlines/Weapon"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  236. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Temp").show()
  237. else:
  238. if (ep+weapon_ep[i]>0.0):
  239. HUD.get_node("Status/Outlines/Weapon"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  240. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Temp").hide()
  241. else:
  242. HUD.get_node("Status/Outlines/Weapon"+str(i+1)).set_modulate(Color(1.0,0.0,0.0))
  243. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Disabled").show()
  244. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Energy").hide()
  245. HUD.get_node("Status/Outlines/Weapon"+str(i+1)+"/Temp").hide()
  246. for i in range(num_turrets):
  247. var turret = get_node("Turret"+str(i+1)+"/Turret")
  248. if (!turret.disabled):
  249. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Disabled").hide()
  250. if (ep+turret.ep<0.0):
  251. HUD.get_node("Status/Outlines/Turret"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  252. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Energy").show()
  253. else:
  254. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Energy").hide()
  255. HUD.get_node("Status/Outlines/Turret"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  256. if (turret.temp+turret.heat>turret.max_temp || temp>temp_max):
  257. HUD.get_node("Status/Outlines/Turret"+str(i+1)).set_modulate(Color(1.0,1.0,0.0))
  258. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Temp").show()
  259. else:
  260. if (ep+turret.ep>0.0):
  261. HUD.get_node("Status/Outlines/Turret"+str(i+1)).set_modulate(Color(0.0,1.0,0.0))
  262. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Temp").hide()
  263. else:
  264. HUD.get_node("Status/Outlines/Turret"+str(i+1)).set_modulate(Color(1.0,0.0,0.0))
  265. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Disabled").show()
  266. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Energy").hide()
  267. HUD.get_node("Status/Outlines/Turret"+str(i+1)+"/Temp").hide()
  268. HUD.get_node("Status/VBoxContainer/HP/HP").set_value(hp)
  269. HUD.get_node("Status/VBoxContainer/HP/HP").set_max(hp_max)
  270. HUD.get_node("Status/VBoxContainer/HP/Text").set_text(str(round(hp))+Equipment.units["armor"]+" / "+str(round(hp_max))+Equipment.units["armor"])
  271. HUD.get_node("Status/VBoxContainer/EP/EP").set_value(ep)
  272. HUD.get_node("Status/VBoxContainer/EP/EP").set_max(ep_max)
  273. HUD.get_node("Status/VBoxContainer/EP/Text").set_text(str(round(ep))+Equipment.units["energy"]+" / "+str(round(ep_max))+Equipment.units["energy"])
  274. HUD.get_node("Status/VBoxContainer/Temp/Temp").set_value(temp)
  275. HUD.get_node("Status/VBoxContainer/Temp/Temp").set_max(temp_max)
  276. HUD.get_node("Status/VBoxContainer/Temp/Text").set_text(str(round(temp))+Equipment.units["max_temperature"]+" / "+str(round(temp_max))+Equipment.units["max_temperature"])
  277. HUD.get_node("Status/VBoxContainer/Disable/Disable").set_value(sp)
  278. HUD.get_node("Status/VBoxContainer/Disable/Disable").set_max(sp_max)
  279. HUD.get_node("Status/VBoxContainer/Disable/Text").set_text(str(round(sp))+Equipment.units["sp"]+" / "+str(round(sp_max))+Equipment.units["sp"])
  280. func _input(event):
  281. var s = (Input.is_action_pressed("shoot") || (Input.is_action_pressed("LMB") && !HUD.map))
  282. for i in range(num_weapons):
  283. shoot[i] = s && Player.weapon_group[weapon_group_selected][i]
  284. launch_missile = (Input.is_action_pressed("RMB") && !HUD.map || Input.is_action_pressed("launch_missile"))
  285. if (s || launch_missile):
  286. disable_autopilot()
  287. if (Input.is_action_pressed("thrust") || Input.is_action_pressed("reverse_thrust")):
  288. disable_autopilot()
  289. if (!ap):
  290. thrust = Input.is_action_pressed("thrust")*(1-disabled)
  291. reverse_thrust = Input.is_action_pressed("reverse_thrust")*(1-disabled)
  292. if (Input.is_action_pressed("shoot_at_me")):
  293. var ang = 2*PI*randf()
  294. var dir = Vector2(0,-1).rotated(ang)
  295. var pos = global_position-dir*rand_range(400,1000)
  296. var node = Position2D.new()
  297. node.position = pos
  298. node.set_rotation(ang)
  299. get_node("/root/Main").add_child(node)
  300. Weapons.shoot("paa",node,1.0,dir,ang,get_lv(),Factions.ENEMY)
  301. if (event.is_pressed()):
  302. if(event.is_action_pressed("RMB") && HUD.map):
  303. var pos = (get_global_mouse_position()-global_position)/get_node("/root/Main/Camera").get_zoom()/(HUD.map_scale*HUD.map_zoom)-HUD.map_center/(HUD.map_zoom*HUD.map_scale)
  304. var ni = nav_point.instance()
  305. target = null
  306. ni.position = pos
  307. get_node("/root/Main").add_child(ni)
  308. if (!Input.is_action_pressed("shift")):
  309. for n in nav:
  310. n.queue_free()
  311. nav.clear()
  312. nav.push_back(ni)
  313. if (dock>=0):
  314. get_node("/root/Main/"+station).docked[dock] = false
  315. dock = -1
  316. station = null
  317. enable_autopilot()
  318. elif (event.is_action_pressed("land")):
  319. var pos = get_global_mouse_position()
  320. var dist = 1000000000
  321. if (dock>=0):
  322. get_node("/root/Main/"+station).docked[dock] = false
  323. station = null
  324. for st in Stations.stations:
  325. var dist2 = pos.distance_squared_to(get_node("/root/Main/"+s).global_position)
  326. if (dist2<dist):
  327. dist = dist2
  328. station = st
  329. if (station!=null):
  330. disable_autopilot()
  331. var ni = nav_point.instance()
  332. dock = get_node("/root/Main/"+station).request_landing_position() # reserve docking slot
  333. if (dock<0):
  334. return
  335. target = null
  336. get_node("/root/Main/"+station).add_child(ni)
  337. ni.global_position = get_node("/root/Main/"+station+"/Position"+str(dock)).global_position
  338. nav.resize(1)
  339. nav[0] = ni
  340. docking = false
  341. enable_autopilot()
  342. elif (event.is_action_pressed("board")):
  343. disable_autopilot()
  344. if (boarding):
  345. HUD.get_node("Boarding")._player_undock()
  346. else:
  347. disable_grappling_hook()
  348. var pos = get_global_mouse_position()
  349. var dist = 100000
  350. board_target = null
  351. for sh in get_node("/root/Main").ships:
  352. if (sh.disabled):
  353. var dist2 = pos.distance_squared_to(sh.global_position)
  354. if (dist2<dist):
  355. dist = dist2
  356. board_target = sh
  357. if (board_target!=null):
  358. board = true
  359. elif (event.is_action_pressed("missile_cycle_up")):
  360. select_next_missile()
  361. elif (event.is_action_pressed("missile_cycle_dn")):
  362. select_prev_missile()
  363. elif (event.is_action_pressed("zoom_in")):
  364. get_node("/root/Main/Camera").set_zoom(clamp(get_node("/root/Main/Camera").get_zoom().x*0.9,1.0,10.0)*Vector2(1.0,1.0))
  365. elif (event.is_action_pressed("zoom_out")):
  366. get_node("/root/Main/Camera").set_zoom(clamp(get_node("/root/Main/Camera").get_zoom().x*1.1,1.0,10.0)*Vector2(1.0,1.0))
  367. elif (event.is_action_pressed("weapon_group_1")):
  368. weapon_group_selected = 0
  369. change_weapon_group()
  370. elif (event.is_action_pressed("weapon_group_2")):
  371. weapon_group_selected = 1
  372. change_weapon_group()
  373. elif (event.is_action_pressed("weapon_group_3")):
  374. weapon_group_selected = 2
  375. change_weapon_group()
  376. elif (event.is_action_pressed("weapon_group_4")):
  377. weapon_group_selected = 3
  378. change_weapon_group()
  379. elif (event.type==InputEvent.MOUSE_MOTION && missile_selected>=0 && missile_tt[missile_selected]>0.0 && missile_ammo[missile_selected]>0):
  380. var dist = 50000
  381. missile_target = null
  382. for t in get_node("/root/Main").ships:
  383. if (Factions.is_enemy(faction,t.faction) && t.faction!=Factions.NEUTRAL):
  384. var dist2 = get_global_mouse_position().distance_squared_to(t.global_position)/(get_node("/root/Main/Camera").get_zoom().x*get_node("/root/Main/Camera").get_zoom().x)
  385. if (dist2<dist):
  386. dist = dist2
  387. missile_target = t
  388. if (missile_target!=missile_target_old && missile_type.size()>0):
  389. missile_lock = missile_tt[missile_selected]
  390. missile_locked = false
  391. if (missile_target!=null):
  392. var size = missile_target.get_node("Sprite").get_texture().get_size()/get_node("/root/Main/Camera").get_zoom()/2.0
  393. size = max(max(size.x,size.y),80.0)
  394. HUD.get_node("Target/Up").position = Vector2(0,-size)
  395. HUD.get_node("Target/Down").position = Vector2(0,size)
  396. HUD.get_node("Target/Right").position = Vector2(size,0)
  397. HUD.get_node("Target/Left").position = Vector2(-size,0)
  398. HUD.get_node("Target").show()
  399. else:
  400. HUD.get_node("Target").hide()
  401. func targeting():
  402. HUD.get_node("Target").position = (missile_target.global_position-get_node("/root/Main/Camera").get_camera_pos())/get_node("/root/Main/Camera").get_zoom()+OS.get_video_mode_size()/2.0
  403. for s in ["Up","Right","Down","Left"]:
  404. HUD.get_node("Target/"+s).set_offset(Vector2(0,16.0-64.0*missile_lock/missile_tt[missile_selected]))
  405. func target_locked():
  406. HUD.get_node("Target/Anim").play("missile_lock")
  407. func target_lost():
  408. HUD.get_node("Target").hide()
  409. func init():
  410. connect("targeting",self,"targeting")
  411. connect("target_locked",self,"target_locked")
  412. connect("target_lost",self,"target_lost")
  413. icon = HUD.get_node("Map/Map/Player")