alps.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "bevec.h"
  2. #include "eruta.h"
  3. #include "dynar.h"
  4. #include "rebox.h"
  5. #include "sprite.h"
  6. #include "area.h"
  7. #include "thing.h"
  8. #include "camera.h"
  9. #include "alps.h"
  10. #include <stdlib.h>
  11. /* Planned effects:
  12. * 1) Damage display. (Can be linked to the SpriteState also.)
  13. * 2) Weather: Rain, snow, hail. (each of these is exclusive)
  14. * 3) Sunlight: "American nights" (simple color filter over all) ,
  15. * komorebi (forest light), brightness (white over all).
  16. * 4) Slashes. (Could be linked to the SpriteState also).
  17. * 5) Spell effects: Star bursts
  18. *
  19. * 6) Aura colors to indicate forcefields, status effects, etc.
  20. * Definitely to be linked tho the spritestate. Probably doesn't belong in Alps.
  21. *
  22. *
  23. */
  24. AlpsDrop * alpsdrop_init(AlpsDrop *drop, Point p, Point v, double life) {
  25. drop->position = p;
  26. drop->velocity = v;
  27. drop->life = life;
  28. return drop;
  29. }
  30. int rand_betweeni(int low, int high) {
  31. return low + (rand() % (high - low));
  32. }
  33. double rand_betweend(double low, double high) {
  34. return low + (high - low) * ((double)rand() / (double) RAND_MAX);
  35. }
  36. Point rand_point(Point low, Point high) {
  37. double x, y;
  38. x = rand_betweend(low.x, high.x);
  39. y = rand_betweend(low.y, high.y);
  40. return bevec(x, y);
  41. }
  42. AlpsDrop * alpsdrop_initrandom(AlpsDrop *drop, Camera * camera) {
  43. Point p = rand_point(camera_at(camera), camera_br(camera));
  44. Point v = bevec(0.0, 80.0 + ((double)(rand() % 600)) / 10.0);
  45. Point pw = camera_screentoworld(camera, p);
  46. double life = 1.0 + ((double)(rand() % 50)) / 10.0;
  47. return alpsdrop_init(drop, pw, v, life);
  48. }
  49. /* Update an alpsdrop. This also takes the calera as a parameter, since
  50. for efficiency, and since they are not critical effects are generated
  51. only inside the camera view, at positions related to it. O,nvce they leave the
  52. camera view, the effects are disabled. */
  53. void alpsdrop_update(AlpsDrop *drop, Camera * camera, double dt) {
  54. Point screenp;
  55. drop->position = bevec_add(drop->position, bevec_mul(drop->velocity, dt));
  56. screenp = camera_worldtoscreen(camera, drop->position);
  57. drop->life -= dt;
  58. if (drop->life <= 0.0) {
  59. alpsdrop_initrandom(drop, camera);
  60. }
  61. }
  62. void alpsshower_init(AlpsShower * rain, Camera * camera, int intensity, float abberation,
  63. Point velocity) {
  64. int index;
  65. rain->camera = camera;
  66. rain->intensity = ((intensity < ALPS_SHOWER_DROPS) ?
  67. intensity : ALPS_SHOWER_DROPS);
  68. rain->abberation = abberation;
  69. rain->velocity = velocity;
  70. for (index = 0; index < rain->intensity; index ++) {
  71. alpsdrop_initrandom(rain->drops + index, camera);
  72. }
  73. }
  74. void alpsdrop_draw(AlpsDrop * drop, Camera * camera) {
  75. // al_put_pixel(drop->position.x, drop->position.y, al_map_rgb(128,128,255));
  76. /* al_draw_line(drop->position.x, drop->position.y - 5,
  77. drop->position.x, drop->position.y,
  78. al_map_rgb(128,128,255), 2);*/
  79. Point drawp = camera_worldtoscreen(camera, drop->position);
  80. al_draw_filled_ellipse(drawp.x, drawp.y,
  81. 1.5, 6.0, al_map_rgba(128,128,255,191));
  82. }
  83. /* XXX: camera is redundant. */
  84. void alpsshower_draw(AlpsShower * rain, Camera * camera) {
  85. int index;
  86. for (index = 0 ; index < rain->intensity ; index++) {
  87. alpsdrop_draw(rain->drops + index, rain->camera);
  88. }
  89. (void) camera;
  90. }
  91. void alpsshower_update(AlpsShower * rain, double dt) {
  92. int index;
  93. for (index = 0; index < rain->intensity; index ++) {
  94. alpsdrop_update(rain->drops + index, rain->camera, dt);
  95. }
  96. }