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.
 
 
 
 
 
 

81 lines
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: starfield.c,v 1.4 2002/12/22 18:44:12 sam Exp $
  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 <stdlib.h>
  23. #include "common.h"
  24. void init_starfield( game *g, starfield *s )
  25. {
  26. int i;
  27. for( i = 0; i < STARS; i++ )
  28. {
  29. s->x[i] = rand() % g->w;
  30. s->y[i] = rand() % g->h;
  31. s->z[i] = 1 + rand() % 3;
  32. s->ch[i] = (rand() % 2) ? '.' : '\'';
  33. s->c[i] = 6 + rand() % 2;
  34. }
  35. }
  36. void draw_starfield( game *g, starfield *s )
  37. {
  38. int i;
  39. for( i = 0; i < STARS; i++ )
  40. {
  41. if( s->x[i] >= 0 )
  42. {
  43. gfx_color( s->c[i] );
  44. gfx_goto( s->x[i], s->y[i] );
  45. gfx_putchar( s->ch[i] );
  46. }
  47. }
  48. }
  49. void update_starfield( game *g, starfield *s )
  50. {
  51. int i;
  52. for( i = 0; i < STARS; i++ )
  53. {
  54. if( s->x[i] < 0 )
  55. {
  56. s->x[i] = rand() % g->w;
  57. s->y[i] = 0;
  58. s->z[i] = 1 + rand() % 2;
  59. s->ch[i] = (rand() % 2) ? '.' : '\'';
  60. s->c[i] = 6 + rand() % 2;
  61. }
  62. else if( s->y[i] < g->h-1 )
  63. {
  64. s->y[i] += s->z[i];
  65. }
  66. else
  67. {
  68. s->x[i] = -1;
  69. }
  70. }
  71. }