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.

starfield.c 1.1 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <stdlib.h>
  2. #include "common.h"
  3. void init_starfield( game *g, starfield *s )
  4. {
  5. int i;
  6. for( i = 0; i < STARS; i++ )
  7. {
  8. s->x[i] = rand() % g->w;
  9. s->y[i] = rand() % g->h;
  10. s->z[i] = 1 + rand() % 3;
  11. s->ch[i] = (rand() % 2) ? '.' : '\'';
  12. s->c[i] = 6 + rand() % 2;
  13. }
  14. }
  15. void draw_starfield( game *g, starfield *s )
  16. {
  17. int i;
  18. for( i = 0; i < STARS; i++ )
  19. {
  20. if( s->x[i] >= 0 )
  21. {
  22. GFX_COLOR( s->c[i] );
  23. GFX_GOTO( s->x[i], s->y[i] );
  24. GFX_WRITE( s->ch[i] );
  25. }
  26. }
  27. }
  28. void update_starfield( game *g, starfield *s )
  29. {
  30. int i;
  31. for( i = 0; i < STARS; i++ )
  32. {
  33. if( s->x[i] < 0 )
  34. {
  35. s->x[i] = rand() % g->w;
  36. s->y[i] = 0;
  37. s->z[i] = 1 + rand() % 2;
  38. s->ch[i] = (rand() % 2) ? '.' : '\'';
  39. s->c[i] = 6 + rand() % 2;
  40. }
  41. else if( s->y[i] < g->h-1 )
  42. {
  43. s->y[i] += s->z[i];
  44. }
  45. else
  46. {
  47. s->x[i] = -1;
  48. }
  49. }
  50. }