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

Last change on this file since 2990 was 2990, checked in by Sam Hocevar, 12 years ago

Port ttyvaders to the unified libcaca 0.99.beta15 API.

  • Property svn:keywords set to Id
File size: 2.4 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 2990 2008-10-18 21:42:24Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16
17#include <stdlib.h>
18#include <math.h>
19#include <unistd.h>
20
21#include "common.h"
22
23void intro(game *g)
24{
25    caca_event_t ev;
26    caca_canvas_t *foo_sprite;
27    caca_canvas_t *bar_sprite;
28    caca_canvas_t *baz_sprite;
29    caca_buffer_t *b;
30    int frame = 0;
31
32    b = caca_load_file("data/foofight.caca");
33    foo_sprite = caca_import_canvas(b, "");
34    caca_free_buffer(b);
35
36    b = caca_load_file("data/barfight.caca");
37    bar_sprite = caca_import_canvas(b, "");
38    caca_free_buffer(b);
39
40    b = caca_load_file("data/bazfight.caca");
41    baz_sprite = caca_import_canvas(b, "");
42    caca_free_buffer(b);
43
44    while(caca_get_event(g->dp, CACA_EVENT_KEY_PRESS, &ev, 0) == 0)
45    {
46        int i, xo, yo, x[5], y[5];
47
48        frame++;
49
50        caca_clear_canvas(g->cv);
51
52        xo = caca_get_canvas_width(g->cv) / 2;
53        yo = caca_get_canvas_height(g->cv) / 2;
54
55        caca_set_color(g->cv, CACA_COLOR_RED, CACA_COLOR_BLACK);
56        caca_fill_ellipse(g->cv, xo, yo, 16, 8, "#");
57        caca_set_color(g->cv, CACA_COLOR_GREEN, CACA_COLOR_BLACK);
58        caca_draw_thin_ellipse(g->cv, xo, yo, 16, 8);
59
60        for(i = 0; i < 4; i ++)
61        {
62            x[i] = xo + 0.5 + 12 * cos(0.05 * frame + i * M_PI / 2);
63            y[i] = yo + 0.5 + 6 * sin(0.05 * frame + i * M_PI / 2);
64        }
65        x[4] = x[0];
66        y[4] = y[0];
67
68        caca_set_color(g->cv, CACA_COLOR_BLACK, CACA_COLOR_BLACK);
69        caca_fill_triangle(g->cv, x[0], y[0], x[1], y[1], x[2], y[2], " ");
70        caca_fill_triangle(g->cv, x[0], y[0], x[3], y[3], x[2], y[2], " ");
71        caca_draw_line(g->cv, x[0], y[0], x[2], y[2], " ");
72        caca_set_color(g->cv, CACA_COLOR_GREEN, CACA_COLOR_BLACK);
73        caca_draw_thin_polyline(g->cv, x, y, 4);
74
75        caca_set_canvas_frame(foo_sprite, frame % 5);
76        caca_blit(g->cv, xo, yo, foo_sprite, NULL);
77
78        caca_refresh_display(g->dp);
79
80        usleep(40000);
81    }
82}
83
Note: See TracBrowser for help on using the repository browser.