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?
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)
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 | |
| 6 | unsigned char sbuffer[ GRID_TOTAL ]; |
| 7 | |
| 8 | //crt.cpp |
| 9 | static int ofx = 0; |
| 10 | static int ofy = 0; |
| 11 | static FONT *bfont = NULL; |
| 12 | |
| 13 | void setup_crt( FONT *_font ) |
| 14 | { |
| 15 | bfont = _font; |
| 16 | ofx = ofy = text_height( bfont ); |
| 17 | } |
| 18 | |
| 19 | void 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 | |
| 31 | unsigned char read( int x, int y ) |
| 32 | { |
| 33 | return sbuffer[ x + ( y * GRID_WIDTH ) ]; |
| 34 | } |
| 35 | |
| 36 | void gotoXY( int x, int y ) |
| 37 | { |
| 38 | cursor = x + ( y * GRID_WIDTH ); |
| 39 | } |
| 40 | |
| 41 | int whereX() |
| 42 | { |
| 43 | return cursor % GRID_WIDTH; |
| 44 | } |
| 45 | |
| 46 | int whereY() |
| 47 | { |
| 48 | return cursor / GRID_WIDTH; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | void 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 | |
| 112 | void 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 |
| 119 | void 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 | |
| 135 | void write( const char *c ) |
| 136 | { |
| 137 | for ( const char *b = c; *b != '\0'; b++ ) |
| 138 | { |
| 139 | write( *(unsigned char *)b ); |
| 140 | } |
| 141 | } |