Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

94 rader
2.1 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. if(s == NULL)
  31. exit(1);
  32. for(i = 0; i < STARS; i++)
  33. {
  34. s[i].x = caca_rand(0, g->w - 1);
  35. s[i].y = caca_rand(0, g->h - 1);
  36. s[i].z = caca_rand(1, 3);
  37. s[i].c = caca_rand(0, 1) ? EE_LIGHTGRAY : EE_DARKGRAY;
  38. s[i].ch = caca_rand(0, 1) ? '.' : '\'';
  39. }
  40. return s;
  41. }
  42. void draw_starfield(game *g, starfield *s)
  43. {
  44. int i;
  45. for(i = 0; i < STARS; i++)
  46. {
  47. if(s[i].x >= 0)
  48. {
  49. caca_set_color(s[i].c);
  50. caca_putchar(s[i].x, s[i].y, s[i].ch);
  51. }
  52. }
  53. }
  54. void update_starfield(game *g, starfield *s)
  55. {
  56. int i;
  57. for(i = 0; i < STARS; i++)
  58. {
  59. if(s[i].x < 0)
  60. {
  61. s[i].x = caca_rand(0, g->w - 1);
  62. s[i].y = 0;
  63. s[i].z = caca_rand(1, 2);
  64. s[i].c = caca_rand(0, 1) ? EE_LIGHTGRAY : EE_DARKGRAY;
  65. s[i].ch = caca_rand(0, 1) ? '.' : '\'';
  66. }
  67. else if(s[i].y < g->h-1)
  68. {
  69. s[i].y += s[i].z;
  70. }
  71. else
  72. {
  73. s[i].x = -1;
  74. }
  75. }
  76. }
  77. void free_starfield(game *g, starfield *s)
  78. {
  79. free(s);
  80. }