Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1.  
  2.  
  3. function coord(x, y) {
  4. this.x = x;
  5. this.y = y;
  6. }
  7.  
  8. function attack(ap, as) {
  9. this.ap = ap;
  10. this.as = as;
  11. }
  12.  
  13. function unit(name, coord, size, hp, attack, range) {
  14. this.name = name;
  15. this.coord = coord;
  16. this.size = size;
  17. this.hp = hp;
  18. this.attack = attack;
  19. this.range = range;
  20. }
  21.  
  22. function ennemy(name, coord, hp, attack, range, speed) {
  23. this.name = name;
  24. this.coord = coord;
  25. this.hp = hp;
  26. this.attack = attack;
  27. this.range = range;
  28. this.speed = speed;
  29. }
  30.  
  31. function map(size, unit, ennemy, coins, score, time) {
  32. this.size = size;
  33. this.units = unit;
  34. this.ennemys = ennemy;
  35. this.coins = coins;
  36. this.score = score;
  37. this.time = time;
  38. }
  39.  
  40. //Faits avancer les ennemis sur la route
  41. function ennemy_forward(ennemy) {
  42. ennemy.coord.y = ennemy.coord.y + ennemy.speed;
  43. return ennemy;
  44. }
  45.  
  46. //Gere une attaque entre un attaquent et un attaqué qui est appellé toute les "as" secondes
  47. function attack_deal(attaquant, defenseur) {
  48. defenseur.hp = defenseur.hp - attaquant.attack.ap;
  49. }
  50.  
  51. //fonction boolenne qui repere si un ennemi est a porté sur la map
  52. function test_range(map, unit) {
  53. for (var k = 0 ; k < map.units.length ; ++k) {
  54. if ((unit.coord.x > map.units[k].coord.x // en haut a droite
  55. && unit.coord.y > map.units[k].coord.y
  56. && unit.coord.x - map.units[k].coord.x <= unit.range
  57. && unit.coord.y - map.units[k].coord.y <= unit.range)
  58.  
  59. || (unit.coord.x > map.units[k].coord.x // en bas a droite
  60. && unit.coord.y < map.units[k].coord.y
  61. && unit.coord.x - map.units[k].coord.x <= unit.range
  62. && - unit.coord.y - map.units[k].coord.y <= unit.range)
  63.  
  64. || (unit.coord.x < map.units[k].coord.x // en bas a gauche
  65. && unit.coord.y < map.units[k].coord.y
  66. && - unit.coord.x - map.units[k].coord.x <= unit.range
  67. && - unit.coord.y - map.units[k].coord.y <= unit.range)
  68.  
  69. || (unit.coord.x < map.units[k].coord.x // en haut a gauche
  70. && unit.coord.y > map.units[k].coord.y
  71. && - unit.coord.x - map.units[k].coord.x <= unit.range
  72. && unit.coord.x - map.units[k].coord.x <= unit.range)) {
  73. return true;
  74. } else {
  75. return false;
  76. }
  77. }
  78. }
  79.  
  80. //fonction qui gère l'apparition d'ennemi
  81. function ennemy_spawn(map) {
  82. rand = Math.floor((Math.random() * 3) + 1);
  83. if (rand == 1) {
  84. map.ennemys[map.ennemys.length] = new ennemy(new coord(0,250), 400, new attack(500,2), 20, 20);
  85. }
  86. if (rand == 2) {
  87. map.ennemys[map.ennemys.length] = new ennemy(new coord(0,250), 500, new attack(500,2), 5, 10);
  88. }
  89. else {
  90. map.ennemys[map.ennemys.length] = new ennemy(new coord(0,250), 200, new attack(500,2), 100, 15);
  91. }
  92. }
  93.  
  94. //fonction qui renvoie 0 si auncune condition remplie, 1 si victoire, -1 si défaite
  95. //~ function win_condition (map) {
  96. //~ if () == 0) {
  97. //~ return 1;
  98. //~ }
  99. //~ if (map.units[0].hp <= 0) {
  100. //~ return -1;
  101. //~ }
  102. //~ return 0;
  103. //~ }
  104.  
  105. //~ var tour1 = new unit (new coord(100,100), 500, 500, 200);
  106. //~ var archer1 = new ennemy(new coord(-120,120), 500, new attack(500,2), 20, 10);
  107. var map1 = new map (500, [], [], 500, 500, 0);
  108. ennemy_spawn(map1);
  109. alert(map.ennemys[0].hp);
  110. //window.onload = function() {
  111. //var canvas = document.getElementById('mon_canvas');
  112. //if (!canvas) {
  113. //alert("Erreur canvas");
  114. //return;
  115. //}
  116. //var context = canvas.getContext('2d');
  117. //if (!context) {
  118. //alert("Erreur context canvas");
  119. //return;
  120. //}
  121. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement