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

Last change on this file since 1460 was 1460, checked in by Sam Hocevar, 13 years ago
  • Bwarf, typo in the no warranty clause.
  • Property svn:keywords set to Id
File size: 2.9 KB
RevLine 
[70]1/*
[1456]2 *  ttyvaders     Textmode shoot'em up
3 *  Copyright (c) 2002-2003 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
[70]5 *
[1456]6 *  $Id: box.c 1460 2006-12-12 01:49:48Z sam $
[70]7 *
[1460]8 *  This program is free software. It comes without any warranty, to
[1456]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.
[70]13 */
14
[110]15#include "config.h"
16
[70]17#include <stdlib.h>
18
19#include "common.h"
20
[88]21box * create_box(game *g, int x, int y, int w, int h)
[70]22{
[166]23    box *b = malloc(sizeof(box));
[174]24    if(b == NULL)
25        exit(1);
[70]26
27    b->x = x;
28    b->y = y;
29    b->w = w;
30    b->h = h;
31    b->frame = 0;
32
33    return b;
34}
35
[88]36void draw_box(game *g, box *b)
[70]37{
[122]38    int j, frame;
[70]39
[1057]40    cucul_set_color(g->cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
[70]41
42    /* Draw the thin horizontal line */
[88]43    if(b->frame < 8)
[70]44    {
[1057]45        cucul_draw_line(g->cv, b->x - b->w * b->frame / 16, b->y,
46                               b->x + b->w * b->frame / 16 - 1, b->y, "X");
[70]47        return;
48    }
49
50    /* Draw the frame */
51    frame = b->frame < 12 ? b->frame : 12;
52
[1057]53    cucul_draw_line(g->cv, b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
54                    b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8, "X");
55    cucul_draw_line(g->cv, b->x - b->w / 2, b->y + b->h * (frame - 8) / 8,
56                    b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8, "X");
[70]57
[1057]58    cucul_draw_line(g->cv, b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
59                    b->x - b->w / 2, b->y + b->h * (frame - 8) / 8 - 1, "X");
60    cucul_draw_line(g->cv, b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8,
61               b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8 - 1, "X");
[70]62
[1057]63    cucul_set_color(g->cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
[70]64
[122]65    for(j = b->y - b->h * (frame - 8) / 8 + 1;
66         j < b->y + b->h * (frame - 8) / 8;
[88]67         j++)
[70]68    {
[1057]69        cucul_draw_line(g->cv, b->x - b->w / 2 + 1, j,
70                        b->x + b->w / 2 - 2, j, "X");
[70]71    }
72
[88]73    if(b->frame < 12)
[70]74    {
75        return;
76    }
77
78    /* Draw the text inside the frame */
[1057]79    cucul_set_color(g->cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
[70]80
81    /* FIXME: use a font */
[1057]82    cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 2,
[544]83                 "XXXX.  .XXXX  X   X  .XXXX  .XXXX  XXXX.");
[1057]84    cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 3,
[544]85                 "X  `X  X'  X  X   X  X'     X'     X  `X");
[1057]86    cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 4,
[544]87                 "XXXX'  XXXXX  X   X  `XXX   XXXX   X   X");
[1057]88    cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 5,
[544]89                 "X'     X' `X  X. ,X     `X  X'     X  ,X");
[1057]90    cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 6,
[544]91                 "X      X   X  `XXXX  XXXX'  `XXXX  XXXX'");
[70]92}
93
[88]94void free_box(box *b)
[70]95{
[88]96    free(b);
[70]97}
98
Note: See TracBrowser for help on using the repository browser.