source: libcaca/trunk/src/starfield.c @ 153

Last change on this file since 153 was 153, checked in by Sam Hocevar, 20 years ago
  • libee/graphics.c: + Renamed ee_color() to ee_set_color(), wrote ee_get_color().
  • libee/line.c: + Implemented draw_polyline() and draw_thin_polyline().
  • libee/sprite.c: + Removed the f member of struct ee_sprite. + Implemented ee_get_sprite_{width|height|dx|dy}(). + Restore the color fater ee_draw_sprite() is called.
  • libee/box.c: + Fixed a bug causing improper box clipping at the right and the bottom.
  • data/foo_fighter: + Fixed bugs in the sprite.
  • src/intro.c: + Test effects for the future game's intro.
  • test/spritedit.c: + Added stuff to the sprite editor. We can now navigate through frames.
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
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 153 2003-11-12 01:48:58Z sam $
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
23#include "config.h"
24
25#include <stdlib.h>
26
27#include "common.h"
28
29starfield * create_starfield(game *g)
30{
31    int i;
32    starfield *s;
33
34    s = malloc(STARS * sizeof(starfield));
35
36    for(i = 0; i < STARS; i++)
37    {
38        s[i].x = ee_rand(0, g->w - 1);
39        s[i].y = ee_rand(0, g->h - 1);
40        s[i].z = ee_rand(1, 3);
41        s[i].c = ee_rand(6, 7);
42        s[i].ch = ee_rand(0, 1) ? '.' : '\'';
43    }
44
45    return s;
46}
47
48void draw_starfield(game *g, starfield *s)
49{
50    int i;
51
52    for(i = 0; i < STARS; i++)
53    {
54        if(s[i].x >= 0)
55        {
56            ee_set_color(s[i].c);
57            ee_putchar(s[i].x, s[i].y, s[i].ch);
58        }
59    }
60}
61
62void update_starfield(game *g, starfield *s)
63{
64    int i;
65
66    for(i = 0; i < STARS; i++)
67    {
68        if(s[i].x < 0)
69        {
70            s[i].x = ee_rand(0, g->w - 1);
71            s[i].y = 0;
72            s[i].z = ee_rand(1, 2);
73            s[i].c = ee_rand(6, 7);
74            s[i].ch = ee_rand(0, 1) ? '.' : '\'';
75        }
76        else if(s[i].y < g->h-1)
77        {
78            s[i].y += s[i].z;
79        }
80        else
81        {
82            s[i].x = -1;
83        }
84    }
85}
86
87void free_starfield(game *g, starfield *s)
88{
89    free(s);
90}
91
Note: See TracBrowser for help on using the repository browser.