You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

86 rivejä
1.8 KiB

  1. /*
  2. * ttyvaders Textmode shoot'em up
  3. * Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software. It commes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #include "config.h"
  15. #include <stdlib.h>
  16. #include "common.h"
  17. starfield * create_starfield(game *g)
  18. {
  19. int i;
  20. starfield *s;
  21. s = malloc(STARS * sizeof(starfield));
  22. if(s == NULL)
  23. exit(1);
  24. for(i = 0; i < STARS; i++)
  25. {
  26. s[i].x = cucul_rand(0, g->w - 1);
  27. s[i].y = cucul_rand(0, g->h - 1);
  28. s[i].z = cucul_rand(1, 3);
  29. s[i].c = cucul_rand(0, 1) ? CUCUL_COLOR_LIGHTGRAY : CUCUL_COLOR_DARKGRAY;
  30. s[i].ch = cucul_rand(0, 1) ? '.' : '\'';
  31. }
  32. return s;
  33. }
  34. void draw_starfield(game *g, starfield *s)
  35. {
  36. int i;
  37. for(i = 0; i < STARS; i++)
  38. {
  39. if(s[i].x >= 0)
  40. {
  41. cucul_set_color(g->cv, s[i].c, CUCUL_COLOR_BLACK);
  42. cucul_putchar(g->cv, s[i].x, s[i].y, s[i].ch);
  43. }
  44. }
  45. }
  46. void update_starfield(game *g, starfield *s)
  47. {
  48. int i;
  49. for(i = 0; i < STARS; i++)
  50. {
  51. if(s[i].x < 0)
  52. {
  53. s[i].x = cucul_rand(0, g->w - 1);
  54. s[i].y = 0;
  55. s[i].z = cucul_rand(1, 2);
  56. s[i].c = cucul_rand(0, 1) ? CUCUL_COLOR_LIGHTGRAY : CUCUL_COLOR_DARKGRAY;
  57. s[i].ch = cucul_rand(0, 1) ? '.' : '\'';
  58. }
  59. else if(s[i].y < g->h-1)
  60. {
  61. s[i].y += s[i].z;
  62. }
  63. else
  64. {
  65. s[i].x = -1;
  66. }
  67. }
  68. }
  69. void free_starfield(game *g, starfield *s)
  70. {
  71. free(s);
  72. }