Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » advice on creating textmode like interface

This thread is locked; no one can reply to it. rss feed Print
advice on creating textmode like interface
Nuklear Zelph
Member #8,205
January 2007

My goal is to create a game very similar to BEAST by Dan Baker. if you'd like me to send you a copy, let me know. it can be freely distributed. the game can be slowed down using its settings on my 1 GHZ machine to where one can actually see what is going on kinda, but it is unplayable. i also want to mess around with allegro and this gives me a good excuse.

i was thinking of making a set of 2d arrays that would deal with the textmode like interface. one would hold blit coordinates, the other, what goes where on screen. then on timeout or user input the screen refreshes to what is in the 2d array. i want to make it more flexible eventually to take advantage of the graphical environment, but it should play like BEAST does.

is this a good way to go about it, or should i try another route?

Nuklear

Audric
Member #907
January 2001

You mean, you'll be using an array/list/vector of { int x, int y, int what_to_draw }, even for walls?

A more classic method would be a 2D array for the playfield, each cell containing an enumerated value for what is there (wall, player, beast, etc).

Additionally, you'll use a list/array/vector of creatures: this will be more handy when you need to update each beast once (without scanning the whole board)

DanielH
Member #934
January 2001
avatar

This is what I used in my Castle Adventure Game. You can download the source and check it out.

Instead of redrawing a buffer everytime, I just redrew the character at that location with a text_mode of 0.

However, there was only one color.

1//castle.h
2#define GRID_WIDTH 40
3#define GRID_HEIGHT 25
4#define GRID_TOTAL 1000 // 40 x 25
5 
6unsigned char sbuffer[ GRID_TOTAL ];
7 
8//crt.cpp
9static int ofx = 0;
10static int ofy = 0;
11static FONT *bfont = NULL;
12 
13void setup_crt( FONT *_font )
14{
15 bfont = _font;
16 ofx = ofy = text_height( bfont );
17}
18 
19void clrscr()
20{
21 cursor = 0;
22 
23 clear_bitmap( screen );
24 
25 for ( int i = 0; i < GRID_TOTAL; i++ )
26 {
27 sbuffer[ i ] = 0;
28 }
29}
30 
31unsigned char read( int x, int y )
32{
33 return sbuffer[ x + ( y * GRID_WIDTH ) ];
34}
35 
36void gotoXY( int x, int y )
37{
38 cursor = x + ( y * GRID_WIDTH );
39}
40 
41int whereX()
42{
43 return cursor % GRID_WIDTH;
44}
45 
46int whereY()
47{
48 return cursor / GRID_WIDTH;
49}
50 
51 
52void write( unsigned char c )
53{
54 static unsigned char t[ 2 ] = { 0, 0 };
55 static char t2[ 8 ];
56 static char *buf;
57 
58 buf = t2;
59 
60 if ( c == '~' )
61 {
62 c = ' ';
63 }
64
65 if ( c == '\n' )
66 {
67 if ( cursor % GRID_WIDTH == 0 )
68 {
69 cursor += GRID_WIDTH;
70 }
71 else
72 {
73 cursor += ( GRID_WIDTH - ( cursor % GRID_WIDTH ) );
74 }
75 }
76 else
77 {
78 if ( c != sbuffer[ cursor ] )
79 {
80 if ( c == 255 )
81 {
82 c = ' ';
83 }
84 t[ 0 ] = c;
85 
86 if ( need_uconvert( (char*)t, U_ASCII, U_CURRENT ) )
87 {
88 uconvert( (char*)t, U_ASCII, buf, U_CURRENT, sizeof( buf ) );
89 }
90 else
91 {
92 buf = (char*)t;
93 }
94 
95 textout( screen,
96 bfont,
97 buf,
98 ( cursor % GRID_WIDTH ) * ofx,
99 ( cursor / GRID_WIDTH ) * ofy,
100 makecol( 255, 255, 255 ) );
101 }
102
103 sbuffer[ cursor++ ] = c;
104 }
105 
106 if ( cursor >= GRID_TOTAL )
107 {
108 cursor -= GRID_TOTAL;
109 }
110}
111 
112void write( unsigned char c, int x, int y )
113{
114 gotoXY( x, y );
115 write( c );
116}
117 
118// center either x or y or both
119void write( const char *c, int x, int y )
120{
121 if ( x == -1 )
122 {
123 x = ( GRID_WIDTH - (int)strlen( c ) ) / 2;
124 }
125 
126 if ( y == -1 )
127 {
128 y = GRID_HEIGHT / 2;
129 }
130 
131 gotoXY( x, y );
132 write( c );
133}
134 
135void write( const char *c )
136{
137 for ( const char *b = c; *b != '\0'; b++ )
138 {
139 write( *(unsigned char *)b );
140 }
141}

Go to: