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,v 1.1 2003/02/09 11:17:40 sam Exp $ |
---|
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 | |
---|
27 | box * create_box( game *g, int x, int y, int w, int h ) |
---|
28 | { |
---|
29 | box *b = malloc( sizeof( box ) ); |
---|
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 | |
---|
40 | void draw_box( game *g, box *b ) |
---|
41 | { |
---|
42 | int i, j, frame; |
---|
43 | |
---|
44 | gfx_color( YELLOW ); |
---|
45 | |
---|
46 | /* Draw the thin horizontal line */ |
---|
47 | if( b->frame < 8 ) |
---|
48 | { |
---|
49 | for( i = b->x - b->w * b->frame / 16 ; |
---|
50 | i < b->x + b->w * b->frame / 16 ; |
---|
51 | i++ ) |
---|
52 | { |
---|
53 | gfx_goto( i, b->y ); |
---|
54 | gfx_putchar( 'X' ); |
---|
55 | } |
---|
56 | |
---|
57 | return; |
---|
58 | } |
---|
59 | |
---|
60 | /* Draw the frame */ |
---|
61 | frame = b->frame < 12 ? b->frame : 12; |
---|
62 | |
---|
63 | for( i = b->x - b->w / 2 ; |
---|
64 | i < b->x + b->w / 2 ; |
---|
65 | i++ ) |
---|
66 | { |
---|
67 | gfx_goto( i, b->y - b->h * (frame - 8) / 8 ); |
---|
68 | gfx_putchar( 'X' ); |
---|
69 | gfx_goto( i, b->y + b->h * (frame - 8) / 8 ); |
---|
70 | gfx_putchar( 'X' ); |
---|
71 | } |
---|
72 | |
---|
73 | for( j = b->y - b->h * (frame - 8) / 8 ; |
---|
74 | j < b->y + b->h * (frame - 8) / 8 ; |
---|
75 | j++ ) |
---|
76 | { |
---|
77 | gfx_goto( b->x - b->w / 2, j ); |
---|
78 | gfx_putchar( 'X' ); |
---|
79 | gfx_goto( b->x + b->w / 2 - 1, j ); |
---|
80 | gfx_putchar( 'X' ); |
---|
81 | } |
---|
82 | |
---|
83 | gfx_color( BLACK ); |
---|
84 | |
---|
85 | for( j = b->y - b->h * (frame - 8) / 8 + 1 ; |
---|
86 | j < b->y + b->h * (frame - 8) / 8 ; |
---|
87 | j++ ) |
---|
88 | { |
---|
89 | for( i = b->x - b->w / 2 + 1 ; |
---|
90 | i < b->x + b->w / 2 - 1 ; |
---|
91 | i++ ) |
---|
92 | { |
---|
93 | gfx_goto( i, j ); |
---|
94 | gfx_putchar( 'X' ); |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | if( b->frame < 12 ) |
---|
99 | { |
---|
100 | return; |
---|
101 | } |
---|
102 | |
---|
103 | /* Draw the text inside the frame */ |
---|
104 | gfx_color( YELLOW ); |
---|
105 | |
---|
106 | /* FIXME: use a font */ |
---|
107 | gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 2 ); |
---|
108 | gfx_putstr( "XXXX. .XXXX X X .XXXX .XXXX XXXX." ); |
---|
109 | gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 3 ); |
---|
110 | gfx_putstr( "X `X X' X X X X' X' X `X" ); |
---|
111 | gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 4 ); |
---|
112 | gfx_putstr( "XXXX' XXXXX X X `XXX XXXX X X" ); |
---|
113 | gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 5 ); |
---|
114 | gfx_putstr( "X' X' `X X. ,X `X X' X ,X" ); |
---|
115 | gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 6 ); |
---|
116 | gfx_putstr( "X X X `XXXX XXXX' `XXXX XXXX'" ); |
---|
117 | } |
---|
118 | |
---|
119 | void free_box( box *b ) |
---|
120 | { |
---|
121 | free( b ); |
---|
122 | } |
---|
123 | |
---|