Advertisement
Guest User

Untitled

a guest
Apr 12th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3. import flash.display.Sprite;
  4. import flash.display.MovieClip;
  5. import flash.events.Event;
  6. import flash.events.MouseEvent;
  7. import flash.events.KeyboardEvent;
  8. import flash.ui.Keyboard;
  9. import flash.ui.Mouse;
  10.  
  11. public class Main extends Sprite
  12. {
  13. // Createing The Level
  14. // Reference To Tile Moveiclip
  15. private var tileVar:Tile;
  16. // Grid Width Can Be Set To Whatever Number Of Tiles Is In Each Line In The levelArray
  17. private var gridWidth:uint = 18;
  18. // The Level Array Holds Number Values To Repersent If A Tile Is A Empty Space, Wall, End Point, Etc
  19. private var levelArray:Array =
  20. [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  21. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  22. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  23. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  24. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  25. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  26. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  27. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  28. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  29. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  30. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  31. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  32. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  33. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  34. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  35. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  36. 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  37. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  38. // Level Vector Is A Vector That Is Later Filled With All The Tile Objects That Make Up The Level
  39. private var levelVector:Vector.<Object > = new Vector.<Object > ;
  40. // Pathfinding
  41. // Open List Is An Array Of The Current Tiles Being Checked
  42. private var openListArray:Array = [];
  43. // Close List Is An Array Of Tiles That Have Been Checked
  44. private var closeListArray:Array = [];
  45. // Current Parent Is The Current Tile We Are Checking The Surroundings Of
  46. private var currentParent:Object;
  47. // Current Target Is Our Target Tile
  48. private var currentTarget:Object;
  49. // Starting Parent Doesn't Really Need To Exist But Is A Reference To The First Tile Being Checked At The Start Of Pathfinding
  50. private var startingParent:Object;
  51. // A Variable To Check If The Path Has Been Found
  52. private var currentTargetFound:Boolean;
  53. // A Variable That Checks If No Path Can Be Found
  54. private var noPathCanBeFound:Boolean;
  55. // The Final Array That Is Filled With The Shortest Path To A Point
  56. private var finalListArray:Array = [];
  57. // Enemy
  58. private var enemyVar:Enemy;
  59. private var currentTileEnemyIn:Object = null;
  60. // Keyboard
  61. // Used As A Pause Button
  62. private var spaceKeyDown:Boolean;
  63. public function Main()
  64. {
  65. // Remove Right Click Menu;
  66. stage.addEventListener(MouseEvent.RIGHT_CLICK, function(e:Event){});
  67. // Create The Level
  68. createLevel();
  69. // Create The Enemy
  70. createEnemy();
  71. // On Enter Frame Events
  72. addEventListener(Event.ENTER_FRAME,onFrame);
  73. //
  74. stage.addEventListener(KeyboardEvent.KEY_UP,keyIsUp);
  75. stage.addEventListener(KeyboardEvent.KEY_DOWN,keyIsDown);
  76. }
  77. // On Frame Events
  78. private function onFrame(e:Event):void
  79. {
  80. // Checks If There Is A Path To Move Along
  81. if (noPathCanBeFound == false)
  82. {
  83. // Checks If Enemy Has Finished Path And If Enemy Movement Should Be Paused - If Both False Then Enemy Move Along Its Path
  84. if (enemyVar.enemyPathArray.length != 0 && spaceKeyDown == false)
  85. {
  86. // Simple Movement To Get To Each Tile
  87. if (enemyVar.y > enemyVar.enemyPathArray[0].y)
  88. {
  89. enemyVar.y--;
  90. }
  91. if (enemyVar.y < enemyVar.enemyPathArray[0].y)
  92. {
  93. enemyVar.y++;
  94. }
  95. if (enemyVar.x > enemyVar.enemyPathArray[0].x)
  96. {
  97. enemyVar.x--;
  98. }
  99. if (enemyVar.x < enemyVar.enemyPathArray[0].x)
  100. {
  101. enemyVar.x++;
  102. }
  103. // If The Enemy Reaches The Center Of A Tile Remove It From The List Of Tiles It Needs To Move To
  104. if (enemyVar.y == enemyVar.enemyPathArray[0].y && enemyVar.x == enemyVar.enemyPathArray[0].x)
  105. {
  106. enemyVar.enemyPathArray.splice(0,1);
  107. }
  108. }
  109. }
  110. }
  111. // Create Enemy
  112. private function createEnemy():void
  113. {
  114. enemyVar = new Enemy();
  115. enemyVar.x = 40 + Math.round(Math.random() * 640);
  116. enemyVar.y = 40 + Math.round(Math.random() * 640);
  117. enemyVar.enemyPathArray = [];
  118. enemyVar.currentTileEnemyIn = null;
  119. addChild(enemyVar);
  120. }
  121. // Create Level
  122. private function createLevel():void
  123. {
  124. var tilePlacementX:Number = 20;
  125. var tilePlacementY:Number = 20;
  126. var currentCollum:int = 1;
  127. var currentRow:int = 1;
  128. // cLT = Create Level Tiles
  129. for (var cLT=0; cLT<levelArray.length; cLT++)
  130. {
  131. tileVar = new Tile();
  132. tileVar.x = tilePlacementX;
  133. tileVar.y = tilePlacementY;
  134. // Purely Aesthetic
  135. tileVar.gotoAndStop(levelArray[cLT]+1);
  136. // If The Level Array Not A 1 Then The Tile Is Walkable;
  137. if (levelArray[cLT] != 1)
  138. {
  139. tileVar.walkable = true;
  140. }
  141. else
  142. {
  143. // If The Level Array Is A 1 Then Make A Non-Walkable Wall Tile
  144. if (levelArray[cLT] == 1)
  145. {
  146. tileVar.walkable = false;
  147. }
  148. }
  149. // This Is A Little Preset Thing I Did Where If In The Level Array At The Start I Put A 2 In That Would Be The End Point
  150. // Much Like In A TD That Could Be The Point The Enemies Want To Get To
  151. /*if (levelArray[cLT] == 2)
  152. {
  153. currentTarget = tileVar;
  154. }*/
  155. // These Vars Are Used In The Pathfinding Functions And Are Explined When They Come Up
  156. tileVar.positionInArray = cLT;
  157. tileVar.currentRow = currentRow;
  158. tileVar.currentCollum = currentCollum;
  159. tileVar.gScore = 0;
  160. tileVar.hScore = 0;
  161. tileVar.fScore = 0;
  162. tileVar.currentTileParent = null;
  163. tileVar.alreadyOnClosedList = false;
  164. // This Listener Let Us Add And Remove Walls
  165. tileVar.addEventListener(MouseEvent.CLICK,makeIntoWall);
  166. // This Listener Lets Us Make A End Point
  167. tileVar.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN,makeIntoEndArea);
  168. // Add The Child To Stage
  169. addChild(tileVar);
  170. // Push This Object Into The Level Vector
  171. levelVector.push(tileVar);
  172. // Updates The X and Y Placemetn For The Next Tile;
  173. tilePlacementX += 40;
  174. currentRow++;
  175. if (tilePlacementX >= 720)
  176. {
  177. currentCollum++;
  178. currentRow = 1;
  179. tilePlacementX = 20;
  180. tilePlacementY += 40;
  181. }
  182. }
  183. setChildIndex(tutorialText,numChildren - 1);
  184. }
  185. // This Function Lets Us Add/Remove Walls
  186. private function makeIntoWall(e:MouseEvent):void
  187. {
  188. // Can Not Make Current Tile The Enemy Is In Into A Wall
  189. if (e.currentTarget != currentTileEnemyIn)
  190. {
  191. // If Tile Is Not A Wall Make It A Wall
  192. if (e.currentTarget.walkable == true)
  193. {
  194. e.currentTarget.gotoAndStop(2);
  195. e.currentTarget.walkable = false;
  196. }
  197. else
  198. {
  199. // If Tile Is A Wall Make It Not A Wall
  200. if (e.currentTarget.walkable == false)
  201. {
  202. e.currentTarget.gotoAndStop(0);
  203. e.currentTarget.walkable = true;
  204. }
  205. }
  206. // If You Have A End Point Then Update The Path If You Have No End Point This Prevent A Crash
  207. if (currentTarget != null)
  208. {
  209. // Finds The Paths Starting Point
  210. findStartingPoint();
  211. }
  212. }
  213. }
  214. private function makeIntoEndArea(e:MouseEvent):void
  215. {
  216. // Can Not Make Current Tile The Enemy Is In Into A Wall
  217. if (e.currentTarget != currentTileEnemyIn)
  218. {
  219. // Make Current Tile Into An End Area
  220. e.currentTarget.gotoAndStop(3);
  221. e.currentTarget.walkable = true;
  222. // Sets The Selected Tile To The Current Target Of The Pathfinding
  223. currentTarget = e.currentTarget;
  224. // Finds The Paths Starting Point
  225. findStartingPoint();
  226. }
  227. }
  228. private function findStartingPoint():void
  229. {
  230. // fSP = Find Starting Point
  231. for (var fSP=0; fSP<levelVector.length; fSP++)
  232. {
  233. if (levelVector[fSP].hitTestPoint(enemyVar.x,enemyVar.y,true))
  234. {
  235. enemyVar.currentTileEnemyIn = levelVector[fSP];
  236. startingParent = levelVector[fSP];
  237. break;
  238. }
  239. }
  240. // Update Path
  241. setPathfindingForCurrentParentTile(enemyVar.currentTileEnemyIn);
  242. findAPathForEnemy(enemyVar);
  243. }
  244. private function findAPathForEnemy(currentEnemy:Object):void
  245. {
  246. // At The Start We Assume A Path Can Be Found
  247. noPathCanBeFound = false;
  248. // This Is Purely Aesthetic - Like All gotoAndStop It Only Adjusts The Appearence Of The Tiles This Loop Can Be Removed
  249. // rLVA = Reset Level Vector Appearence
  250. for (var rLVA=0; rLVA<levelVector.length; rLVA++)
  251. {
  252. if (levelVector[rLVA].currentFrame == 3 || levelVector[rLVA].currentFrame == 7)
  253. {
  254. levelVector[rLVA].gotoAndStop(1);
  255. }
  256. }
  257. // Reset The Open And Closed Lists
  258. openListArray = [];
  259. closeListArray = [];
  260. // Push The Tile The Enemy Is In Into The Open List
  261. openListArray.push(enemyVar.currentTileEnemyIn);
  262. // Resets The Level Vectors Values For Pathfinding;
  263. // rLVPV = Reset Level Vector Pathfinding Values
  264. for (var rLVPV=0; rLVPV<levelVector.length; rLVPV++)
  265. {
  266. levelVector[rLVPV].gScore = 0;
  267. levelVector[rLVPV].hScore = 0;
  268. levelVector[rLVPV].fScore = 0;
  269. levelVector[rLVPV].currentTileParent = null;
  270. levelVector[rLVPV].alreadyOnClosedList = false;
  271. }
  272. // Reset The Fact That We Have Found The Square We Are Going To
  273. currentTargetFound = false;
  274. // Set The Current Parent Square To The Square The Enemy Is Currently In
  275. currentParent = enemyVar.currentTileEnemyIn;
  276. // Loop Until We Find A Target
  277. while (currentTargetFound == false)
  278. {
  279. // If We Run Out Of Possible Tiles In Our Open List It Means The Target Can Not Be Reached (Is Surrounded By Impassable Tiles)
  280. if (openListArray.length == 0)
  281. {
  282. // We Break The Loop
  283. currentTargetFound = true;
  284. // And Set It So The onFrame Function Does Not Try To Move The Enemy To A Point That Can Not Be Reahced
  285. noPathCanBeFound = true;
  286. }
  287. // The Start Of Fun Pathfinding Functions
  288. setPathfindingForCurrentParentTile(currentParent);
  289. // Through The Above Function We Will Set currentTargetFound To True Unless It Is Impossible To Get To The Current Target
  290. if (currentTargetFound == true)
  291. {
  292. // Sets The Enemies Parth To The Final List Path We Create With The setPathfindingForCurrentParentTile Function
  293. enemyVar.enemyPathArray = finalListArray;
  294. // Reverses This List Becuase It Starts At The End
  295. enemyVar.enemyPathArray.reverse();
  296. // Remove The First Object In This List As We Are Already In That Square;
  297. enemyVar.enemyPathArray.splice(0,1);
  298. }
  299. }
  300. }
  301. private function setPathfindingForCurrentParentTile(currentParentTile:Object):void
  302. {
  303. // Remove Current Parent From Open List
  304. // rCPFOL = Remove Current Parent From Open List
  305. for (var rCPFOL=0; rCPFOL<openListArray.length; rCPFOL++)
  306. {
  307. if (currentParent == openListArray[rCPFOL])
  308. {
  309. openListArray.splice(rCPFOL,1);
  310. break;
  311. }
  312. }
  313. // Add Current Parent To Close List - AKA The List Of Objects We've Checked
  314. closeListArray.push(currentParentTile);
  315. currentParentTile.alreadyOnClosedList = true;
  316. // NW Tile
  317. // Check If Going NW Would Go Through A Wall - NOTE: IF YOU WANT TO ALLOW ENEMIES TO CUT THROUGH CORNERS REMOVE THIS IF STATEMENT
  318. if (levelVector[currentParentTile.positionInArray-(gridWidth)].walkable == true && levelVector[currentParentTile.positionInArray-(1)].walkable == true)
  319. {
  320. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray-(gridWidth+1)]);
  321. }
  322. // N Tile
  323. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray-(gridWidth)]);
  324. // Check If Going NE Would Go Through A Wall - NOTE: IF YOU WANT TO ALLOW ENEMIES TO CUT THROUGH CORNERS REMOVE THIS IF STATEMENT
  325. if (levelVector[currentParentTile.positionInArray-(gridWidth)].walkable == true && levelVector[currentParentTile.positionInArray+(1)].walkable == true)
  326. {
  327. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray-(gridWidth-1)]);
  328. }
  329. // W Tile
  330. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray-(1)]);
  331. // E Tile
  332. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray+(1)]);
  333. // SW Tile
  334. // Check If Going NW Would Go Through A Wall - NOTE: IF YOU WANT TO ALLOW ENEMIES TO CUT THROUGH CORNERS REMOVE THIS IF STATEMENT
  335. if (levelVector[currentParentTile.positionInArray+(gridWidth)].walkable == true && levelVector[currentParentTile.positionInArray-(1)].walkable == true)
  336. {
  337. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray+(gridWidth-1)]);
  338. }
  339. // S Tile
  340. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray+(gridWidth)]);
  341. // Check If Going SE Would Go Through A Wall - NOTE: IF YOU WANT TO ALLOW ENEMIES TO CUT THROUGH CORNERS REMOVE THIS IF STATEMENT
  342. if (levelVector[currentParentTile.positionInArray+(gridWidth)].walkable == true && levelVector[currentParentTile.positionInArray+(1)].walkable == true)
  343. {
  344. checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(levelVector[currentParentTile.positionInArray+(gridWidth+1)]);
  345. }
  346. // Find New Current Parent Tile
  347. getNewCurrentParentTile();
  348. }
  349. private function checkIfThisCurrentSurroundingTileIsOnOpenListAndIfNotAddIt(currentChildToCheckIfOnOpenArray:Object):void
  350. {
  351. // If The Target We Are Checking Is The Target Point We Want To Get To Then We Have Found Our Path
  352. if (currentChildToCheckIfOnOpenArray == currentTarget)
  353. {
  354. currentTargetFound = true;
  355. // Sets End Tile Parent To Current Parent
  356. currentTarget.currentParent = currentParent;
  357. // This Function Gives Us Our Path From The End To The Tile The Enemy Is In
  358. findWayBack();
  359. }
  360. // If We Have Not Found Our Target And This Tile Is Not Our Target Then...
  361. if (currentChildToCheckIfOnOpenArray != currentTarget && currentTargetFound == false)
  362. {
  363. // If It Is A Wall Or Already On The Closed List We Skip It
  364. if (currentChildToCheckIfOnOpenArray.walkable == true && currentChildToCheckIfOnOpenArray.alreadyOnClosedList == false)
  365. {
  366. // Check If This Child If Already On The Open List
  367. var thisChildIsNotAlreadyOnOpenList:Boolean = true;
  368. // aCPSTTOL = Add Current Parent Surrounding Tiles To Open List
  369. for (var aCPSTTOL=0; aCPSTTOL<openListArray.length; aCPSTTOL++)
  370. {
  371. if (openListArray[aCPSTTOL] == currentChildToCheckIfOnOpenArray)
  372. {
  373. // This Child Is On The Open List
  374. thisChildIsNotAlreadyOnOpenList = false;
  375. break;
  376. }
  377. }
  378. // If thisChildIsNotAlreadyOnOpenList Is Still True Then Add It To The Open List
  379. if (thisChildIsNotAlreadyOnOpenList == true)
  380. {
  381. // Add Current Child To Open Array
  382. openListArray.push(currentChildToCheckIfOnOpenArray);
  383. // Sets Child Of Current Parent, Parent Var To That Of The Current Parent;
  384. currentChildToCheckIfOnOpenArray.currentParent = currentParent;
  385. // Give This Tile An H Score
  386. // An H Score Is The Number Of Tiles This Tile Is From The End (Not Counting Walls) Times 10
  387. updateATileHScore(currentChildToCheckIfOnOpenArray);
  388. // Add To This Tiles G Score
  389. // A G Score Is How Far A Tile Is In The Path We Are Taking - If Getting To This Tile Is A Up, Down, Left, Or Right Movement
  390. // Then The G Score Is Equal To Its Parents G Score + 10, If Its A Diagonal Movement Then The G Score Is Equal To Its Parents G Score + 14 Beucase Moveing Diagonal Is Slightly Longer Path
  391. addToATileGScore(currentChildToCheckIfOnOpenArray);
  392. // Update The Tiles F Score
  393. // A F Score Is The Tiles H + The Tiles G Score
  394. // The Lower The F Score The Better The Path Is To TAke
  395. updateATileFScore(currentChildToCheckIfOnOpenArray);
  396. }
  397. }
  398. }
  399. }
  400. private function getNewCurrentParentTile():void
  401. {
  402. // If We Still Have Not Found Out Target
  403. if (currentTargetFound == false)
  404. {
  405. // Look For The Lowest F Value
  406. var currentLowestFValue:int = 10000;
  407. // fLFV = Find Lowest F Value
  408. for (var fLFV=0; fLFV<openListArray.length; fLFV++)
  409. {
  410. // If A Tiles F Value Is Lower Then The Current One Then Our Parent Becomes That Tile
  411. if (openListArray[fLFV].fScore < currentLowestFValue)
  412. {
  413. currentLowestFValue = openListArray[fLFV].fScore;
  414. currentParent = openListArray[fLFV];
  415. }
  416. }
  417. }
  418. }
  419. private function findWayBack():void
  420. {
  421. // We Have Found Our Current Target Now We Just Keep Adding The Parent Of Each Square Until We Get To Our Starting Square
  422. var currentFindWayBackParent:Object = currentTarget;
  423. // Each New Parent We Hop To Is Added To Our Final List Array
  424. finalListArray = [];
  425. while (currentFindWayBackParent != startingParent)
  426. {
  427. finalListArray.push(currentFindWayBackParent);
  428. currentFindWayBackParent.gotoAndStop(7);
  429. currentFindWayBackParent = currentFindWayBackParent.currentParent;
  430. }
  431. // When We Find Our Parent We Have The Shortest Path From The Current Target To Our Parent
  432. if (currentFindWayBackParent == startingParent)
  433. {
  434. finalListArray.push(startingParent);
  435. startingParent.gotoAndStop(7);
  436. }
  437. }
  438. private function addToATileGScore(currentTileGScoreToAddTo:Object):void
  439. {
  440. // Check If Parent Is Up Down Left Or Right Of This Tile
  441. if (levelVector[currentTileGScoreToAddTo.positionInArray-(gridWidth)] == currentTileGScoreToAddTo.currentParent || levelVector[currentTileGScoreToAddTo.positionInArray-(1)] == currentTileGScoreToAddTo.currentParent|| levelVector[currentTileGScoreToAddTo.positionInArray+(1)] == currentTileGScoreToAddTo.currentParent || levelVector[currentTileGScoreToAddTo.positionInArray+(gridWidth)] == currentTileGScoreToAddTo.currentParent)
  442. {
  443. // A Up Down Left Or Right Movement Cost 10
  444. currentTileGScoreToAddTo.gScore = currentTileGScoreToAddTo.currentParent.gScore + 10;
  445. }
  446. // Check If Parent Is Diagonal To This Tile
  447. if (levelVector[currentTileGScoreToAddTo.positionInArray - (gridWidth - 1)] == currentTileGScoreToAddTo.currentParent || levelVector[currentTileGScoreToAddTo.positionInArray - (gridWidth + 1)] == currentTileGScoreToAddTo.currentParent || levelVector[currentTileGScoreToAddTo.positionInArray + (gridWidth - 1)] == currentTileGScoreToAddTo.currentParent || levelVector[currentTileGScoreToAddTo.positionInArray + (gridWidth + 1)] == currentTileGScoreToAddTo.currentParent)
  448. {
  449. // A Diagonal Movement Cost 14
  450. currentTileGScoreToAddTo.gScore = currentTileGScoreToAddTo.currentParent.gScore + 14;
  451. }
  452. }
  453. private function updateATileHScore(currentTileHScoreToUpdate:Object):void
  454. {
  455. // Simple Math To Find The Combined Diffrence Between The Current Tiles Collum And Row Compated To The Target Tile Collum And Row
  456. var currentTargetCollum:int = currentTarget.currentCollum;
  457. var currentTargetRow:int = currentTarget.currentRow;
  458. var currentCollumDiffrence:int;
  459. var currentRowDiffrence:int;
  460. currentCollumDiffrence = currentTargetCollum - currentTileHScoreToUpdate.currentCollum;
  461. if (currentCollumDiffrence < 0)
  462. {
  463. currentCollumDiffrence *= -1;
  464. }
  465. currentRowDiffrence = currentTargetRow - currentTileHScoreToUpdate.currentRow;
  466. if (currentRowDiffrence < 0)
  467. {
  468. currentRowDiffrence *= -1;
  469. }
  470. currentTileHScoreToUpdate.hScore = 10 * (currentCollumDiffrence + currentRowDiffrence);
  471. }
  472. private function updateATileFScore(currentTileGScoreToUpdate:Object):void
  473. {
  474. // Adds The Tile G and H Score Together
  475. currentTileGScoreToUpdate.fScore = currentTileGScoreToUpdate.hScore + currentTileGScoreToUpdate.gScore;
  476. }
  477. // Keyboard Events
  478. private function keyIsUp(e:KeyboardEvent):void
  479. {
  480. if (e.keyCode == 32)
  481. {
  482. spaceKeyDown = false;
  483. }
  484. }
  485. private function keyIsDown(e:KeyboardEvent):void
  486. {
  487. if (e.keyCode == 32)
  488. {
  489. spaceKeyDown = true;
  490. }
  491. }
  492. }
  493. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement