#include "DarkGDK.h"
#include <dos.h>
#include <stdio.h>
#include <conio.h>
//#include <WinAble.h>
#define MaxInputs 1000
struct INPUTUSER {int colred; int colgreen; int colblue; char *input;};
INPUTUSER inputuser[MaxInputs];
int spot;
char *in;
bool capslock;
char *unput;
char *Entry;
int numcount;
int iNextTextSprite;
int sizetext;
double size;
void Texts ( int iX , int iY , int iSize , char* czText , bool bHorizonalCenter = false , bool bVerticalCenter = false,int sprite=1);
void fixUV( char c );
void Texts ( int iX , int iY , int iSize , char* czText , bool bHorizontalCenter , bool bVerticalCenter, int sprite)
{
size=iSize;
// if bHorizonalCenter is true then work out the x coordinate to make the text centered
if ( bHorizontalCenter )
{
iX = (int)(( dbScreenWidth() / 2 ) - ( ( strlen( czText ) * iSize ) / 2 ));
}
// if bHorizonalCenter is true then work out the y coordinate to make the text centered
if ( bVerticalCenter )
{
iY = ( dbScreenHeight() / 2 ) - ( iSize / 2 );
}
sizetext=(int)strlen( czText );
// loop through and draw each character
for ( int i = 0 ; i < sizetext ; i++ )
{
// if ( czText[i] == 32 )
// iX += iSize;
// else
// {
dbSprite ( iNextTextSprite , iX , iY , sprite );
fixUV( czText[i]);
dbSizeSprite ( iNextTextSprite , iSize , iSize );
iX += iSize;
iNextTextSprite++;
// }
}
}
void fixUV( char c )
{
c=c-32;
// so we offset it to line up with our image
float U = 0.0f;
float V = 0.0f;
int iY = c / 10;
int iX = c % 10;
float fOffset = 1.0f / 10.0f;
U = iX * fOffset;
V = iY * fOffset;
dbSetSpriteTextureCoord ( iNextTextSprite , 0 , U, V );
dbSetSpriteTextureCoord ( iNextTextSprite , 1 , U + fOffset , V );
dbSetSpriteTextureCoord ( iNextTextSprite , 2 , U , V + fOffset );
dbSetSpriteTextureCoord ( iNextTextSprite , 3 , U + fOffset , V + fOffset );
}
void hidesprite()
{
for(int i=100+sizetext+1; i<=iNextTextSprite; i++)
{
dbHideSprite(i);
}
}
void setdef(int r, int g, int b)
{
int i;
for ( i = 100 ; i <= 100+sizetext ; i++ )
{
dbSetSpriteDiffuse( i, r, g, b );
}
hidesprite();
}
bool intxc(int xcnt,int mousex,int mousey)
{
bool selected=false;
if(mousex>=dbSpriteX(xcnt)&&mousey>=dbSpriteY(xcnt)&&mousex<=dbSpriteX(xcnt)+size&&mousey<=dbSpriteY(xcnt)+size)//mousex>=dbSpriteX(xcont)&&mousey>=dbSpriteY(xcont)&&mousex<=dbSpriteX(xcont)+dbSpriteWidth(xcont))//&&mousex<=dbSpriteX(xcont)+dbSpriteWidth(xcont)&&mousey<=dbSpriteY(xcont)+dbSpriteHeight(xcont))
{
// xx=xcontt;
// dbPrint(xx);
dbText(100,100,"true");
dbShowSprite(xcnt+sizetext);
//dbShowSprite(101+sizetext+1);
selected=true;
}
return selected;
}
void inputbyusers()
{
in= new char(100);
in[0]='';
inputuser[0].colblue=255;
inputuser[0].colgreen=255;
inputuser[0].colred=255;
inputuser[0].input=in;
spot=0;
}
void addline(char *line)
{
inputuser[spot].input=in;
spot++;
}
void changecollar(int r, int g, int b)
{
inputuser[spot].colblue=b;
inputuser[spot].colgreen=g;
inputuser[spot].colred=r;
}
void TextSetup()
{
dbLoadImage ( "fontdefault2.bmp" , 100);
dbLoadImage ( "fontdefaulthighlight.bmp" , 101 );
}
void ChatFunc(int x, int y)
{
dbInk(dbRgb(100,100,100),0);
dbBox(x,y,dbScreenWidth(),y+20);
dbInk(dbRgb(255,255,255),0);
//dbSetImageColorKey(255,255,255);
unput=dbGetEntry();
if (unput > 0) {
if (*unput != 0) {
if (numcount < 256)
{
if ((!dbKeyState(14)) && (!dbKeyState(28)))
{
strcat(Entry, unput);
dbClearEntryBuffer();
numcount++;
}
if (dbKeyState(14) && !dbKeyState(28)&&numcount > 0)
{
dbClearEntryBuffer();
iNextTextSprite--;
dbDeleteSprite(iNextTextSprite);
//iNextTextSprite--;
numcount--;
Entry[numcount] = '';
}
if(dbKeyState(28))
{
dbClearEntryBuffer();
Entry="";
}
dbClearEntryBuffer();
}
}
}
for(int xx=100;xx<=iNextTextSprite;xx++)
{
//dbHideSprite(xx);
dbDeleteSprite(xx);
//dbCLS();
}
//x=dbTextWidth(Entry);
Texts(x,y,13,Entry,false,false,100);
//Texts(0,0,12,Entry,false,false,101);
//hidesprite();
//dbText(0, 20, dbStr(numcount));
//dbText(0, 40, Entry);
//dbSync ( );
}
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple 2D project that uses Dark GDK
// it can be used as a starting point in making your own 2D games
// whenever using Dark GDK you must ensure you include the header file
// the main entry point for the application is this function
void DarkGDK ( void )
{
//bdos(0xC, 0, 0) ;
numcount=0;
Entry=new char(256);
TextSetup();
iNextTextSprite=100;
//char *unput;
//system('c0');
// in this application a backdrop is loaded and then several
// animated sprites are displayed on screen
// when starting a Dark GDK program it is useful to set global
// application properties, we begin by turning the sync rate on,
// this means we control when the screen is updated, we also set
// the maximum rate to 60 which means the maximum frame rate will
// be set at 60 frames per second
dbSyncOn ( );
dbSyncRate ( 60 );
// unput=dbScanCode();
while ( LoopGDK ( ) )
{
//double scan=dbScanCode();
ChatFunc(0,0);
if ( dbEscapeKey ( ) )
break;
//dbPrint(scan);
// here we make a call to update the contents of the screen
dbSync ( );
}
return;
}
this is it with sprites
Go through yourself at a wall.