source: ttyvaders/trunk/src/intro.c @ 1057

Last change on this file since 1057 was 1057, checked in by Sam Hocevar, 14 years ago
  • Bring the tree back in sync with the new libcaca API.
  • Property svn:keywords set to Id
File size: 2.8 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: intro.c 1057 2006-09-18 16:54:08Z 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#include <math.h>
27#include <unistd.h>
28
29#include "common.h"
30
31void intro(game *g)
32{
33    caca_event_t ev;
34    cucul_canvas_t *foo_sprite;
35    cucul_canvas_t *bar_sprite;
36    cucul_canvas_t *baz_sprite;
37    cucul_buffer_t *b;
38    int frame = 0;
39
40    b = cucul_load_file("data/foofight.caca");
41    foo_sprite = cucul_import_canvas(b, "");
42    cucul_free_buffer(b);
43
44    b = cucul_load_file("data/barfight.caca");
45    bar_sprite = cucul_import_canvas(b, "");
46    cucul_free_buffer(b);
47
48    b = cucul_load_file("data/bazfight.caca");
49    baz_sprite = cucul_import_canvas(b, "");
50    cucul_free_buffer(b);
51
52    while(caca_get_event(g->dp, CACA_EVENT_KEY_PRESS, &ev, 0) == 0)
53    {
54        int i, xo, yo, x[5], y[5];
55
56        frame++;
57
58        cucul_clear_canvas(g->cv);
59
60        xo = cucul_get_canvas_width(g->cv) / 2;
61        yo = cucul_get_canvas_height(g->cv) / 2;
62
63        cucul_set_color(g->cv, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
64        cucul_fill_ellipse(g->cv, xo, yo, 16, 8, "#");
65        cucul_set_color(g->cv, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
66        cucul_draw_thin_ellipse(g->cv, xo, yo, 16, 8);
67
68        for(i = 0; i < 4; i ++)
69        {
70            x[i] = xo + 0.5 + 12 * cos(0.05 * frame + i * M_PI / 2);
71            y[i] = yo + 0.5 + 6 * sin(0.05 * frame + i * M_PI / 2);
72        }
73        x[4] = x[0];
74        y[4] = y[0];
75
76        cucul_set_color(g->cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
77        cucul_fill_triangle(g->cv, x[0], y[0], x[1], y[1], x[2], y[2], " ");
78        cucul_fill_triangle(g->cv, x[0], y[0], x[3], y[3], x[2], y[2], " ");
79        cucul_draw_line(g->cv, x[0], y[0], x[2], y[2], " ");
80        cucul_set_color(g->cv, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
81        cucul_draw_thin_polyline(g->cv, x, y, 4);
82
83        cucul_set_canvas_frame(foo_sprite, frame % 5);
84        cucul_blit(g->cv, xo, yo, foo_sprite, NULL);
85
86        caca_refresh_display(g->dp);
87
88        usleep(40000);
89    }
90}
91
Note: See TracBrowser for help on using the repository browser.