//////////////////////////////////////////////////////////////////////////////
// _____ __ __ _ //
// / ____| | \/ | (_) //
// | | __ __ _ _ __ ___ ___| \ / | __ _ _ _ __ ___ _ __ _ __ //
// | | |_ |/ _` | '_ ` _ \ / _ \ |\/| |/ _` | | '_ \ / __| '_ \| '_ \ //
// | |__| | (_| | | | | | | __/ | | | (_| | | | | | _ | (__| |_) | |_) | //
// \_____|\__,_|_| |_| |_|\___|_| |_|\__,_|_|_| |_|(_) \___| .__/| .__/ //
// | | | | //
// |_| |_| //
//////////////////////////////////////////////////////////////////////////////
/*This is used in Tutorial 4.00 - 4.05 */
#define GLOBALS_OWNERSHIP
#include "Globals.h"
#include <string.h>
//----------------------------------------------------------------------------
// Local Function Declarations
//----------------------------------------------------------------------------
void EraseBackground();
void Game_Main();
void DrawFont(int x, int y, const char *pszText);
//------------------------------------------------------------------------
// Local Definitions
//------------------------------------------------------------------------
// This is a shortcut for checking the state of a key using DirectInput
#define KEYDOWN(key) (G.KeyState[key] & 0x80)
// This converts an R,G,B set to a 16-bit color (565)
#define RGB16COLOR(r,g,b) ((r << 11) + (g << 5) + b)
#define KEYDOWN2(i) (G.ddod.dwData & 0x80)
//////////////////////////////////////////////////////////////////////////////
// Game_Main
//
// This function is called once per frame.
//
void Game_Main()
{
HRESULT hRet;
static int j = 0;
static char typing3[256];
static char typing[256];
static char typing2[16][16];
static int letterCounter = -1;
DWORD arrayNum = 10;
while (hRet = G.lpDIKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), G.ddod, &arrayNum, 0)
== DIERR_INPUTLOST)
{
// Acquire the keyboard
if (FAILED(hRet = G.lpDIKeyboard->Acquire())) break;
}
char letter = ' ';
for (DWORD i = 0; i < arrayNum; ++i) {
if (G.ddod.dwData & 0x80) {
switch (G.ddod.dwOfs) {
case DIK_A: letter = 'A';
break;
case DIK_B: letter = 'B';
break;
case DIK_C: letter = 'C';
break;
case DIK_D: letter = 'D';
break;
case DIK_E: letter = 'E';
break;
case DIK_F: letter = 'F';
break;
case DIK_G: letter = 'G';
break;
case DIK_H: letter = 'H';
break;
case DIK_I: letter = 'I';
break;
case DIK_J: letter = 'J';
break;
case DIK_K: letter = 'K';
break;
case DIK_L: letter = 'L';
break;
case DIK_M: letter = 'M';
break;
case DIK_N: letter = 'N';
break;
case DIK_O: letter = 'O';
break;
case DIK_P: letter = 'P';
break;
case DIK_Q: letter = 'Q';
break;
case DIK_R: letter = 'R';
break;
case DIK_S: letter = 'S';
break;
case DIK_T: letter = 'T';
break;
case DIK_U: letter = 'U';
break;
case DIK_V: letter = 'V';
break;
case DIK_W: letter = 'W';
break;
case DIK_X: letter = 'X';
break;
case DIK_Y: letter = 'Y';
break;
case DIK_Z: letter = 'Z';
break;
default: break;
}
}
}
if (letter != ' ')
typing[j] = letter;
strcpy(typing3, typing);
DrawFont(j*13, 240, &typing[j]);
DrawFont(0, 260, typing3);
G.lpDDSPrimary->Flip(NULL, 0);
if (strlen(typing)-1 == j)
++j;
if (j > 53)
j = 0;
}
/***************************************************************************/
//////////////////////////////////////////////////////////////////////////////
// EraseBackground
//
// This will clear the entire display surface (i.e. the backbuffer) to the
// color BLACK.
//
void EraseBackground()
{
HRESULT hRet;
DDBLTFX ddbltfx;
// Prepare for a black color blt
ddbltfx.dwSize = sizeof(DDBLTFX);
ddbltfx.dwFillColor = 0;
while (TRUE)
{
// Blt the color BLACK over the entire backbuffer
hRet = G.lpDDSBack->Blt(NULL, NULL, NULL,
DDBLT_COLORFILL|DDBLT_WAIT, &ddbltfx);
if (SUCCEEDED(hRet)) break;
// If the surfaces are lost, restore them and try again
if (hRet == DDERR_SURFACELOST)
if (FAILED(hRet = RestoreAll())) break;
else break;
}
}
void DrawFont(int x, int y, const char *pszText)
{
// Font definitions
#define ALPHA_LARGE_STARTX 0
#define ALPHA_LARGE_STARTY 0
#define ALPHA_LARGE_WIDTH 11
#define ALPHA_LARGE_HEIGHT 13
#define ALPHA_SMALL_STARTX 0
#define ALPHA_SMALL_STARTY 13
#define ALPHA_SMALL_WIDTH 11
#define ALPHA_SMALL_HEIGHT 17
#define NUMERIC_STARTX 0
#define NUMERIC_STARTY 29
#define NUMERIC_WIDTH 11
#define NUMERIC_HEIGHT 13
enum charWidth {ALW, ASW, NW} CharWidth;
RECT rectSrc, rectDst;
int location = 0;
int letterSpacing;
char curr;
DDBLTFX ddbltfx;
DDSURFACEDESC ddsd;
INIT_STRUCT(ddsd);
INIT_STRUCT(ddbltfx);
// Go through each character in the given string
for (int i = 0; i < (int)strlen(pszText); i++)
{
// Get the current character
curr = pszText;
// Capital letter?
if (curr >= 'A' && curr <= 'Z')
{
rectSrc.left = ALPHA_LARGE_STARTX + ((curr - 'A') * ALPHA_LARGE_WIDTH);
rectSrc.top = ALPHA_LARGE_STARTY;
rectSrc.right = rectSrc.left + ALPHA_LARGE_WIDTH - 1;
rectSrc.bottom = rectSrc.top + ALPHA_LARGE_HEIGHT - 1;
letterSpacing = ALPHA_LARGE_WIDTH;
CharWidth = ALW;
}
// Small letter?
else if (curr >= 'a' && curr <= 'z')
{
rectSrc.left = ALPHA_SMALL_STARTX + ((curr - 'a') * ALPHA_SMALL_WIDTH);
rectSrc.top = ALPHA_SMALL_STARTY;
rectSrc.right = rectSrc.left + ALPHA_SMALL_WIDTH - 1;
rectSrc.bottom = rectSrc.top + ALPHA_SMALL_HEIGHT - 1;
letterSpacing = ALPHA_SMALL_WIDTH;
CharWidth = ASW;
}
// Number?
else if (curr >= '0' && curr <= '9')
{
rectSrc.left = NUMERIC_STARTX + ((curr - '0') * NUMERIC_WIDTH);
rectSrc.top = NUMERIC_STARTY;
rectSrc.right = rectSrc.left + NUMERIC_WIDTH - 1;
rectSrc.bottom = rectSrc.top + NUMERIC_HEIGHT - 1;
letterSpacing = NUMERIC_WIDTH;
CharWidth = NW;
}
// Other (space or non-supported character)
else
{
// If it's a space, move over one character (screen position)
if (curr == ' ') location++;
// Skip to the next character in the string
continue;
}
// Draw this character to the backbuffer at the proper location
rectDst.top = y;
rectDst.left = x + (location++ * letterSpacing);
rectDst.right = rectDst.left + 11;
rectDst.bottom = rectDst.top + 15;
switch (CharWidth) {
case ALW: rectDst.bottom = rectDst.top + ALPHA_LARGE_HEIGHT - 1; break;
case ASW: rectDst.bottom = rectDst.top + ALPHA_SMALL_HEIGHT - 1; break;
case NW: rectDst.bottom = rectDst.top + NUMERIC_HEIGHT - 1; break;
default: break;
}
G.lpDDSBack->Blt(&rectDst, G.lpDDSRes, &rectSrc, DDBLT_WAIT, NULL);
}
}
// ---------------------------------------------------------------------------
// GameMain.cpp - End of file
// ---------------------------------------------------------------------------
🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Buffered Input....
here's my stab at it:
i haven't gotten all the kinks out but it's definitely doing what i want it to do. so for now, i'm quite satisfied [grin]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement