[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 1057 2006-09-18 16:54:08Z 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] | 29 | box * 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] | 44 | void draw_box(game *g, box *b) |
---|
[70] | 45 | { |
---|
[122] | 46 | int j, frame; |
---|
[70] | 47 | |
---|
[1057] | 48 | cucul_set_color(g->cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); |
---|
[70] | 49 | |
---|
| 50 | /* Draw the thin horizontal line */ |
---|
[88] | 51 | if(b->frame < 8) |
---|
[70] | 52 | { |
---|
[1057] | 53 | cucul_draw_line(g->cv, b->x - b->w * b->frame / 16, b->y, |
---|
| 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 | |
---|
[1057] | 61 | cucul_draw_line(g->cv, 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 | cucul_draw_line(g->cv, b->x - b->w / 2, b->y + b->h * (frame - 8) / 8, |
---|
| 64 | b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8, "X"); |
---|
[70] | 65 | |
---|
[1057] | 66 | cucul_draw_line(g->cv, b->x - b->w / 2, b->y - b->h * (frame - 8) / 8, |
---|
| 67 | b->x - b->w / 2, b->y + b->h * (frame - 8) / 8 - 1, "X"); |
---|
| 68 | cucul_draw_line(g->cv, b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8, |
---|
| 69 | b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8 - 1, "X"); |
---|
[70] | 70 | |
---|
[1057] | 71 | cucul_set_color(g->cv, CUCUL_COLOR_BLACK, CUCUL_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 | { |
---|
[1057] | 77 | cucul_draw_line(g->cv, b->x - b->w / 2 + 1, j, |
---|
| 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 */ |
---|
[1057] | 87 | cucul_set_color(g->cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); |
---|
[70] | 88 | |
---|
| 89 | /* FIXME: use a font */ |
---|
[1057] | 90 | cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 2, |
---|
[544] | 91 | "XXXX. .XXXX X X .XXXX .XXXX XXXX."); |
---|
[1057] | 92 | cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 3, |
---|
[544] | 93 | "X `X X' X X X X' X' X `X"); |
---|
[1057] | 94 | cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 4, |
---|
[544] | 95 | "XXXX' XXXXX X X `XXX XXXX X X"); |
---|
[1057] | 96 | cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 5, |
---|
[544] | 97 | "X' X' `X X. ,X `X X' X ,X"); |
---|
[1057] | 98 | cucul_putstr(g->cv, b->x - b->w / 2 + 12, b->y - b->h / 2 + 6, |
---|
[544] | 99 | "X X X `XXXX XXXX' `XXXX XXXX'"); |
---|
[70] | 100 | } |
---|
| 101 | |
---|
[88] | 102 | void free_box(box *b) |
---|
[70] | 103 | { |
---|
[88] | 104 | free(b); |
---|
[70] | 105 | } |
---|
| 106 | |
---|