source: libcaca/trunk/src/box.c @ 147

Last change on this file since 147 was 147, checked in by Sam Hocevar, 20 years ago
  • libee/graphics.c: + Moved ee_putstr() and ee_putchar() in here.
  • libee/ee.h: + Got rid of ee_goto(). + Moved <slang.h> or <curses.h> into libee.
  • Replaced ee_goto()/ee_putstr() pairs with ee_putstr().
  • Ditto for ee_putchar().
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/*
2 *   ttyvaders     Textmode shoot'em up
3 *   Copyright (c) 2002-2003 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
6 *   $Id: box.c 147 2003-11-10 23:38:50Z 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
29box * create_box(game *g, int x, int y, int w, int h)
30{
31    box *b = malloc(sizeof( box ));
32
33    b->x = x;
34    b->y = y;
35    b->w = w;
36    b->h = h;
37    b->frame = 0;
38
39    return b;
40}
41
42void draw_box(game *g, box *b)
43{
44    int j, frame;
45
46    ee_color(EE_YELLOW);
47
48    /* Draw the thin horizontal line */
49    if(b->frame < 8)
50    {
51        ee_draw_line(b->x - b->w * b->frame / 16, b->y,
52                     b->x + b->w * b->frame / 16 - 1, b->y, 'X');
53        return;
54    }
55
56    /* Draw the frame */
57    frame = b->frame < 12 ? b->frame : 12;
58
59    ee_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
60                 b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8, 'X');
61    ee_draw_line(b->x - b->w / 2, b->y + b->h * (frame - 8) / 8,
62                 b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8, 'X');
63
64    ee_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
65                 b->x - b->w / 2, b->y + b->h * (frame - 8) / 8 - 1, 'X');
66    ee_draw_line(b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8,
67                 b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8 - 1, 'X');
68
69    ee_color(EE_BLACK);
70
71    for(j = b->y - b->h * (frame - 8) / 8 + 1;
72         j < b->y + b->h * (frame - 8) / 8;
73         j++)
74    {
75        ee_draw_line(b->x - b->w / 2 + 1, j,
76                     b->x + b->w / 2 - 2, j, 'X');
77    }
78
79    if(b->frame < 12)
80    {
81        return;
82    }
83
84    /* Draw the text inside the frame */
85    ee_color(EE_YELLOW);
86
87    /* FIXME: use a font */
88    ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2,
89              "XXXX.  .XXXX  X   X  .XXXX  .XXXX  XXXX.");
90    ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3,
91              "X  `X  X'  X  X   X  X'     X'     X  `X");
92    ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4,
93              "XXXX'  XXXXX  X   X  `XXX   XXXX   X   X");
94    ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5,
95              "X'     X' `X  X. ,X     `X  X'     X  ,X");
96    ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6,
97              "X      X   X  `XXXX  XXXX'  `XXXX  XXXX'");
98}
99
100void free_box(box *b)
101{
102    free(b);
103}
104
Note: See TracBrowser for help on using the repository browser.