source: ttyvaders/trunk/src/box.c @ 88

Last change on this file since 88 was 88, checked in by Sam Hocevar, 17 years ago
  • Coding style everywhere.
  • Property svn:keywords set to Id
File size: 3.0 KB
RevLine 
[70]1/*
2 *   ttyvaders     Textmode shoot'em up
3 *   Copyright (c) 2002-2003 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
[80]6 *   $Id: box.c 88 2003-11-09 13:16:19Z sam $
[70]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 <stdlib.h>
24
25#include "common.h"
26
[88]27box * create_box(game *g, int x, int y, int w, int h)
[70]28{
[88]29    box *b = malloc(sizeof( box ));
[70]30
31    b->x = x;
32    b->y = y;
33    b->w = w;
34    b->h = h;
35    b->frame = 0;
36
37    return b;
38}
39
[88]40void draw_box(game *g, box *b)
[70]41{
42    int i, j, frame;
43
[88]44    ee_color(EE_YELLOW);
[70]45
46    /* Draw the thin horizontal line */
[88]47    if(b->frame < 8)
[70]48    {
[88]49        for(i = b->x - b->w * b->frame / 16 ;
[70]50             i < b->x + b->w * b->frame / 16 ;
[88]51             i++)
[70]52        {
[88]53            ee_goto(i, b->y);
54            ee_putchar('X');
[70]55        }
56
57        return;
58    }
59
60    /* Draw the frame */
61    frame = b->frame < 12 ? b->frame : 12;
62
[88]63    for(i = b->x - b->w / 2 ;
[70]64         i < b->x + b->w / 2 ;
[88]65         i++)
[70]66    {
[88]67        ee_goto(i, b->y - b->h * (frame - 8) / 8);
68        ee_putchar('X');
69        ee_goto(i, b->y + b->h * (frame - 8) / 8);
70        ee_putchar('X');
[70]71    }
72
[88]73    for(j = b->y - b->h * (frame - 8) / 8 ;
[70]74         j < b->y + b->h * (frame - 8) / 8 ;
[88]75         j++)
[70]76    {
[88]77        ee_goto(b->x - b->w / 2, j);
78        ee_putchar('X');
79        ee_goto(b->x + b->w / 2 - 1, j);
80        ee_putchar('X');
[70]81    }
82
[88]83    ee_color(EE_BLACK);
[70]84
[88]85    for(j = b->y - b->h * (frame - 8) / 8 + 1 ;
[70]86         j < b->y + b->h * (frame - 8) / 8 ;
[88]87         j++)
[70]88    {
[88]89        for(i = b->x - b->w / 2 + 1 ;
[70]90             i < b->x + b->w / 2 - 1 ;
[88]91             i++)
[70]92        {
[88]93            ee_goto(i, j);
94            ee_putchar('X');
[70]95        }
96    }
97
[88]98    if(b->frame < 12)
[70]99    {
100        return;
101    }
102
103    /* Draw the text inside the frame */
[88]104    ee_color(EE_YELLOW);
[70]105
106    /* FIXME: use a font */
[88]107    ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2);
108    ee_putstr("XXXX.  .XXXX  X   X  .XXXX  .XXXX  XXXX.");
109    ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3);
110    ee_putstr("X  `X  X'  X  X   X  X'     X'     X  `X");
111    ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4);
112    ee_putstr("XXXX'  XXXXX  X   X  `XXX   XXXX   X   X");
113    ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5);
114    ee_putstr("X'     X' `X  X. ,X     `X  X'     X  ,X");
115    ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6);
116    ee_putstr("X      X   X  `XXXX  XXXX'  `XXXX  XXXX'");
[70]117}
118
[88]119void free_box(box *b)
[70]120{
[88]121    free(b);
[70]122}
123
Note: See TracBrowser for help on using the repository browser.