Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. // Creating variables
  2. var myX = 0, myY = 0, yes=0
  3. var patX=[], patY=[], ip, patSize=10, enemyX=[], enemyY=[], ie, broiEnemy=0, ticks=0, currentPosition=[], healthEnemy=[], towerX=[], towerY=[], broiTowers=0, it, target=[]
  4. for(ip=0; ip<150; ip++) {
  5. patX[ip]=ip
  6. patY[ip]=20
  7. }
  8. for(ip=150; ip<300; ip++) {
  9. patX[ip]=150
  10. patY[ip]=ip-150+20
  11. }
  12.  
  13. for(ip=300; ip<400; ip++) {
  14. patX[ip]=ip-150
  15. patY[ip]=170
  16. }
  17. for(ip=400; ip<500; ip++) {
  18. patX[ip]=250
  19. patY[ip]=170-ip+400
  20. }
  21. for(ip=500; ip<700; ip++) {
  22. patX[ip]=250+ip-500
  23. patY[ip]=170-600+ip
  24. }
  25. for(ip=700; ip<1160; ip++) {
  26. patX[ip]=250-ip-500+1400
  27. patY[ip]=170-600+700
  28. }
  29.  
  30. function update() {
  31. myX=mouseX
  32. myY=mouseY
  33.  
  34. ticks++
  35. if(ticks%60==0) {
  36. broiEnemy++
  37. healthEnemy[broiEnemy]=120
  38. currentPosition[broiEnemy]=0
  39. enemyX[broiEnemy]=patX[currentPosition[broiEnemy]]
  40. enemyY[broiEnemy]=patY[currentPosition[broiEnemy]]
  41. }
  42. for(ie=0; ie<broiEnemy; ie++) {
  43. if(enemyX[ie]!=undefined) {
  44. currentPosition[ie]+=1
  45. enemyX[ie]=patX[currentPosition[ie]]
  46. enemyY[ie]=patY[currentPosition[ie]]
  47. }
  48. for(it=0; it<=broiTowers; it++) {
  49. if(areCirclesColliding(towerX[it], towerY[it], 100, enemyX[ie], enemyY[ie], 10)) {
  50. yes++
  51. target[it]=broiEnemy;
  52. for(ie=broiEnemy; ie>0; ie--) {
  53. if(ie<target[it]) {
  54. target[it]=ie
  55. }
  56. }
  57.  
  58. healthEnemy[target[it]]-=0.6
  59. if(healthEnemy[ie]<=0) {
  60. enemyX[target[it]]=undefined
  61. enemyY[target[it]]=undefined
  62. healthEnemy[target[it]]=undefined
  63. }
  64. }
  65. yes=0
  66. }
  67. }
  68. }
  69. function FindTarget() {
  70.  
  71. }
  72. function draw() {
  73. // This is how you draw a rectangle
  74. context.fillStyle="blue";
  75. fillCircle(myX, myY, 10);
  76. context.globalAlpha=0.1
  77. context.fillStyle="grey";
  78. fillCircle(myX, myY, 100);
  79. context.globalAlpha=1
  80. for(ip=0; ip<1160; ip++) {
  81. context.fillStyle="brown"
  82. context.fillRect(patX[ip], patY[ip], patSize, patSize)
  83. }
  84. for(ie=0; ie<broiEnemy; ie++) {
  85. context.fillStyle="blue"
  86. fillCircle(enemyX[ie], enemyY[ie], 10)
  87. context.fillStyle="black"
  88. context.fillRect(enemyX[ie]-1-15, enemyY[ie]-16, 32, 6)
  89. context.fillStyle="green"
  90. context.fillRect(enemyX[ie]-15, enemyY[ie]-15, healthEnemy[ie]/4, 5)
  91. }
  92. for(it=0; it<=broiTowers; it++) {
  93. context.globalAlpha=1
  94. context.fillStyle="green"
  95. fillCircle(towerX[it], towerY[it], 10)
  96. context.globalAlpha=0.1
  97. context.fillStyle="grey"
  98. fillCircle(towerX[it], towerY[it], 100)
  99. }
  100. };
  101.  
  102. function keyup(key) {
  103. // Show the pressed keycode in the console
  104. console.log("Pressed", key);
  105. };
  106.  
  107. function mouseup() {
  108. // Show coordinates of mouse on click
  109. console.log("Mouse clicked at", mouseX, mouseY);
  110. broiTowers++
  111. towerX[broiTowers]=mouseX
  112. towerY[broiTowers]=mouseY
  113. };
  114. function areCirclesColliding(x1, y1, r1, x2, y2, r2){
  115. let dist = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
  116. return dist<=r1+r2;
  117. }
  118. function fillCircle(x, y, r) {
  119. context.beginPath();
  120. context.arc(x, y, r, 0, 2*Math.PI);
  121. context.fill();
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement