No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

92 líneas
2.0 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; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include "config.h"
  23. #include <stdlib.h>
  24. #include "common.h"
  25. starfield * create_starfield(game *g)
  26. {
  27. int i;
  28. starfield *s;
  29. s = malloc(STARS * sizeof(starfield));
  30. for(i = 0; i < STARS; i++)
  31. {
  32. s[i].x = ee_rand(0, g->w - 1);
  33. s[i].y = ee_rand(0, g->h - 1);
  34. s[i].z = ee_rand(1, 3);
  35. s[i].c = ee_rand(6, 7);
  36. s[i].ch = ee_rand(0, 1) ? '.' : '\'';
  37. }
  38. return s;
  39. }
  40. void draw_starfield(game *g, starfield *s)
  41. {
  42. int i;
  43. for(i = 0; i < STARS; i++)
  44. {
  45. if(s[i].x >= 0)
  46. {
  47. ee_set_color(s[i].c);
  48. ee_putchar(s[i].x, s[i].y, s[i].ch);
  49. }
  50. }
  51. }
  52. void update_starfield(game *g, starfield *s)
  53. {
  54. int i;
  55. for(i = 0; i < STARS; i++)
  56. {
  57. if(s[i].x < 0)
  58. {
  59. s[i].x = ee_rand(0, g->w - 1);
  60. s[i].y = 0;
  61. s[i].z = ee_rand(1, 2);
  62. s[i].c = ee_rand(6, 7);
  63. s[i].ch = ee_rand(0, 1) ? '.' : '\'';
  64. }
  65. else if(s[i].y < g->h-1)
  66. {
  67. s[i].y += s[i].z;
  68. }
  69. else
  70. {
  71. s[i].x = -1;
  72. }
  73. }
  74. }
  75. void free_starfield(game *g, starfield *s)
  76. {
  77. free(s);
  78. }