PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/game/boss.c

https://github.com/acieroid/gish
C | 160 lines | 118 code | 22 blank | 20 comment | 25 complexity | 26206df7b2ea3e03958631b56fb17b3d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. /*
  2. Copyright (C) 2005, 2010 - Cryptic Sea
  3. This file is part of Gish.
  4. Gish is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "../config.h"
  17. #include <string.h>
  18. #include "../game/boss.h"
  19. #include "../game/animation.h"
  20. #include "../game/gameobject.h"
  21. #include "../game/render.h"
  22. #include "../math/vector.h"
  23. int numofbosses;
  24. _boss boss[16];
  25. void createboss(int type,float position[3])
  26. {
  27. memset(&boss[numofbosses],0,sizeof(boss[0]));
  28. boss[numofbosses].type=type;
  29. boss[numofbosses].timetolive=10000;
  30. copyvector(boss[numofbosses].position,position);
  31. boss[numofbosses].animationnum=14;
  32. boss[numofbosses].size[0]=3.0f;
  33. boss[numofbosses].size[1]=3.0f;
  34. numofbosses++;
  35. }
  36. void bosssimulation(void)
  37. {
  38. int count/*,count2*/;
  39. float vec[3];
  40. for (count=0;count<numofbosses;count++)
  41. {
  42. if (boss[count].timetolive>100)
  43. {
  44. subtractvectors(vec,object[0].position,boss[count].position);
  45. if (boss[count].animationtype!=2)
  46. if (vectorlength(vec)<3.0f)
  47. {
  48. boss[count].animationtype=2;
  49. boss[count].frame=0;
  50. boss[count].framedelay=0.0f;
  51. }
  52. if (boss[count].animationtype==2)
  53. if (vectorlength(vec)>=3.0f)
  54. {
  55. boss[count].animationtype=1;
  56. boss[count].frame=0;
  57. boss[count].framedelay=0.0f;
  58. }
  59. if (vectorlength(vec)>2.5f)
  60. scaleaddvectors(boss[count].velocity,boss[count].velocity,vec,0.003f);
  61. scalevector(boss[count].velocity,boss[count].velocity,0.75f);
  62. addvectors(boss[count].position,boss[count].position,boss[count].velocity);
  63. if (boss[count].animationtype!=2)
  64. {
  65. boss[count].framedelay+=0.1f;
  66. if (boss[count].framedelay>=1.0f)
  67. {
  68. boss[count].framedelay=0.0f;
  69. boss[count].frame++;
  70. if (boss[count].frame>=animation[boss[count].animationnum].walk[1])
  71. boss[count].frame=0;
  72. }
  73. boss[count].texturenum=animation[boss[count].animationnum].walk[0]+boss[count].frame;
  74. }
  75. else
  76. {
  77. boss[count].framedelay+=0.15f;
  78. if (boss[count].framedelay>=1.0f)
  79. {
  80. boss[count].framedelay=0.0f;
  81. boss[count].frame++;
  82. if (boss[count].frame>=animation[boss[count].animationnum].attack[1])
  83. boss[count].frame=0;
  84. }
  85. boss[count].texturenum=animation[boss[count].animationnum].attack[0]+boss[count].frame;
  86. if (boss[count].frame==3)
  87. object[0].hitpoints-=10;
  88. }
  89. if (boss[count].velocity[0]>0.0f)
  90. boss[count].direction=0;
  91. else
  92. boss[count].direction=1;
  93. if (frame.numoflights>1)
  94. if (boss[count].timetolive>150)
  95. boss[count].timetolive=150;
  96. }
  97. if (boss[count].timetolive<45)
  98. {
  99. boss[count].animationtype=3;
  100. boss[count].frame=0;
  101. boss[count].framedelay=0.0f;
  102. boss[count].texturenum=animation[boss[count].animationnum].die[0]+8-boss[count].timetolive/5;
  103. }
  104. }
  105. }
  106. void bosstimetolive(void)
  107. {
  108. int count;
  109. count=0;
  110. while (count<numofbosses)
  111. {
  112. if (boss[count].timetolive<10000)
  113. boss[count].timetolive--;
  114. while (count<numofbosses && boss[count].timetolive<0)
  115. {
  116. deleteboss(count);
  117. if (boss[count].timetolive<10000)
  118. boss[count].timetolive--;
  119. }
  120. count++;
  121. }
  122. }
  123. void deleteboss(int bossnum)
  124. {
  125. if (bossnum<0)
  126. return;
  127. if (bossnum>=numofbosses)
  128. return;
  129. numofbosses--;
  130. if (bossnum==numofbosses)
  131. return;
  132. memcpy(&boss[bossnum],&boss[numofbosses],sizeof(boss[0]));
  133. }