PageRenderTime 77ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/old/PlaceTowers.hx

http://spacecreeps.googlecode.com/
Haxe | 760 lines | 487 code | 124 blank | 149 comment | 74 complexity | 84aef35e6003dbd6481314b46a54cfa8 MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-3.0
  1. /*
  2. * PlaceTowers - tower placement phase of play
  3. *
  4. * Copyright 2007 James W. Hofmann
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #if flash9
  22. import flash.events.TimerEvent;
  23. import flash.Lib;
  24. import flash.display.Sprite;
  25. import flash.display.Bitmap;
  26. import flash.display.Graphics;
  27. import flash.display.Shape;
  28. import flash.display.BitmapData;
  29. import flash3f.InputHandler;
  30. import flash3f.Images;
  31. import flash.geom.Point;
  32. #else neko
  33. import neko3f.InputHandler;
  34. import lib3f.Point;
  35. #end
  36. import lib3f.IntPoint;
  37. import lib3f.Dist;
  38. //// base rules for tower placement
  39. // 1. Distance/adjacency - 2 units of Manhattan distance
  40. // 2. Space is free; or space has non-upgraded tower, to upgrade
  41. // 3. Tower must be provided with a target inside the map area
  42. //// things the interface should do
  43. // 1. Tower/Wall modes
  44. // 2. Place tower with mouse, then select target
  45. // 3. Undo
  46. // 4. Drag-place walls
  47. class PlaceTowers
  48. {
  49. static public var checkforspace : Bool;
  50. static public var towerstoplace : Int;
  51. static public var mode : String;
  52. static public var lastx : Int;
  53. static public var lasty : Int;
  54. static public var lastshooter : Shooter;
  55. static public var targetstart : Point;
  56. static public var upgradetarget : GameTile;
  57. static public var finished : Bool;
  58. #if flash9
  59. static public var mypop : PopTart;
  60. static public var okareaarray : Array<IsoBitmap>;
  61. //static public var targetsprite : Sprite = new Sprite();
  62. //static public var targetcache : Array<Array<Int>>;
  63. //static public var targetbg : Bitmap;
  64. static public var tutorialtickerplace : Int;
  65. static public var tutorialtickertarget : Int;
  66. static public var targetline : Shape; // line from tower to target
  67. static public var targetbox : Shape; // target area shape
  68. static public var targetcache : Bitmap;
  69. static public var showcache : Shiner;
  70. #end
  71. static public function reportnumtowers() : Int
  72. {
  73. return Std.int(FortressManager.calcterritory()/20)+1;
  74. }
  75. static public function reportnumwalls() : Int
  76. {
  77. return 8;
  78. }
  79. static public function start()
  80. {
  81. }
  82. /*static public function start()
  83. {
  84. finished = false;
  85. Gameplay.screenPlacement();
  86. InputHandler.clear();
  87. towerstoplace = Std.int(FortressManager.calcterritory()/20)+1;
  88. if (FortressManager.nospaceleft() && FortressManager.towerscantbeupgraded())
  89. towerstoplace = 0;
  90. #if flash9
  91. okareaarray = new Array();
  92. tutorialtickerplace = 1;
  93. tutorialtickertarget = 1;
  94. if (towerstoplace>0)
  95. {
  96. if (towerstoplace>1)
  97. mypop = new PopTart(["PLACE "+Std.string(towerstoplace)+" TOWERS OR UPGRADES"]);
  98. else
  99. mypop = new PopTart(["PLACE 1 TOWER OR UPGRADE"]);
  100. mypop.waitforever = true;
  101. }
  102. calc_validtower();
  103. targetcache = new Bitmap();
  104. targetcache.visible = false;
  105. targetcache.bitmapData = new BitmapData(680,425,true,0x000000);
  106. draw_targetcache();
  107. Lib.current.addChild(targetcache);
  108. targetline = new Shape();
  109. targetline.visible = false;
  110. Lib.current.addChild(targetline);
  111. targetbox = new Shape();
  112. targetbox.visible = false;
  113. Lib.current.addChild(targetbox);
  114. upgradedist = new Shiner(Fonts.verdanaitalic.gen(["Larger Range and Shot Speed"]));
  115. upgradedist.visible = false;
  116. upgradedist.x = 680/2 - (upgradedist.width/2);
  117. upgradedist.y = 425/2 - 425/6 - (upgradedist.height/2);
  118. Lib.current.addChild(upgradedist);
  119. upgradepower = new Shiner(Fonts.verdanaitalic.gen(["Double Shot Power"]));
  120. upgradepower.visible = false;
  121. upgradepower.x = 680/2 - (upgradepower.width/2);
  122. upgradepower.y = 425/2 - (upgradepower.height/2);
  123. Lib.current.addChild(upgradepower);
  124. upgradeshots = new Shiner(Fonts.verdanaitalic.gen(["Fast Fire Rate"]));
  125. upgradeshots.visible = false;
  126. upgradeshots.x = 680/2 - (upgradeshots.width/2);
  127. upgradeshots.y = 425/2 + 425/6 - (upgradeshots.height/2);
  128. Lib.current.addChild(upgradeshots);
  129. showcache = new Shiner(Fonts.verdanaitalic.gen(["Show Targets"]));
  130. showcache.x = 4;
  131. showcache.y = 425 - 42;
  132. Lib.current.addChild(showcache);
  133. #end
  134. checkforspace = true;
  135. }*/
  136. static public function test_show_targets() : Void
  137. {
  138. #if flash9
  139. if (showcache.bitmapData.rect.contains
  140. (InputHandler.cursx-showcache.x,InputHandler.cursy-showcache.y))
  141. targetcache.visible = true;
  142. else
  143. targetcache.visible = false;
  144. #end
  145. }
  146. /*static public function up() : Void
  147. {
  148. tutorial();
  149. if (mode=="place")
  150. {
  151. test_show_targets();
  152. input_place();
  153. }
  154. else if (mode=="upgrade")
  155. {
  156. input_upgrade();
  157. }
  158. else
  159. {
  160. draw_currenttarget();
  161. input_target();
  162. }
  163. }*/
  164. static public function noroom()
  165. {
  166. if (checkforspace && FortressManager.nospaceleft() && FortressManager.towerscantbeupgraded())
  167. {
  168. #if flash9
  169. mypop = new PopTart(["NO ROOM FOR TOWERS!"]);
  170. #end
  171. towerstoplace = 0;
  172. }
  173. checkforspace = false;
  174. }
  175. static public function tutorial()
  176. {
  177. #if flash9
  178. if (mode=="place")
  179. {
  180. tutorialtickerplace = (tutorialtickerplace+1) % (30*24);
  181. if (tutorialtickerplace==0)
  182. {
  183. if (towerstoplace>1)
  184. mypop = new PopTart(["PLACE "+Std.string(towerstoplace)+" TOWERS OR UPGRADES"]);
  185. else
  186. mypop = new PopTart(["PLACE 1 TOWER OR UPGRADE"]);
  187. }
  188. else if (tutorialtickerplace==(30*6))
  189. {
  190. mypop = new PopTart(["GREEN AREAS ARE OK TO PLACE"]);
  191. }
  192. else if (tutorialtickerplace==(30*12))
  193. {
  194. mypop = new PopTart(["20 SQ. OF TERRITORY = 1 TOWER"]);
  195. }
  196. else if (tutorialtickerplace==(30*18))
  197. {
  198. mypop = new PopTart(["YOU GET 2 FREE TOWERS PER ROUND"]);
  199. }
  200. }
  201. else
  202. {
  203. tutorialtickertarget = (tutorialtickertarget+1) % (30*24);
  204. if (tutorialtickertarget==0)
  205. {
  206. mypop = new PopTart(["SELECT TARGET"]);
  207. }
  208. if (tutorialtickertarget==(30*4))
  209. {
  210. mypop = new PopTart(["SELECT A 3X3 SQUARE..."]);
  211. }
  212. else if (tutorialtickertarget==(30*8))
  213. {
  214. mypop = new PopTart(["THE TOWER WILL TRACK CREEPS..."]);
  215. }
  216. else if (tutorialtickertarget==(30*12))
  217. {
  218. mypop = new PopTart(["IN THIS SQUARE"]);
  219. }
  220. else if (tutorialtickertarget==(30*16))
  221. {
  222. mypop = new PopTart(["CASTLES HAVE A LARGER RADIUS"]);
  223. }
  224. else if (tutorialtickertarget==(30*20))
  225. {
  226. mypop = new PopTart(["UPGRADES IMPROVE TOWER FIREPOWER"]);
  227. }
  228. }
  229. mypop.waitforever = true;
  230. #end
  231. }
  232. /*static public function end()
  233. {
  234. #if flash9
  235. mypop.waitforever = false;
  236. mypop.waittime = 0;
  237. Lib.current.removeChild(targetline);
  238. Lib.current.removeChild(targetbox);
  239. Lib.current.removeChild(targetcache);
  240. Lib.current.removeChild(upgradedist);
  241. Lib.current.removeChild(upgradepower);
  242. Lib.current.removeChild(upgradeshots);
  243. Lib.current.removeChild(showcache);
  244. for (n in okareaarray)
  245. IsoManager.remove(n);
  246. #end
  247. finished = true;
  248. }*/
  249. static public function setlast()
  250. {
  251. lastx = HUD.ctx;
  252. lasty = HUD.cty;
  253. targetstart = IsoMetrics.tiletopix_xy(HUD.ctx, HUD.cty);
  254. lastshooter = Game.cur.map[lastx][lasty].fort.shooter;
  255. }
  256. static public function finishplace()
  257. {
  258. FortressManager.calcterritory();
  259. towerstoplace-=1;
  260. mode = "target";
  261. #if flash9
  262. SFX.towerplacement = true;
  263. mypop = new PopTart(["SELECT TARGET"]);
  264. mypop.waitforever = true;
  265. targetcache.visible = true;
  266. for (n in okareaarray)
  267. {
  268. IsoManager.remove(n);
  269. }
  270. okareaarray = new Array();
  271. draw_targetcache();
  272. calc_validtarget();
  273. targetline.visible = true;
  274. targetline.graphics.clear();
  275. targetbox.visible = true;
  276. targetbox.graphics.clear();
  277. #end
  278. checkforspace = true;
  279. }
  280. static public function input_upgrade()
  281. {
  282. if (InputHandler.click)
  283. {
  284. if (InputHandler.cursy<425/2 - 425/8)
  285. {
  286. upgradetarget.fort.upgrade(2);
  287. finishplace();
  288. }
  289. else if (InputHandler.cursy>=425/2 - 425/8 && InputHandler.cursy<=425/2 + 425/8)
  290. {
  291. upgradetarget.fort.upgrade(3);
  292. finishplace();
  293. }
  294. else
  295. {
  296. upgradetarget.fort.upgrade(4);
  297. finishplace();
  298. }
  299. #if flash9
  300. upgradedist.visible = false;
  301. upgradepower.visible = false;
  302. upgradeshots.visible = false;
  303. #end
  304. }
  305. }
  306. static public function input_place()
  307. {
  308. if (InputHandler.click)
  309. {
  310. if (Graph.inbounds(HUD.ctx, HUD.cty, Game.cur.map) && Game.cur.map[HUD.ctx][HUD.cty].fort!=null && Game.cur.map[HUD.ctx][HUD.cty].fort.shooter!=null)
  311. {
  312. var cur = Game.cur.map[HUD.ctx][HUD.cty];
  313. if (cur.fort.shooter.weapon==1)
  314. {
  315. mode = "upgrade";
  316. upgradetarget = cur;
  317. #if flash9
  318. upgradedist.visible = true;
  319. upgradepower.visible = true;
  320. upgradeshots.visible = true;
  321. #end
  322. setlast();
  323. }
  324. }
  325. else
  326. {
  327. FortressManager.test(HUD.ctx,HUD.cty);
  328. if (FortressManager.test(HUD.ctx,HUD.cty) &&
  329. FortressManager.farfort(HUD.ctx,HUD.cty)
  330. )
  331. {
  332. FortressManager.addtower(HUD.ctx,HUD.cty);
  333. for (n in Game.cur.shooterman.shooters) n.retarget();
  334. setlast();
  335. finishplace();
  336. }
  337. }
  338. }
  339. if (InputHandler.wheeldelta==true || InputHandler.rotleftkey)
  340. {
  341. // select tower
  342. }
  343. else if (InputHandler.rotrightkey)
  344. {
  345. // select tower
  346. }
  347. // add mouseover select towers
  348. // add descriptions?
  349. }
  350. static public function input_target()
  351. {
  352. if (InputHandler.click &&
  353. HUD.ctx>0 && HUD.cty>0 && HUD.ctx<25 && HUD.cty<25 &&
  354. Dist.IntPoint(new IntPoint(HUD.ctx, HUD.cty),
  355. new IntPoint(lastx, lasty))<lastshooter.dist)
  356. {
  357. lastshooter.target = new IntPoint(HUD.ctx, HUD.cty);
  358. mode = "place";
  359. calc_validtower();
  360. if (towerstoplace>0 && !(FortressManager.nospaceleft() && FortressManager.towerscantbeupgraded()))
  361. {
  362. #if flash9
  363. if (towerstoplace>1)
  364. mypop = new PopTart(["PLACE ",towerstoplace," TOWERS OR UPGRADES"]);
  365. else
  366. mypop = new PopTart(["PLACE 1 TOWER OR UPGRADE"]);
  367. mypop.waitforever = true;
  368. //targetbg.visible = false;
  369. //targetsprite.visible = false;
  370. draw_targetcache();
  371. targetline.visible = false;
  372. targetbox.visible = false;
  373. targetcache.visible = false;
  374. #end
  375. }
  376. else
  377. {
  378. ComponentManager.remove(PlaceTowers);
  379. }
  380. }
  381. if (InputHandler.wheeldelta==true || InputHandler.rotleftkey)
  382. {
  383. // select tower
  384. }
  385. else if (InputHandler.rotrightkey)
  386. {
  387. // select tower
  388. }
  389. // add mouseover select towers
  390. // add descriptions?
  391. }
  392. static public function calc_validtower()
  393. {
  394. #if flash9
  395. for (n in okareaarray)
  396. {
  397. IsoManager.remove(n);
  398. }
  399. okareaarray = new Array();
  400. var final : Array<IntPoint> = new Array();
  401. for (n in Graph.iter(Game.cur.map))
  402. {
  403. if (FortressManager.test(n.x, n.y) && FortressManager.farfort(n.x,n.y))
  404. final.push(new IntPoint(n.x, n.y));
  405. }
  406. for (n in final)
  407. {
  408. var nb : IsoBitmap = new IsoBitmap(Images.getdata(0xFD00FF));
  409. var npc : Point = IsoMetrics.tiletopix_xy(n.x, n.y);
  410. nb.offy = 0;
  411. nb.offx = 0;
  412. nb.movep(npc);
  413. okareaarray.push(nb);
  414. IsoManager.add(nb);
  415. }
  416. #end
  417. }
  418. static public function calc_validtarget()
  419. {
  420. #if flash9
  421. var boxstart = IsoMetrics.tiletopix_xy(lastx, lasty);
  422. boxstart.x+=12;
  423. boxstart.y-=0;
  424. var cachebox : Shape = new Shape();
  425. cachebox.graphics.clear();
  426. cachebox.graphics.lineStyle(2,0xFFFF22,0.75);
  427. cachebox.graphics.beginFill(0x888888,0);
  428. var pts : Array<Point> = new Array();
  429. if (lastshooter.weapon!=2)
  430. {
  431. pts.push(IsoMetrics.tilecorner_left(lastx-4, lasty-3));
  432. pts.push(IsoMetrics.tilecorner_bottom(lastx-4, lasty-3));
  433. pts.push(IsoMetrics.tilecorner_right(lastx-4, lasty-3));
  434. pts.push(IsoMetrics.tilecorner_left(lastx-3, lasty-4));
  435. pts.push(IsoMetrics.tilecorner_bottom(lastx-3, lasty-4));
  436. pts.push(IsoMetrics.tilecorner_right(lastx-3, lasty-4));
  437. pts.push(IsoMetrics.tilecorner_top(lastx+3, lasty-4));
  438. pts.push(IsoMetrics.tilecorner_left(lastx+3, lasty-4));
  439. pts.push(IsoMetrics.tilecorner_bottom(lastx+3, lasty-4));
  440. pts.push(IsoMetrics.tilecorner_top(lastx+4, lasty-3));
  441. pts.push(IsoMetrics.tilecorner_left(lastx+4, lasty-3));
  442. pts.push(IsoMetrics.tilecorner_bottom(lastx+4, lasty-3));
  443. pts.push(IsoMetrics.tilecorner_right(lastx+4, lasty+3));
  444. pts.push(IsoMetrics.tilecorner_top(lastx+4, lasty+3));
  445. pts.push(IsoMetrics.tilecorner_left(lastx+4, lasty+3));
  446. pts.push(IsoMetrics.tilecorner_right(lastx+3, lasty+4));
  447. pts.push(IsoMetrics.tilecorner_top(lastx+3, lasty+4));
  448. pts.push(IsoMetrics.tilecorner_left(lastx+3, lasty+4));
  449. pts.push(IsoMetrics.tilecorner_bottom(lastx-3, lasty+4));
  450. pts.push(IsoMetrics.tilecorner_right(lastx-3, lasty+4));
  451. pts.push(IsoMetrics.tilecorner_top(lastx-3, lasty+4));
  452. pts.push(IsoMetrics.tilecorner_bottom(lastx-4, lasty+3));
  453. pts.push(IsoMetrics.tilecorner_right(lastx-4, lasty+3));
  454. pts.push(IsoMetrics.tilecorner_top(lastx-4, lasty+3));
  455. }
  456. else if (lastshooter.weapon==2)
  457. {
  458. pts.push(IsoMetrics.tilecorner_left(lastx-6, lasty-4));
  459. pts.push(IsoMetrics.tilecorner_bottom(lastx-6, lasty-4));
  460. pts.push(IsoMetrics.tilecorner_right(lastx-6, lasty-4));
  461. pts.push(IsoMetrics.tilecorner_left(lastx-5, lasty-5));
  462. pts.push(IsoMetrics.tilecorner_bottom(lastx-5, lasty-5));
  463. pts.push(IsoMetrics.tilecorner_right(lastx-5, lasty-5));
  464. pts.push(IsoMetrics.tilecorner_left(lastx-4, lasty-6));
  465. pts.push(IsoMetrics.tilecorner_bottom(lastx-4, lasty-6));
  466. pts.push(IsoMetrics.tilecorner_right(lastx-4, lasty-6));
  467. pts.push(IsoMetrics.tilecorner_top(lastx+4, lasty-6));
  468. pts.push(IsoMetrics.tilecorner_left(lastx+4, lasty-6));
  469. pts.push(IsoMetrics.tilecorner_bottom(lastx+4, lasty-6));
  470. pts.push(IsoMetrics.tilecorner_top(lastx+5, lasty-5));
  471. pts.push(IsoMetrics.tilecorner_left(lastx+5, lasty-5));
  472. pts.push(IsoMetrics.tilecorner_bottom(lastx+5, lasty-5));
  473. pts.push(IsoMetrics.tilecorner_top(lastx+6, lasty-4));
  474. pts.push(IsoMetrics.tilecorner_left(lastx+6, lasty-4));
  475. pts.push(IsoMetrics.tilecorner_bottom(lastx+6, lasty-4));
  476. pts.push(IsoMetrics.tilecorner_right(lastx+6, lasty+4));
  477. pts.push(IsoMetrics.tilecorner_top(lastx+6, lasty+4));
  478. pts.push(IsoMetrics.tilecorner_left(lastx+6, lasty+4));
  479. pts.push(IsoMetrics.tilecorner_right(lastx+5, lasty+5));
  480. pts.push(IsoMetrics.tilecorner_top(lastx+5, lasty+5));
  481. pts.push(IsoMetrics.tilecorner_left(lastx+5, lasty+5));
  482. pts.push(IsoMetrics.tilecorner_right(lastx+4, lasty+6));
  483. pts.push(IsoMetrics.tilecorner_top(lastx+4, lasty+6));
  484. pts.push(IsoMetrics.tilecorner_left(lastx+4, lasty+6));
  485. pts.push(IsoMetrics.tilecorner_bottom(lastx-4, lasty+6));
  486. pts.push(IsoMetrics.tilecorner_right(lastx-4, lasty+6));
  487. pts.push(IsoMetrics.tilecorner_top(lastx-4, lasty+6));
  488. pts.push(IsoMetrics.tilecorner_bottom(lastx-5, lasty+5));
  489. pts.push(IsoMetrics.tilecorner_right(lastx-5, lasty+5));
  490. pts.push(IsoMetrics.tilecorner_top(lastx-5, lasty+5));
  491. pts.push(IsoMetrics.tilecorner_bottom(lastx-6, lasty+4));
  492. pts.push(IsoMetrics.tilecorner_right(lastx-6, lasty+4));
  493. pts.push(IsoMetrics.tilecorner_top(lastx-6, lasty+4));
  494. }
  495. cachebox.graphics.moveTo(pts[0].x, pts[0].y);
  496. for(p in pts)
  497. {
  498. cachebox.graphics.lineTo(p.x, p.y);
  499. }
  500. cachebox.graphics.endFill();
  501. targetcache.bitmapData.draw(cachebox);
  502. #end
  503. }
  504. static public function draw_targetcache()
  505. {
  506. // draw the shape and line of each target.
  507. #if flash9
  508. targetcache.bitmapData = new BitmapData(680,425,true,0x000000);
  509. for (shoot in Game.cur.shooterman.shooters)
  510. {
  511. if (shoot.target!=null)
  512. {
  513. var boxstart = IsoMetrics.tiletopix_xy(shoot.target.x, shoot.target.y);
  514. boxstart.x+=12;
  515. boxstart.y-=22;
  516. var towerstart = IsoMetrics.tiletopix_xy(shoot.location.x, shoot.location.y);
  517. var distx : Float = boxstart.x-towerstart.x;
  518. var disty : Float = boxstart.y-towerstart.y;
  519. var tdist : Float = Math.sqrt(distx*distx + disty*disty);
  520. var dirx : Float = (distx/tdist);
  521. var diry : Float = (disty/tdist);
  522. var cachebox : Shape = new Shape();
  523. var cacheline : Shape = new Shape();
  524. cacheline.graphics.clear();
  525. cacheline.graphics.lineStyle(1,0xFFFFFF,0.75);
  526. cacheline.graphics.beginFill(0xFFFFFF,0.1);
  527. cacheline.graphics.moveTo(towerstart.x+11+(diry*3),towerstart.y+4-(dirx*3));
  528. cacheline.graphics.lineTo(towerstart.x+11-(diry*3),towerstart.y+4+(dirx*3));
  529. cacheline.graphics.lineTo(boxstart.x,boxstart.y+33);
  530. cacheline.graphics.endFill();
  531. cachebox.graphics.clear();
  532. cachebox.graphics.lineStyle(1,0xFF0000,0.75);
  533. cachebox.graphics.beginFill(0xFF0000,0.1);
  534. cachebox.graphics.moveTo(boxstart.x, boxstart.y);
  535. cachebox.graphics.lineTo(boxstart.x+(11*3), boxstart.y+(11*3));
  536. cachebox.graphics.lineTo(boxstart.x, boxstart.y+(11*6));
  537. cachebox.graphics.lineTo(boxstart.x-(11*3), boxstart.y+(11*3));
  538. cachebox.graphics.endFill();
  539. targetcache.bitmapData.draw(cacheline);
  540. targetcache.bitmapData.draw(cachebox);
  541. }
  542. else if (shoot.weapon==0)
  543. {
  544. var boxstart = IsoMetrics.tiletopix_xy(shoot.location.x, shoot.location.y);
  545. boxstart.x+=12;
  546. boxstart.y-=0;
  547. var cachebox : Shape = new Shape();
  548. cachebox.graphics.clear();
  549. cachebox.graphics.lineStyle(1,0x00FF00,0.75);
  550. cachebox.graphics.beginFill(0x00FF00,0.2);
  551. cachebox.graphics.moveTo(boxstart.x-(11*1), boxstart.y-(11*5));
  552. cachebox.graphics.lineTo(boxstart.x+(11*0), boxstart.y-(11*4));
  553. cachebox.graphics.lineTo(boxstart.x+(11*1), boxstart.y-(11*5));
  554. cachebox.graphics.lineTo(boxstart.x+(11*6), boxstart.y+(11*0));
  555. cachebox.graphics.lineTo(boxstart.x+(11*5), boxstart.y+(11*1));
  556. cachebox.graphics.lineTo(boxstart.x+(11*6), boxstart.y+(11*2));
  557. cachebox.graphics.lineTo(boxstart.x+(11*1), boxstart.y+(11*7));
  558. cachebox.graphics.lineTo(boxstart.x+(11*0), boxstart.y+(11*6));
  559. cachebox.graphics.lineTo(boxstart.x-(11*1), boxstart.y+(11*7));
  560. cachebox.graphics.lineTo(boxstart.x-(11*6), boxstart.y+(11*2));
  561. cachebox.graphics.lineTo(boxstart.x-(11*5), boxstart.y+(11*1));
  562. cachebox.graphics.lineTo(boxstart.x-(11*6), boxstart.y+(11*0));
  563. cachebox.graphics.endFill();
  564. targetcache.bitmapData.draw(cachebox);
  565. }
  566. }
  567. #end
  568. }
  569. static public function draw_currenttarget()
  570. {
  571. // draw the current target's specific shape and line, and update the tower angle sprite
  572. #if flash9
  573. var distx : Float = InputHandler.cursx-targetstart.x;
  574. var disty : Float = InputHandler.cursy-targetstart.y;
  575. var tdist : Float = Math.sqrt(distx*distx + disty*disty);
  576. var dirx : Float = (distx/tdist);
  577. var diry : Float = (disty/tdist);
  578. var goodlocation = false;
  579. if (Dist.IntPoint(new IntPoint(HUD.ctx,HUD.cty), new IntPoint(lastx, lasty))<lastshooter.dist && HUD.ctx<25 && HUD.cty<25
  580. && HUD.ctx>0 && HUD.cty>0)
  581. {
  582. goodlocation=true;
  583. }
  584. targetline.graphics.clear();
  585. if (goodlocation)
  586. {
  587. targetline.graphics.lineStyle(1,0xFFFFFF);
  588. targetline.graphics.beginFill(0xFFFFFF,0.8);
  589. targetline.graphics.moveTo(targetstart.x+11+(diry*5),targetstart.y+4-(dirx*5));
  590. targetline.graphics.lineTo(targetstart.x+11-(diry*5),targetstart.y+4+(dirx*5));
  591. targetline.graphics.lineTo(InputHandler.cursx,InputHandler.cursy);
  592. targetline.graphics.endFill();
  593. }
  594. var startpoint = IsoMetrics.tiletopix_xy(HUD.ctx,HUD.cty);
  595. startpoint.x+=12;
  596. startpoint.y-=22;
  597. targetbox.graphics.clear();
  598. if (goodlocation)
  599. {
  600. targetbox.graphics.lineStyle(1,0xFFFFFF);
  601. targetbox.graphics.beginFill(0xAAFFAA,0.8);
  602. }
  603. else
  604. {
  605. targetbox.graphics.lineStyle(1,0x888888);
  606. targetbox.graphics.beginFill(0x000000,0.8);
  607. }
  608. targetbox.graphics.moveTo(startpoint.x, startpoint.y);
  609. targetbox.graphics.lineTo(startpoint.x+(11*3), startpoint.y+(11*3));
  610. targetbox.graphics.lineTo(startpoint.x, startpoint.y+(11*6));
  611. targetbox.graphics.lineTo(startpoint.x-(11*3), startpoint.y+(11*3));
  612. targetbox.graphics.endFill();
  613. var vecx = targetstart.x + 12 - InputHandler.cursx;
  614. var vecy = targetstart.y - InputHandler.cursy;
  615. var startdist = Math.sqrt((vecx*vecx)+(vecy*vecy));
  616. lastshooter.angle = Math.atan2(vecx/startdist, vecy/startdist);
  617. lastshooter.drawangle();
  618. #end
  619. }
  620. }