/*
Dos/Adom fans:

I haven't been on this brd in over a yr., (busy, sidetracked)
and I don't know if he still visits, but IAIN once published
a baby sprite example on a site he had going (sorry, but I
don't have the addrs). Some may recall the Cursor Driven
Menu system he did here a good while back -- (nice,
as it clued newbies to the workings of such menu designs).

Here's a revamp of the aforementioned sprite driver --
this one able to scroll a larger space than that windowed,
(perhaps the actual scrn size, in the case of a rogue or RPG).

Array size, window size and scrn offsets are #definable, or
single-loc sets. I'll leave barriers, cursor choice and further
color / collision detction to the user, 4 shrt post.

Enjoy. If anyone knows IAIN or EMIL's mail I would appreciate.

-- Mike H.
*/

#include <stdio.h>
#include <conio.h>

#define UP 72
#define DN 80
#define LF 75
#define RT 77

// wndow size -- horiz
#define h1 12
// window size -- vert
#define v1 6
// array size -- horiz
#define h2 17
// array size -- vert
#define v2 8

int main() {

const int oH = 28; // screen offset -- horiz
const int oV = 9; // screen offset -- vert

int Hl = 0; int Vl = 0; // currnt wndow pos
int hx = 0; int ix = 0; // for runners - display
int cH = 2; int cV = 1; // currnt crsor pos

int k = 0; // gtch

char jx[v2][h2] =
{ { "o.o.o.o.o.o.o.o.o" }, { "o...............o" },
{ "o.......C.......o" }, { "o...............o" },
{ "o...............o" }, { "o...............o" },
{ "o...............o" }, { "o.o.o.o.o.o.o.o.o" } };

textcolor( 8 );
clrscr();

// optional
gotoxy( oH - 2, oV-1 ); cprintf( "%c", 197 );
gotoxy( oH+h1+1, oV-1 ); cprintf( "%c", 197 );
gotoxy( oH - 2, oV+v1 ); cprintf( "%c", 197 );
gotoxy( oH+h1+1, oV+v1 ); cprintf( "%c", 197 );

do {

// prnt wndow to scrn..
_setcursortype( 0 );
for( hx = Vl; hx < ( Vl + v1 ); hx++ ) {
for( ix = Hl; ix < ( Hl + h1 ); ix++ ) {
gotoxy( ix+oH-Hl, hx+oV-Vl );

if( jx[hx][ix] == 'o' ) textcolor( 1 );
else if( jx[hx][ix] == '.' ) textcolor( 1 );
else textcolor( 7 );

cprintf("%c", jx[hx][ix] ); } }
_setcursortype( 2 );

gotoxy( oH+cH, oV+cV );

k = getch();
if( k == 0 )
k = getch();

// clr collision..
gotoxy( oH+2, oV+v1+2 );
cprintf(" ");

if( k == RT ) if( cH < ( h1 - 1 ) ) cH++;
else if( (Hl+h1) < h2 ) Hl++;

if( k == DN ) if( cV < ( v1 - 1 ) ) cV++;
else if( (Vl+v1) < v2 ) Vl++;

if( k == LF ) if( cH > 0 ) cH--;
else if( Hl > 0 ) Hl--;

if( k == UP ) if( cV > 0 ) cV--;
else if( Vl > 0 ) Vl--;

// coll detect..
if( jx[cV+Vl][cH+Hl] != '.' )
if( jx[cV+Vl][cH+Hl] != 'o' ) {
gotoxy( oH+2, oV+v1+2 );
textcolor( 4 );
cprintf("COLLISION"); }

} while( k != 27 ); // bail on 'Esc'
_setcursortype( 2 );
return( 0 );
}