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

Last change on this file since 194 was 194, checked in by Sam Hocevar, 16 years ago
  • BUGS TODO: + Removed libcaca stuff.
  • data/bongem.txt: + Fixed sprite syntax.
  • src/: + Set framerate to 25fps instead of 10fps. + Updated code to latest libcaca changes.
  • Property svn:keywords set to Id
File size: 3.1 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 194 2003-11-16 15:31:14Z 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
[110]23#include "config.h"
24
[70]25#include <stdlib.h>
26
27#include "common.h"
28
[88]29box * create_box(game *g, int x, int y, int w, int h)
[70]30{
[166]31    box *b = malloc(sizeof(box));
[174]32    if(b == NULL)
33        exit(1);
[70]34
35    b->x = x;
36    b->y = y;
37    b->w = w;
38    b->h = h;
39    b->frame = 0;
40
41    return b;
42}
43
[88]44void draw_box(game *g, box *b)
[70]45{
[122]46    int j, frame;
[70]47
[194]48    caca_set_color(CACA_COLOR_YELLOW);
[70]49
50    /* Draw the thin horizontal line */
[88]51    if(b->frame < 8)
[70]52    {
[186]53        caca_draw_line(b->x - b->w * b->frame / 16, b->y,
[122]54                     b->x + b->w * b->frame / 16 - 1, b->y, 'X');
[70]55        return;
56    }
57
58    /* Draw the frame */
59    frame = b->frame < 12 ? b->frame : 12;
60
[186]61    caca_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
[122]62                 b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8, 'X');
[186]63    caca_draw_line(b->x - b->w / 2, b->y + b->h * (frame - 8) / 8,
[122]64                 b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8, 'X');
[70]65
[186]66    caca_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
[122]67                 b->x - b->w / 2, b->y + b->h * (frame - 8) / 8 - 1, 'X');
[186]68    caca_draw_line(b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8,
[122]69                 b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8 - 1, 'X');
[70]70
[194]71    caca_set_color(CACA_COLOR_BLACK);
[70]72
[122]73    for(j = b->y - b->h * (frame - 8) / 8 + 1;
74         j < b->y + b->h * (frame - 8) / 8;
[88]75         j++)
[70]76    {
[186]77        caca_draw_line(b->x - b->w / 2 + 1, j,
[122]78                     b->x + b->w / 2 - 2, j, 'X');
[70]79    }
80
[88]81    if(b->frame < 12)
[70]82    {
83        return;
84    }
85
86    /* Draw the text inside the frame */
[194]87    caca_set_color(CACA_COLOR_YELLOW);
[70]88
89    /* FIXME: use a font */
[186]90    caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2,
[148]91              "XXXX.  .XXXX  X   X  .XXXX  .XXXX  XXXX.");
[186]92    caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3,
[148]93              "X  `X  X'  X  X   X  X'     X'     X  `X");
[186]94    caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4,
[148]95              "XXXX'  XXXXX  X   X  `XXX   XXXX   X   X");
[186]96    caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5,
[148]97              "X'     X' `X  X. ,X     `X  X'     X  ,X");
[186]98    caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6,
[148]99              "X      X   X  `XXXX  XXXX'  `XXXX  XXXX'");
[70]100}
101
[88]102void free_box(box *b)
[70]103{
[88]104    free(b);
[70]105}
106
Note: See TracBrowser for help on using the repository browser.