#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glext.h>
#include "wglext.h"#include <olectl.h> #include <gdiplus/gdiplus.h>
#include "resource.h"
float bgAngle=0.0f;
float pLoad=150.0f;
float loadAngleStep=1.0f;
float loadAngle=0.0f-pLoad*loadAngleStep;
float loadFarStep=0.1f;
float loadFar=-pLoad*loadFarStep;
int pC=0;
int sndVol=0, melVol=0;
int qC=0, qCmx=4;
bool rvOn=false;
float rvSteps=255.0f/2.5f;
float rvC, rvAngle, rvWidth, rvWstep, rvWmx=0.5f;
int rvX, rvY, rvSide;
int turn=1;
int moveOff=0;
int cx, cy;
int posX=0, posY=0, posHL=1;
int posXl=-1, posYl=-1;
int mXar0 [10], mYar0 [10];
int mXar1 [10]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, mYar1 [10]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int mXar [10], mYar [10];
int cCPU=2, cPlayer=2, cMove;
int button=0;
float colorCoordHL [4]={0.0f, 0.0f, 0.0f}, colorCoordX [4]={0.0f, 0.0f, 1.0f}, colorCoordY [4]={0.5f, 0.25f, 0.0f},
colorCellHL1 [4]={0.5f, 0.25f, 1.0f}, colorCellHL0 [4]={1.0f, 0.0f, 0.0f},
colorCellOff [4]={1.0f, 0.8f, 0.1f},
colorPlayer [4]={0.0f, 1.0f, 0.0f}, colorCPU [4]={0.25f, 0.25f, 0.25f},
colorPlayerStat [4]={0.0f, 0.5f, 0.0f}, colorCPUStat [4]={0.35f, 0.35f, 0.35f},
colorVol [4]={0.95f, 0.8f, 0.1f}, colorExitT [4]={0.85f, 0.0f, 0.0f},
colorExitB [4]={1.0, 0.0f, 0.0f}, colorRestB [4]={1.0f, 0.85f, 0.15f},
colorTxt [4]={1.0f, 1.0f, 1.0f}, colorTxtB [4]={0.5f, 0.5f, 0.5f}, colorH [4]={1.0f, 0.5f, 0.0f},
colorShadow [4]={0.1f, 0.1f, 0.1f};
char mCPUd [100] [65];
int mCPUx [100], mCPUy [100], mCPUr [100], mCPUr0 [100];
int AI=1;
char txt [16];
float resultAngle;
bool resultOff;
float cq=1.0f, ca=0.005f, cl=1.0f;
int fpsOn=0;
bool clockTweak=false;
long clockL=0;
float clockD=0.0f;
bool noRest=false, blur_on=false, loaded=false;
bool moreFPS=true;
bool bQuit=false;
bool quitCPU=false;
bool infOn=false;
bool ctrl_key=false, keyLockEsc=false, keyLockEnter=false;
int fontS, fps=-1, paintC=0, timeS=0;
int dmW [96], dmH [96], dmB [96], dmC=0,
dmH0, dmW0, dmB0, dmN=0,
dmHs, dmWs, dmBs, dmHt, dmWt, dmBt;
bool dmBitsOff=true;
GLuint texture [256];
GLuint base; GLuint PixelFormat;
COLORREF bGround=RGB (55, 56, 84);
HFONT font;GLYPHMETRICSFLOAT gmf [256];LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
const unsigned int TIMER_MEL=5, TIMER_QUIT=10, TIMER_MELON=15;
COLORREF pixel=RGB (0, 0, 0);
TRACKMOUSEEVENT tme;
POINT mypoint;
HCURSOR curArrow, curWait, curNew, curOff;
static HANDLE gThreadCPU=NULL;
DWORD wThreadCPU;
DWORD WINAPI threadCPU (LPVOID);
WNDCLASS wc;
HWND hWnd;
HINSTANCE gThisInstance; int gFunsterStil;
HDC hDC;
HGLRC hRC;
MSG msg;
PAINTSTRUCT PaintStruct;
ULONG_PTR gdiplusToken;
Gdiplus::Graphics * gDC;
Gdiplus::Image * imagesH;
char mb [64];
char szClassName []="OpenGL App";
char title []="Repaint";
char init_d [64]={
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,2,1,0,0,0,
0,0,0,1,2,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
char init_p [64]={
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,2,1,0,0,0,
0,0,0,1,2,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
char rv_d [64];
void paint ();
void mouseMove ();
void mouseClick ();
int getPos (int x, int y);
void cellInfo ();
int reverse (int x, int y, int side, int mode=0);
void windowUp ();
void moveCPU ();
void playerMove ();
bool isMove ();
void turnOver ();
void statusBar ();
void fpsC ();
float fpsTweak ();
void saveConf ();
void loadConf ();
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC, GLuint pf);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
void InitGL ();
int InitMultisample ();
void LoadGLTextures ();
void BuildLists ();
void getScr ();
void screenSet ();
void screenUp ();
void keysOff ();
void loading ();
char AppDir [_MAX_PATH];
int soundVol=0, meloVol=0;
bool soundOn=false, meloIs=false, audioOnce=false;
#include "sound.h"
#include "melody.h"
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
int i;
gThisInstance=hInstance;
gFunsterStil=iCmdShow;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup (&gdiplusToken, &gdiplusStartupInput, NULL);
char AppPath [_MAX_PATH];
int ap_l=0;
memset (AppPath, 0, _MAX_PATH);
memset (AppDir, 0, _MAX_PATH);
GetModuleFileName (NULL, AppPath, _MAX_PATH);
for (i=_MAX_PATH-1; i>=0 && ap_l==0; i--)
{
if (AppPath [i]=='\\')
ap_l=i+1;
}
memcpy (AppDir, AppPath, ap_l);
memset (mb, 0, 64);
srand (time (NULL));
getScr ();
loadConf ();
screenSet ();
wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon (hInstance, MAKEINTRESOURCE(ID_PIC));
wc.hCursor=LoadCursor (hInstance, MAKEINTRESOURCE(ID_CUR));
curArrow=LoadCursor (hInstance, MAKEINTRESOURCE(ID_CUR));
curWait=LoadCursor (hInstance, MAKEINTRESOURCE(ID_CUW));
curNew=LoadCursor (hInstance, MAKEINTRESOURCE(ID_NEW));
curOff=LoadCursor (hInstance, MAKEINTRESOURCE(ID_OFF));
wc.hbrBackground=(HBRUSH)CreateSolidBrush (bGround);
wc.lpszMenuName=NULL;
wc.lpszClassName=szClassName;
RegisterClass (&wc);
for (i=0; i<2; i++)
{
hWnd=CreateWindowEx (
0, szClassName, title, WS_POPUP, 0, 0, cx+1, cy+1, HWND_DESKTOP, NULL, hInstance, NULL );
if (i==0)
{
EnableOpenGL (hWnd, &hDC, &hRC, 0);
PixelFormat=InitMultisample ();
break;
DestroyWindow (hWnd);
}
else
EnableOpenGL (hWnd, &hDC, &hRC, PixelFormat);
}
ShowWindow (hWnd, iCmdShow);
SetForegroundWindow (hWnd); SetFocus (hWnd); InitGL ();
playSound ("board", 0, 1);
tme.cbSize=sizeof(tme);
tme.dwFlags=TME_HOVER;
tme.hwndTrack=hWnd; tme.dwHoverTime=HOVER_DEFAULT;
TrackMouseEvent(&tme);
gThreadCPU=CreateThread (NULL, 0, threadCPU, (void *)"threadCPU", 0, &wThreadCPU);
loaded=true;
while (!bQuit)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message==WM_QUIT)
bQuit=true;
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
if (!bQuit)
{
if (!blur_on)
paint ();
}
Sleep ((audioOnce ? 12 : 10)*(moreFPS ? 1 : 3));
}
saveConf ();
meloClose ();
Gdiplus::GdiplusShutdown (gdiplusToken);
quitCPU=true;
for (int i=0; i<10 && quitCPU; i++)
Sleep (10);
CloseHandle (gThreadCPU);
DisableOpenGL (hWnd, hDC, hRC);
ChangeDisplaySettings (NULL, 0); if (hRC) {
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
}
ReleaseDC (hWnd, hDC); UnregisterClass (szClassName, gThisInstance);
DestroyWindow (hWnd);
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
PostQuitMessage (0);
return 0;
case WM_DESTROY:
return 0;
case WM_KILLFOCUS:
keysOff ();
meloBlurOn=true;
blur_on=true;
break;
case WM_SETFOCUS:
if (noRest==true || loaded==false)
break;
fpsOn=0;
clockL=0;
screenSet ();
if (cx!=dmW0 || cy!=dmH0)
{
getScr ();
dmN=0;
dmWs=dmW0;
dmHs=dmH0;
dmBs=dmB0;
screenUp ();
}
else
windowUp ();
meloBlurOff=true;
blur_on=false;
break;
case WM_SIZE:
switch (wParam)
{
case SIZE_RESTORED:
if (blur_on)
break;
if (noRest==true || loaded==false)
break;
screenSet ();
if (cx!=dmW0 || cy!=dmH0)
{
getScr ();
dmN=0;
dmWs=dmW0;
dmHs=dmH0;
dmBs=dmB0;
screenUp ();
}
else
windowUp ();
break;
}
break;
case WM_PAINT:
BeginPaint(hWnd, &PaintStruct);
if (blur_on && loaded)
{
hDC=GetDC (hWnd);
paint ();
ReleaseDC (hWnd, hDC);
}
EndPaint (hWnd, &PaintStruct);
break;
case WM_LBUTTONUP:
mouseClick ();
break;
case WM_MOUSEMOVE:
mouseMove ();
break;
case WM_TIMER:
switch (wParam)
{
case TIMER_MELON:
KillTimer (hWnd, TIMER_MELON);
meloVol=melVol*250;
break;
case TIMER_MEL:
KillTimer (hWnd, TIMER_MEL);
meloInit ();
break;
case TIMER_QUIT:
qC++;
if (qC==qCmx)
{
KillTimer (hWnd, TIMER_QUIT);
bQuit=true;
}
break;
}
break;
case WM_KEYDOWN:
switch (wParam)
{
case 81:
if (ctrl_key)
PostQuitMessage(0);
break;
case VK_ESCAPE:
if (keyLockEsc)
break;
keyLockEsc=true;
if (infOn)
{
infOn=false;
playSound ("shake");
mouseMove ();
}
break;
case VK_RIGHT:
if (posX<7)
{
posX++;
cellInfo ();
}
break;
case VK_LEFT:
if (posX>0)
{
posX--;
cellInfo ();
}
break;
case VK_NEXT:
if (posX<7 && posY<7)
{
posX++;
posY++;
cellInfo ();
}
break;
case VK_PRIOR:
if (posX<7 && posY>0)
{
posX++;
posY--;
cellInfo ();
}
break;
case VK_UP:
if (posY>0)
{
posY--;
cellInfo ();
}
break;
case VK_DOWN:
if (posY<7)
{
posY++;
cellInfo ();
}
break;
case VK_HOME:
if (posX>0 && posY>0)
{
posX--;
posY--;
cellInfo ();
}
break;
case VK_END:
if (posX>0 && posY<7)
{
posX--;
posY++;
cellInfo ();
}
break;
case VK_CONTROL:
ctrl_key=true;
break;
}
if (wParam==VK_RETURN || wParam==VK_SPACE || wParam==VK_CLEAR)
{
if (keyLockEnter)
break;
playerMove ();
keyLockEnter=true;
}
return 0;
case WM_KEYUP:
switch (wParam)
{
case VK_ESCAPE:
keyLockEsc=false;
break;
case VK_CONTROL:
ctrl_key=false;
break;
}
if (wParam==VK_RETURN || wParam==VK_SPACE || wParam==VK_CLEAR)
keyLockEnter=false;
return 0;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
}
DWORD WINAPI threadCPU (LPVOID)
{
srand (time (NULL));
while (!quitCPU)
{
if (turn==2)
{
turn=3;
moveCPU ();
}
Sleep (10);
}
quitCPU=false;
}
bool arCur=false;
void moveCPU ()
{
int xi, yi, xm, ym, r, r0, mx, mx0, mx1=-100, n=0, i, c=0;
int rs1, rs2;
int tCPUr0 [100], tCPUx [100], tCPUy [100];
bool found=false;
for (yi=0; yi<8; yi++)
{
for (xi=0; xi<8; xi++)
{
memcpy (rv_d, init_d, 64);
r=reverse (xi, yi, 2, 2);
r0=r;
if (r>0)
{
rs1=0; rs2=0;
if (xi==0 || xi==7)
rs1=1;
if (yi==0 || yi==7)
rs2=1;
if (rs1+rs2==1)
r+=5;
else if (rs1+rs2==2)
r+=25;
mCPUr [n]=r;
mCPUr0 [n]=r0;
mCPUx [n]=xi;
mCPUy [n]=yi;
if (AI==1)
{
if (r>mx1)
mx1=r;
}
else if (AI==2)
{
rv_d [getPos (xi, yi)]=2;
memcpy (mCPUd [n], rv_d, 64);
}
n++;
}
}
}
if (AI==2)
{
for (i=0; i<n; i++)
{
mx=0;
for (yi=0; yi<8; yi++)
{
for (xi=0; xi<8; xi++)
{
memcpy (rv_d, mCPUd [i], 64);
r=reverse (xi, yi, 1);
if (r>0)
{
rs1=0; rs2=0;
if (xi==0 || xi==7)
rs1=1;
if (yi==0 || yi==7)
rs2=1;
if (rs1+rs2==1)
r+=5;
else if (rs1+rs2==2)
r+=25;
}
if (r>mx)
mx=r;
}
}
mCPUr [i]-=mx;
if (mCPUr [i]>mx1)
mx1=mCPUr [i];
}
}
for (i=0; i<n; i++)
{
if (mCPUr [i]==mx1 || AI==0)
{
found=true;
tCPUr0 [c]=mCPUr0 [i];
tCPUx [c]=mCPUx [i];
tCPUy [c]=mCPUy [i];
c++;
}
}
if (found)
{
n=rand ()%c;
mx0=tCPUr0 [n];
xm=tCPUx [n];
ym=tCPUy [n];
moveOff=0;
memcpy (rv_d, init_d, 64);
reverse (xm, ym, 2, 1);
memcpy (init_d, rv_d, 64);
init_d [getPos (xm, ym)]=2;
rvC=0.0f;
rvX=xm;
rvY=ym;
rvSide=2;
rvAngle=0.0f;
rvWidth=0.0f;
rvWstep=rvWmx*2.0f/rvSteps;
rvOn=true;
cCPU+=mx0+1;
cPlayer-=mx0;
char t [16];
sprintf (t, "move%d", (rand ()%5+1));
playSound (t);
}
else
{
moveOff++;
if (moveOff==2 || cPlayer+cCPU==64 || !isMove ())
turnOver ();
else
{
turn=1;
arCur=true;
playSound ("break");
}
}
}
bool isMove ()
{
int xi, yi, r;
for (yi=0; yi<8; yi++)
{
for (xi=0; xi<8; xi++)
{
memcpy (rv_d, init_d, 64);
r=reverse (xi, yi, 1);
if (r>0)
return true;
}
}
return false;
}
bool toCur=false;
void turnOver ()
{
resultAngle=90.0f;
resultOff=false;
turn=4;
toCur=true;
}
void keysOff ()
{
ctrl_key=false;
keyLockEsc=false;
keyLockEnter=false;
}
void getScr ()
{
int i, i2, bitsN=0;
bool dmRepeat;
DEVMODE devMode; memset (&devMode, 0, sizeof (devMode)); devMode.dmSize=sizeof (devMode); for (i=0; EnumDisplaySettings (0, i, &devMode); i++)
{
dmRepeat=false;
for (i2=0; i2<dmC; i2++)
{
if (dmW [i2]==devMode.dmPelsWidth && dmH [i2]==devMode.dmPelsHeight && dmB [i2]==devMode.dmBitsPerPel)
dmRepeat=true;
}
if (!dmRepeat)
{
if (bitsN==0)
bitsN=devMode.dmBitsPerPel;
else if (bitsN!=devMode.dmBitsPerPel)
dmBitsOff=false;
dmW [dmC]=devMode.dmPelsWidth;
dmH [dmC]=devMode.dmPelsHeight;
dmB [dmC]=devMode.dmBitsPerPel;
dmC++;
}
}
int swpH, swpW, swpB;
for (i=0; i<dmC; i++)
{
for (i2=i; i2<dmC; i2++)
{
if (dmW [i2]>dmW [i] || (dmW [i2]==dmW [i] && dmH [i2]>dmH [i])
|| (dmW [i2]==dmW [i] && dmH [i2]==dmH [i] && dmB [i2]>dmB [i]))
{
swpW=dmW [i];
swpH=dmH [i];
swpB=dmB [i];
dmW [i]=dmW [i2];
dmH [i]=dmH [i2];
dmB [i]=dmB [i2];
dmW [i2]=swpW;
dmH [i2]=swpH;
dmB [i2]=swpB;
}
}
}
memset (&devMode, 0, sizeof (devMode)); devMode.dmSize=sizeof (devMode); EnumDisplaySettings (0, ENUM_CURRENT_SETTINGS, &devMode);
dmW0=devMode.dmPelsWidth;
dmH0=devMode.dmPelsHeight;
dmB0=devMode.dmBitsPerPel;
}
void windowUp ()
{
SetWindowPos (hWnd, HWND_TOP, 0, 0, cx+1, cy+1, SWP_NOMOVE);}
void screenSet ()
{
cx=(LONG)::GetSystemMetrics (SM_CXSCREEN);
cy=(LONG)::GetSystemMetrics (SM_CYSCREEN);
}
void screenUp ()
{
noRest=true;
windowUp ();
DisableOpenGL (hWnd, hDC, hRC);
EnableOpenGL (hWnd, &hDC, &hRC, PixelFormat);
SetForegroundWindow (hWnd); SetFocus (hWnd); InitGL ();
pC=0;
noRest=false;
}
void InitGL ()
{
SetCursor (curWait);
glShadeModel (GL_SMOOTH); glViewport (0, 0, cx+2, cy+2);
glMatrixMode (GL_PROJECTION);
gluPerspective (45.0f, (GLfloat)cx/(GLfloat)cy, 0.1f, 100.0f);
glClearDepth (1.0); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL); glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glMatrixMode (GL_MODELVIEW);
loading ();
LoadGLTextures ();
glEnable (GL_TEXTURE_2D);
int i;
for (i=0; i<9; i++)
mXar0 [i]=cx/2-(float)cy*4.5f/9.0f+cy*i/9;
for (i=0; i<9; i++)
mYar0 [i]=cy*(i+1)/9;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPolygonMode (GL_BACK, GL_LINE); glPolygonMode (GL_FRONT, GL_FILL); BuildLists ();}
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC, GLuint pf)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
*hDC=GetDC (hWnd);
if (pf==0)
{
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize=sizeof (pfd);
pfd.nVersion=1;
pfd.dwFlags=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType=PFD_TYPE_RGBA;
pfd.cColorBits=dmBs;
pfd.cDepthBits=24;
pfd.iLayerType=PFD_MAIN_PLANE;
iFormat=ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);
}
else
SetPixelFormat(*hDC, pf, &pfd);
*hRC=wglCreateContext (*hDC);
wglMakeCurrent (*hDC, *hRC);
}
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}
int shape [65536];
void LoadGLTextures ()
{
HDC hdcTemp; HBITMAP hbmpTemp; IPicture *pPicture; OLECHAR wszPath [MAX_PATH+1]; long lWidth; long lHeight; float lWidth2;
float lHeight2;
float gWidth;
float gHeight;
long lWidthPixels; long lHeightPixels; GLint glMaxTexDim ; char texs [25] [32]={"blank.gif", "sky.jpg",
"bar.jpg", "bord.gif", "lits.jpg",
"bg.jpg", "tooltip.jpg"
};
char texd [16]={"data\\textures"};
char txt [_MAX_PATH];
int i2, xi, yi, cl, ri;
for (i2=0; i2<8; i2++)
{
if (strlen (texs [i2])==0)
{
}
else if (i2==2 || i2==3 || i2==4) {
sprintf (txt, "%s%s\\%s", AppDir, texd, texs [i2]);
MultiByteToWideChar (CP_ACP, 0, txt, -1, wszPath, MAX_PATH); HRESULT hr=OleLoadPicturePath (wszPath, 0, 0, 0, IID_IPicture, (void**)&pPicture);
if (!FAILED (hr)) {
hdcTemp=CreateCompatibleDC (GetDC (0)); if (!hdcTemp) pPicture->Release(); else
{
if (i2==2)
{
lWidthPixels=256;
lHeightPixels=256;
lWidth2=gWidth;
lHeight2=gHeight;
}
else if (i2==3)
{
lWidthPixels=64;
lHeightPixels=64;
lWidth2=gWidth*60/256;
lHeight2=gHeight*60/256;
}
else if (i2==4)
{
lWidthPixels=128;
lHeightPixels=128;
lWidth2=gWidth/2;
lHeight2=gHeight/2;
}
BITMAPINFO bi={0}; DWORD *pBits=0; bi.bmiHeader.biSize=sizeof (BITMAPINFOHEADER); bi.bmiHeader.biBitCount=32; bi.bmiHeader.biWidth=lWidthPixels; bi.bmiHeader.biHeight=lHeightPixels;
bi.bmiHeader.biCompression=BI_RGB; bi.bmiHeader.biPlanes=1; hbmpTemp=CreateDIBSection (hdcTemp, &bi, DIB_RGB_COLORS, (void**)&pBits, 0, 0);
if (!hbmpTemp) { DeleteDC (hdcTemp); pPicture->Release (); }
else
{
SelectObject (hdcTemp, hbmpTemp); int xi2=0, yi2=0, rows=14, i3from=32, i3to=256, i3, i3x;
if (i2==2)
{
i3from=0;
i3to=8;
rows=1;
}
else if (i2==3)
{
i3from=0;
i3to=5;
rows=1;
}
for (i3=i3from; i3<i3to; i3++)
{
if (!(i2==4 && i3>126 && i3<161))
{
i3x=i3;
if (i2==2)
{
if (xi2==0)
i3x=2;
else if (xi2==1)
i3x=8;
else if (xi2==2)
i3x=9;
else if (xi2==3)
i3x=10;
else if (xi2==4)
i3x=11;
else if (xi2==5)
i3x=12;
else if (xi2==6)
i3x=14;
else if (xi2==7)
i3x=8;
}
else if (i2==3)
{
if (xi2==0)
i3x=5;
else if (xi2==1)
i3x=3;
else if (xi2==2)
i3x=4;
else if (xi2==3)
i3x=6;
else if (xi2==4)
i3x=7;
}
pPicture->Render (hdcTemp, 0, 0, lWidthPixels, lHeightPixels, int(lWidth2*xi2), int(lHeight2*(rows-yi2)), int(lWidth2), int(-lHeight2), 0);
long i, n=lWidthPixels*lHeightPixels;
if ((i2==2 && xi2==0) || i2==3)
{
for (i=0; i<n; i++) {
BYTE* pPixel=(BYTE*)(&pBits[i]); BYTE temp=pPixel [0]; pPixel [0]=pPixel [2]; pPixel [2]=temp; pPixel [3]=255; }
}
else if (i2==2 && xi2==1)
{
memset (shape, 0, 256*256);
for (i=0; i<n; i++) {
BYTE* pPixel=(BYTE*)(&pBits[i]); BYTE temp=pPixel [0]; pPixel [0]=pPixel [2]; pPixel [2]=temp; if (pPixel [0]<50 && pPixel [1]<50 && pPixel [2]>150)
shape [i]=0;
else
shape [i]=(pPixel [0]+pPixel [1]+pPixel [2])/3;
}
}
else if (i2==2 && xi2==7)
{
for (i=0; i<n; i++) {
BYTE* pPixel=(BYTE*)(&pBits[i]); BYTE temp=pPixel [0]; pPixel [0]=pPixel [2]; pPixel [2]=temp; pPixel [3]=shape [i]; }
}
else if (i2==2)
{
for (i=0; i<n; i++) {
BYTE* pPixel=(BYTE*)(&pBits[i]); BYTE temp=pPixel [0]; pPixel [0]=pPixel [2]/1.4f; pPixel [1]=pPixel [1]/1.4f;
pPixel [2]=temp/1.4f; pPixel [3]=shape [i]; }
}
else if (i2==4)
{
for (i=0; i<n; i++) {
BYTE* pPixel=(BYTE*)(&pBits[i]); BYTE temp=pPixel [0]; pPixel [0]=pPixel [2]; pPixel [2]=temp;
if (pPixel [0]<25 && pPixel [1]<25 && pPixel [2]>55) {
pPixel [0]=0;
pPixel [1]=0;
pPixel [2]=0;
pPixel [3]=0;
}
else
{
pPixel [0]=(pPixel [0]+pPixel [1]+pPixel [2])/3;
pPixel [1]=(pPixel [0]+pPixel [1]+pPixel [2])/3;
pPixel [2]=(pPixel [0]+pPixel [1]+pPixel [2])/3;
pPixel [3]=(pPixel [0]+pPixel [1]+pPixel [2])/3;
}
}
}
glGenTextures (1, &texture [i3x]); glBindTexture (GL_TEXTURE_2D, texture [i3x]); if (i2==3)
{
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D (GL_TEXTURE_2D, 0, 4, lWidthPixels, lHeightPixels, 0, GL_RGBA, GL_UNSIGNED_BYTE, pBits);
xi2++;
if (i2==4 && xi2>=rows)
{
xi2=0;
yi2++;
}
}
}
DeleteObject (hbmpTemp); DeleteDC (hdcTemp); pPicture->Release(); }
}
}
}
else
{
int i2x=i2;
if (i2==5)
i2x=13;
else if (i2==6)
i2x=15;
sprintf (txt, "%s%s\\%s", AppDir, texd, texs [i2]);
MultiByteToWideChar (CP_ACP, 0, txt, -1, wszPath, MAX_PATH); HRESULT hr=OleLoadPicturePath (wszPath, 0, 0, 0, IID_IPicture, (void**)&pPicture);
if (!FAILED (hr)) {
hdcTemp=CreateCompatibleDC (GetDC (0)); if (!hdcTemp) pPicture->Release(); else
{
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &glMaxTexDim);
pPicture->get_Width (&lWidth); lWidthPixels=MulDiv (lWidth, GetDeviceCaps (hdcTemp, LOGPIXELSX), 2048);
pPicture->get_Height (&lHeight); lHeightPixels=MulDiv (lHeight, GetDeviceCaps (hdcTemp, LOGPIXELSY), 2048);
if (i2==0)
{
gWidth=lWidth;
gHeight=lHeight;
}
if (lWidthPixels<=glMaxTexDim)
lWidthPixels=1<<(int)floor((log ((double)lWidthPixels)/log (2.0f))+0.5f);
else
lWidthPixels=glMaxTexDim;
if (lHeightPixels<=glMaxTexDim)
lHeightPixels=1<<(int)floor ((log ((double)lHeightPixels)/log (2.0f))+0.5f);
else
lHeightPixels=glMaxTexDim;
BITMAPINFO bi={0}; DWORD *pBits=0; bi.bmiHeader.biSize=sizeof (BITMAPINFOHEADER); bi.bmiHeader.biBitCount=32; bi.bmiHeader.biWidth=lWidthPixels; bi.bmiHeader.biHeight=lHeightPixels;
bi.bmiHeader.biCompression=BI_RGB; bi.bmiHeader.biPlanes=1; hbmpTemp=CreateDIBSection (hdcTemp, &bi, DIB_RGB_COLORS, (void**)&pBits, 0, 0);
if (!hbmpTemp) { DeleteDC (hdcTemp); pPicture->Release (); }
else
{
SelectObject (hdcTemp, hbmpTemp); pPicture->Render (hdcTemp, 0, 0, lWidthPixels, lHeightPixels, 0, lHeight, lWidth, -lHeight, 0);
long i, n=lWidthPixels*lHeightPixels;
for (i=0; i<n; i++) {
BYTE* pPixel=(BYTE*)(&pBits[i]); BYTE temp=pPixel [0]; pPixel [0]=pPixel [2]; pPixel [2]=temp; pPixel [3]=255; }
glGenTextures (1, &texture [i2x]); glBindTexture (GL_TEXTURE_2D, texture [i2x]); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D (GL_TEXTURE_2D, 0, 4, lWidthPixels, lHeightPixels, 0, GL_RGBA, GL_UNSIGNED_BYTE, pBits);
DeleteObject (hbmpTemp); DeleteDC (hdcTemp); pPicture->Release(); }
}
}
}
}
}
int InitMultisample()
{
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
wglChoosePixelFormatARB=(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress ("wglChoosePixelFormatARB");
if (!wglChoosePixelFormatARB)
return 0;
HDC hDC=GetDC(hWnd);
int pixelFormat;
UINT numFormats;
float fAttributes []={0, 0};
int iAttributes[] = {
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, dmBs,
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 0,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
WGL_SAMPLES_ARB, 6,
0, 0};
int r=wglChoosePixelFormatARB(hDC, iAttributes, fAttributes, 1, &pixelFormat, &numFormats);
if (!(r && numFormats>=1))
{
iAttributes [19]=4;
r=wglChoosePixelFormatARB (hDC, iAttributes, fAttributes, 1, &pixelFormat, &numFormats);
if (!(r && numFormats>=1))
{
iAttributes [19]=2;
r=wglChoosePixelFormatARB (hDC, iAttributes, fAttributes, 1, &pixelFormat, &numFormats);
if (!(r && numFormats>=1))
return 0;
}
}
return pixelFormat;
}
float literaScale=0.25f, literaX=0.0f, literaY=0.0f, literaZ=-2.4325f;
char literaText [256]="";
void glPrintLitera ()
{
glEnable (GL_BLEND);
for (int i=0; i<strlen (literaText); i++)
{
int t=literaText [i];
if (t<0)
t+=256;
if (!((t>126 && t<161) || (t>-1 && t<=32)))
{
glBindTexture (GL_TEXTURE_2D, texture [t]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-literaScale/2.0f+literaX+i*literaScale/1.85f,
-literaScale/2.0f+literaY, literaZ); glTexCoord2f (1.0f, 0.0f); glVertex3f ( literaScale/2.0f+literaX+i*literaScale/1.85f,
-literaScale/2.0f+literaY, literaZ); glTexCoord2f (1.0f, 1.0f); glVertex3f ( literaScale/2.0f+literaX+i*literaScale/1.85f,
literaScale/2.0f+literaY, literaZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (-literaScale/2.0f+literaX+i*literaScale/1.85f,
literaScale/2.0f+literaY, literaZ); glEnd ();
}
}
glDisable (GL_BLEND);
}
GLuint bgList, brdList, infList, bgListB;
float brdX=1.0f, brdY=1.0f, brdZ=-2.4325f;
float brdS=2.0f;
float brdL=-brdS*5.5f/9.0f, brdR=brdL+brdS;
float brdT=brdS/2.0f, brdB=-brdS/2.0f;
void BuildLists (){
int i;
bgList=glGenLists (12); float bgQ=sqrt (pow (cx, 2)+pow (cy, 2))/(float)cx;
float bgX=1.825f*((float(cx)/float(cy))/(1600.0f/900.0f))*bgQ, bgY=bgX, bgZ=0.0f;
glNewList (bgList, GL_COMPILE); glBindTexture (GL_TEXTURE_2D, texture [1]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-bgX, -bgY, bgZ); glTexCoord2f (1.0f, 0.0f); glVertex3f ( bgX, -bgY, bgZ); glTexCoord2f (1.0f, 1.0f); glVertex3f ( bgX, bgY, bgZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (-bgX, bgY, bgZ); glEnd ();
glEndList (); brdList=bgList+1;
glNewList (brdList, GL_COMPILE);
glBindTexture (GL_TEXTURE_2D, texture [0]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL, brdB, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdR, brdB, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdR, brdT, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL, brdT, brdZ); glEnd ();
glEndList (); infList=brdList+1;
glNewList (infList, GL_COMPILE);
glBindTexture (GL_TEXTURE_2D, texture [13]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL, brdB, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdR, brdB, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdR, brdT, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL, brdT, brdZ); glEnd ();
glEndList ();}
COLORREF ig1=RGB (170, 170, 170), ig2=RGB (185, 185, 185), iw=RGB (240, 240, 240);
bool isGray (COLORREF px)
{
if (px>ig1 && px<ig2)
return true;
return false;
}
bool isWhite (COLORREF px)
{
if (px>iw)
return true;
return false;
}
void paint ()
{
if (pC<10 && !(pLoad>0.0f))
pC++;
glPushMatrix ();
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable (GL_DEPTH_TEST); glLoadIdentity (); glTranslatef (0.0f, 0.0f, -2.4f);
glRotatef (-bgAngle, 0.0f, 0.0f, 1.0f);
bgAngle+=0.05f*fpsTweak ();
if (bgAngle>180.0f)
bgAngle-=360.0f;
if (cCPU>0)
{
cq=(float)cPlayer/(float)cCPU;
if (cq>1.0f)
cq=1.0f;
}
if ((cq>cl && cq-cl>ca*fpsTweak ()) || (cq<cl && cl-cq>ca*fpsTweak ()))
{
cq=cl+(cq-cl)*ca*fpsTweak ();
cl=cq;
}
glColor3f (0.5f*cq+0.5f, 0.5f*cq+0.5f, 0.5f*cq+0.5f);
glCallList (bgList);
glLoadIdentity (); if (pLoad>0.0f)
{
pLoad-=1.0f*fpsTweak ();
glTranslatef (0.0f, 0.0f, loadFar);
glRotatef (-loadAngle, 0.0f, 0.0f, 1.0f);
loadFar+=loadFarStep*fpsTweak ();
loadAngle+=loadAngleStep*fpsTweak ();
SetCursor (curWait);
}
glColor3f (1.0f, 1.0f, 1.0f);
glCallList (brdList);
glColor3f (1.0f, 1.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, texture [2]);
float brdCell=brdS/9.0f;
float brdL2=brdL+brdS/9.0f, brdT2=brdT-brdS/9.0f;
int xi, yi, c=0;
for (yi=0; yi<8; yi++)
{
c++;
for (xi=0; xi<8; xi++)
{
c++;
if (c%2)
{
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xi*brdCell, brdT2-(yi+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xi+1)*brdCell, brdT2-(yi+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xi+1)*brdCell, brdT2-yi*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xi*brdCell, brdT2-yi*brdCell, brdZ); glEnd ();
}
}
}
glColor3f (1.0f, 1.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, texture [5]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL, brdT-brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL+brdCell, brdT-brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL+brdCell, brdT, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL, brdT, brdZ); glEnd ();
glColor3f (1.0f, 1.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, texture [4]);
for (xi=0; xi<8; xi++)
{
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xi*brdCell, brdT-brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xi+1)*brdCell, brdT-brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xi+1)*brdCell, brdT, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xi*brdCell, brdT, brdZ); glEnd ();
}
glColor3f (1.0f, 1.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, texture [3]);
for (yi=0; yi<8; yi++)
{
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL, brdT2-(yi+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL+brdCell, brdT2-(yi+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL+brdCell, brdT2-yi*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL, brdT2-yi*brdCell, brdZ); glEnd ();
}
if (pC==2)
{
int xs, ys=cy/2, xi2, yi2, c=0, i;
bool chk;
xs=mXar0 [0]-(mXar0 [1]-mXar0 [0])/2;
for (xi=xs; xi<cx; xi++)
{
pixel=GetPixel (hDC, xi, ys);
if ((isGray (pixel) && (c+1)%2) || (isWhite (pixel) && !((c+1)%2)))
{
chk=true;
for (xi2=0; xi2<5; xi2++)
{
pixel=GetPixel (hDC, xi+xi2+1, ys);
if ((!isGray (pixel) && (c+1)%2) || (!isWhite (pixel) && !((c+1)%2)))
chk=false;
}
if (chk)
{
mXar1 [c]=xi;
c++;
if (c==8)
break;
}
}
}
if (c==8)
{
ys=cy/2+(mYar0 [1]-mYar0 [0]);
for (i=xi+10; i<cx; i++)
{
pixel=GetPixel (hDC, i, ys);
if (!isGray (pixel))
{
mXar1 [c]=i;
break;
}
}
}
int mx=0, mxd;
for (i=0; i<9; i++)
{
mxd=abs (mXar1 [i]-mXar0 [i]);
if (mxd>mx)
mx=mxd;
}
if (mx<25)
{
for (i=0; i<9; i++)
mXar [i]=mXar1 [i];
}
else
{
for (i=0; i<9; i++)
mXar [i]=mXar0 [i];
}
ys=mYar0 [0]-(mYar0 [1]-mYar0 [0])/2; xs=mXar [0]+(mXar [1]-mXar [0])/2; c=0;
for (yi=ys; yi<cy; yi++)
{
pixel=GetPixel (hDC, xs, yi);
if ((isGray (pixel) && !((c+1)%2)) || (isWhite (pixel) && (c+1)%2))
{
chk=true;
for (yi2=0; yi2<5; yi2++)
{
pixel=GetPixel (hDC, xs, yi+yi2+1);
if ((!isGray (pixel) && !((c+1)%2)) || (!isWhite (pixel) && (c+1)%2))
chk=false;
}
if (chk)
{
mYar1 [c]=yi;
c++;
if (c==8)
break;
}
}
}
if (c==8)
{
mYar1 [c]=cy;
for (i=yi+10; i<cy+10; i++)
{
pixel=GetPixel (hDC, xs, i);
if (!isGray (pixel))
{
mYar1 [c]=i;
break;
}
}
}
for (i=0; i<9; i++)
{
mxd=abs (mYar1 [i]-mYar0 [i]);
if (mxd>mx)
mx=mxd;
}
if (mx<25)
{
for (i=0; i<9; i++)
mYar [i]=mYar1 [i];
}
else
{
for (i=0; i<9; i++)
mYar [i]=mYar0 [i];
}
mouseMove ();
SetTimer (hWnd, TIMER_MEL, 1000, NULL);
playSound ("board");
SetCursor (curArrow);
}
if (pC>1)
{
if (rvOn || turn!=1)
glColor3f (colorCellOff [0], colorCellOff [1], colorCellOff [2]);
else if (posHL)
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
else
glColor3f (colorCellHL0 [0], colorCellHL0 [1], colorCellHL0 [2]);
glBindTexture (GL_TEXTURE_2D, texture [0]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+posX*brdCell, brdT2-(posY+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(posX+1)*brdCell, brdT2-(posY+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(posX+1)*brdCell, brdT2-posY*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+posX*brdCell, brdT2-posY*brdCell, brdZ); glEnd ();
glColor3f (1.0f, 1.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, texture [6]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL, brdT2-(posY+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL+brdCell, brdT2-(posY+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL+brdCell, brdT2-posY*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL, brdT2-posY*brdCell, brdZ); glEnd ();
glColor3f (1.0f, 1.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, texture [7]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+posX*brdCell, brdT-brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(posX+1)*brdCell, brdT-brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(posX+1)*brdCell, brdT, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+posX*brdCell, brdT, brdZ); glEnd ();
char literaL [10]={'8', '7', '6', '5', '4', '3', '2', '1'};
char literaT [10]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
glBindTexture (GL_TEXTURE_2D, texture [0]);
literaY=brdT-brdCell/2.0f; literaZ=brdZ;
literaScale=0.07f;
for (xi=0; xi<8; xi++)
{
if (xi==posX)
glColor3f (colorCoordHL [0], colorCoordHL [1], colorCoordHL [2]);
else
glColor3f (colorCoordX [0], colorCoordX [1], colorCoordX [2]);
literaX=brdL2+brdCell/2.0f+brdCell*xi;
sprintf (literaText, "%c", literaT [xi]);
glPrintLitera (); }
literaX=brdL+brdCell/2.0f;
for (yi=0; yi<8; yi++)
{
if (yi==posY)
glColor3f (colorCoordHL [0], colorCoordHL [1], colorCoordHL [2]);
else
glColor3f (colorCoordY [0], colorCoordY [1], colorCoordY [2]);
literaY=brdT2-brdCell/2.0f-brdCell*yi;
sprintf (literaText, "%c", literaL [yi]);
glPrintLitera (); }
if (rvOn)
{
rvC+=fpsTweak ();
rvAngle-=360.0f/rvSteps*fpsTweak ();
rvWidth+=rvWstep*fpsTweak ();
if (rvWidth>=rvWmx)
{
rvWidth=rvWmx;
rvWstep*=-1;
}
if (rvC>=rvSteps)
{
for (yi=0; yi<8; yi++)
{
for (xi=0; xi<8; xi++)
{
if (init_d [getPos (xi, yi)]==3)
init_d [getPos (xi, yi)]=1;
else if (init_d [getPos (xi, yi)]==4)
init_d [getPos (xi, yi)]=2;
}
}
rvOn=false;
if (rvSide==1)
turn=8;
else
{
if (isMove ())
{
turn=1;
cellInfo ();
SetCursor (curArrow);
}
else
{
moveOff++;
if (moveOff==2 || cPlayer+cCPU==64)
turnOver ();
else
{
turn=8;
playSound ("break");
}
}
}
}
}
if (turn==4 && toCur) {
toCur=false;
SetCursor (curNew);
}
if (turn==1 && arCur) {
arCur=false;
SetCursor (curArrow);
}
glLoadIdentity (); glEnable (GL_BLEND);
glBindTexture (GL_TEXTURE_2D, texture [8]);
glBegin (GL_QUADS);
int xi, yi, c=0;
for (yi=0; yi<8; yi++)
{
for (xi=0; xi<8; xi++)
{
if (init_d [c]!=0 && !(rvOn && xi==rvX && yi==rvY))
{
if (init_d [c]==1)
glColor3f (colorPlayer [0], colorPlayer [1], colorPlayer [2]);
else if (init_d [c]==2)
glColor3f (colorCPU [0], colorCPU [1], colorCPU [2]);
else if (init_d [c]==3)
glColor3f (colorCPU [0]+(colorPlayer [0]-colorCPU [0])/rvSteps*rvC,
colorCPU [1]+(colorPlayer [1]-colorCPU [1])/rvSteps*rvC,
colorCPU [2]+(colorPlayer [2]-colorCPU [2])/rvSteps*rvC);
else if (init_d [c]==4)
glColor3f (colorPlayer [0]+(colorCPU [0]-colorPlayer [0])/rvSteps*rvC,
colorPlayer [1]+(colorCPU [1]-colorPlayer [1])/rvSteps*rvC,
colorPlayer [2]+(colorCPU [2]-colorPlayer [2])/rvSteps*rvC);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xi*brdCell, brdT2-(yi+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xi+1)*brdCell, brdT2-(yi+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xi+1)*brdCell, brdT2-yi*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xi*brdCell, brdT2-yi*brdCell, brdZ); }
c++;
}
}
float xr=8.1f, yr=0.0f;
glColor3f (colorPlayer [0], colorPlayer [1], colorPlayer [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); yr=1.0f;
glColor3f (colorCPU [0], colorCPU [1], colorCPU [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); glEnd ();
xr=8.1f, yr=3.0f;
glBindTexture (GL_TEXTURE_2D, texture [10]);
glBegin (GL_QUADS);
if (button!=1)
glColor3f (colorRestB [0], colorRestB [1], colorRestB [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); glEnd ();
xr=8.1f, yr=4.0f;
glBindTexture (GL_TEXTURE_2D, texture [11]);
glBegin (GL_QUADS);
if (button!=2)
glColor3f (colorRestB [0], colorRestB [1], colorRestB [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); glEnd ();
xr=8.1f, yr=5.0f;
glBindTexture (GL_TEXTURE_2D, texture [14]);
glBegin (GL_QUADS);
if (button!=3)
glColor3f (colorRestB [0], colorRestB [1], colorRestB [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); glEnd ();
xr=8.1f, yr=6.0f;
glBindTexture (GL_TEXTURE_2D, texture [12]);
glBegin (GL_QUADS);
if (button!=4)
glColor3f (colorRestB [0], colorRestB [1], colorRestB [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); glEnd ();
xr=8.1f, yr=7.0f;
glBindTexture (GL_TEXTURE_2D, texture [9]);
glBegin (GL_QUADS);
if (button!=5)
glColor3f (colorExitB [0], colorExitB [1], colorExitB [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+1)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); glEnd ();
glDisable (GL_BLEND);
glBindTexture (GL_TEXTURE_2D, texture [0]);
xr=8.8f; yr=0.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
literaScale=0.12f;
sprintf (literaText, "%d", cPlayer);
glColor3f (colorPlayerStat [0], colorPlayerStat [1], colorPlayerStat [2]);
glPrintLitera ();
yr=1.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
sprintf (literaText, "%d", cCPU);
glColor3f (colorCPUStat [0], colorCPUStat [1], colorCPUStat [2]);
glPrintLitera (); yr=3.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
sprintf (literaText, "%d", sndVol);
if (button!=1)
glColor3f (colorVol [0], colorVol [1], colorVol [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glPrintLitera (); yr=4.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
sprintf (literaText, "%d", melVol);
if (button!=2)
glColor3f (colorVol [0], colorVol [1], colorVol [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glPrintLitera (); yr=5.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
sprintf (literaText, "%d", AI);
if (button!=3)
glColor3f (colorVol [0], colorVol [1], colorVol [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glPrintLitera (); if (qC!=0)
{
yr=7.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
sprintf (literaText, "%d", qCmx-qC);
if (button!=5)
glColor3f (colorExitT [0], colorExitT [1], colorExitT [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glPrintLitera (); }
if (rvOn)
{
xr=rvX, yr=rvY;
glLoadIdentity (); glEnable (GL_BLEND);
glTranslatef (brdL2+(xr+1)*brdCell-brdCell/2.0f, brdT2-(yr+1)*brdCell+brdCell/2.0f, brdZ);
glRotatef (rvAngle, 0.0f, 0.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, texture [8]);
glBegin (GL_QUADS);
if (rvSide==1)
glColor3f (colorPlayer [0], colorPlayer [1], colorPlayer [2]);
else
glColor3f (colorCPU [0], colorCPU [1], colorCPU [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f+rvWidth), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f+rvWidth), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f+rvWidth), brdCell/2.0f, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f+rvWidth), brdCell/2.0f, 0.0f); glEnd ();
glDisable (GL_BLEND);
}
if (turn==4)
{
glLoadIdentity (); glEnable (GL_BLEND);
glColor4f (0.0f, 0.0f, 0.0f, 0.0f+(90.0f-resultAngle)/180.0f);
glBindTexture (GL_TEXTURE_2D, texture [0]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2, brdB, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdR, brdB, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdR, brdT2, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2, brdT2, brdZ); glEnd ();
glDisable (GL_BLEND);
if (cPlayer>cCPU)
{
literaX=-0.634f;
sprintf (txt, "Выигрыш");
}
else if (cPlayer<cCPU)
{
literaX=-0.734f;
sprintf (txt, "Проигрыш");
}
else
{
literaX=-0.45f;
sprintf (txt, "Ничья");
}
if (resultAngle>0.0f)
resultAngle-=fpsTweak ();
else if (!resultOff)
{
resultAngle=0.0f;
resultOff=true;
if (cPlayer>cCPU)
playSound ("speech_win");
else if (cPlayer<cCPU)
playSound ("speech_lose");
else
playSound ("speech_draw");
}
literaY=-0.082f;
literaScale=0.32f;
sprintf (literaText, "%s", txt);
glColor4f (colorH [0], colorH [1], colorH [2], 0.0f+(90.0f-resultAngle)*1.0f/90.0f);
glPrintLitera (); }
if (button)
{
xr=5.0f;
if (button==1)
{
yr=3.0f;
sprintf (txt, " звук");
}
else if (button==2)
{
yr=4.0f;
sprintf (txt, " мелодия");
}
else if (button==3)
{
yr=5.0f;
sprintf (txt, "сложность");
}
else if (button==4)
{
yr=6.0f;
sprintf (txt, " справка");
}
else if (button==5)
{
yr=7.0f;
sprintf (txt, " выход");
}
glLoadIdentity (); glEnable (GL_BLEND);
glColor4f(1.0, 1.0, 1.0, 0.85f);
glBindTexture (GL_TEXTURE_2D, texture [15]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+xr*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xr+3)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+3)*brdCell, brdT2-yr*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+xr*brdCell, brdT2-yr*brdCell, brdZ); glEnd ();
glDisable (GL_BLEND);
literaY=brdT2-brdCell/2.0f+0.0095f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
literaScale=0.12f;
sprintf (literaText, "%s", txt);
glColor3f (colorCellHL1 [0]/1.5f, colorCellHL1 [1]/1.5f, colorCellHL1 [2]/1.5f);
glPrintLitera (); }
if (infOn)
{
glLoadIdentity (); glEnable (GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glCallList (infList);
glDisable (GL_BLEND);
literaY=0.55f;
literaX=-0.734f;
literaScale=0.32f;
sprintf (literaText, "Repaint");
glColor3f (colorH [0], colorH [1], colorH [2]);
glPrintLitera (); char infTxt [10] [100]={" Задача игры - составлять горизонтальные,",
"вертикальные и диагональные линии.",
"Для этого нужно замыкать своими фишками",
"находящиеся между ними фишки компьютера.",
"Выигрывает тот, кто займёт большую часть",
"доски."
};
xr=-0.25f; yr=1.75f;
glColor3f (colorTxt [0], colorTxt [1], colorTxt [2]);
for (yi=0; yi<6; yi++)
{
literaY=brdT2-brdCell/2.0f-brdCell*(yr+yi*0.5f)-0.0225f;
literaX=brdL2+brdCell/2.0f+brdCell*xr-0.0025f;
literaScale=0.07f;
sprintf (literaText, "%s", infTxt [yi]);
glPrintLitera (); }
xr=-0.25f; yr=1.75f;
literaY=brdT2-brdCell/2.0f-brdCell*(yr+9*0.5f)-0.0025f;
literaX=brdL2+brdCell/2.0f+brdCell*xr-0.0025f;
sprintf (literaText, " Маркичев Д. 2018-2022");
glColor3f (colorTxtB [0], colorTxtB [1], colorTxtB [2]);
glPrintLitera (); }
}
fpsC ();
glEnable (GL_DEPTH_TEST); glPopMatrix ();
SwapBuffers (hDC);
if (turn==8)
turn=2;
}
void mouseMove ()
{
int xi, yi;
if (blur_on)
return;
GetCursorPos (&mypoint);
if (infOn && mypoint.x>=mXar [0]-(mXar [1]-mXar [0]) && mypoint.x<mXar [8] && mypoint.y>=mYar [0]-(mYar [1]-mYar [0]) && mypoint.y<mYar [8])
{
button=0;
SetCursor (curOff);
return;
}
int field=0, fldX=posX, fldY=posY;
for (xi=0; xi<9; xi++)
{
if (mypoint.x>=mXar [xi] && mypoint.x<mXar [xi+1])
{
posX=xi;
field++;
break;
}
}
for (yi=0; yi<9; yi++)
{
if (mypoint.y>=mYar [yi] && mypoint.y<mYar [yi+1])
{
posY=yi;
field++;
break;
}
}
if (field<2)
{
posX=fldX;
posY=fldY;
}
if (posX!=posXl || posY!=posYl)
cellInfo ();
int bL=button;
button=0;
float ri, qi=float(mXar [8]-mXar [7])/25.0f;
if ((mypoint.x>(mXar [8]+(mXar [8]-mXar [7])/10) && mypoint.x<(mXar [8]+(mXar [8]-mXar [7])*11/10)))
{
if (mypoint.y>=mYar [7] && mypoint.y<mYar [8])
{
xi=abs ((float)mypoint.x-((float)mXar [8]+float(mXar [8]-mXar [7])*6.0f/10.0f));
yi=abs ((float)mypoint.y-((float)mYar [7]+float(mYar [8]-mYar [7])*39.0f/40.0f/2.0f));
ri=sqrt (pow (xi, 2)+pow (yi, 2));
if (ri<float(mXar [8]-mXar [7])/2.0f-qi)
button=5;
}
if (mypoint.y>=mYar [6] && mypoint.y<mYar [7])
{
xi=abs ((float)mypoint.x-((float)mXar [8]+float(mXar [8]-mXar [7])*6.0f/10.0f));
yi=abs ((float)mypoint.y-((float)mYar [6]+float(mYar [8]-mYar [7])*39.0f/40.0f/2.0f));
ri=sqrt (pow (xi, 2)+pow (yi, 2));
if (ri<float(mXar [8]-mXar [7])/2.0f-qi)
button=4;
}
if (mypoint.y>=mYar [5] && mypoint.y<mYar [6])
{
xi=abs ((float)mypoint.x-((float)mXar [8]+float(mXar [8]-mXar [7])*6.0f/10.0f));
yi=abs ((float)mypoint.y-((float)mYar [5]+float(mYar [8]-mYar [7])*39.0f/40.0f/2.0f));
ri=sqrt (pow (xi, 2)+pow (yi, 2));
if (ri<float(mXar [8]-mXar [7])/2.0f-qi)
button=3;
}
if (mypoint.y>=mYar [4] && mypoint.y<mYar [5])
{
xi=abs ((float)mypoint.x-((float)mXar [8]+float(mXar [8]-mXar [7])*6.0f/10.0f));
yi=abs ((float)mypoint.y-((float)mYar [4]+float(mYar [8]-mYar [7])*39.0f/40.0f/2.0f));
ri=sqrt (pow (xi, 2)+pow (yi, 2));
if (ri<float(mXar [8]-mXar [7])/2.0f-qi)
button=2;
}
if (mypoint.y>=mYar [3] && mypoint.y<mYar [4])
{
xi=abs ((float)mypoint.x-((float)mXar [8]+float(mXar [8]-mXar [7])*6.0f/10.0f));
yi=abs ((float)mypoint.y-((float)mYar [3]+float(mYar [8]-mYar [7])*39.0f/40.0f/2.0f));
ri=sqrt (pow (xi, 2)+pow (yi, 2));
if (ri<float(mXar [8]-mXar [7])/2.0f-qi)
button=1;
}
}
if (bL!=button && button!=0)
playSound ("select");
if (turn==4)
{
if (mypoint.x>=mXar [0] && mypoint.x<mXar [8] && mypoint.y>=mYar [0] && mypoint.y<mYar [8])
SetCursor (curNew);
}
else if ((rvOn || (turn!=1 && turn!=4)) && !button)
SetCursor (curWait);
}
void mouseClick ()
{
GetCursorPos (&mypoint);
if (infOn && mypoint.x>=mXar [0]-(mXar [1]-mXar [0]) && mypoint.x<mXar [8] && mypoint.y>=mYar [0]-(mYar [1]-mYar [0]) && mypoint.y<mYar [8])
{
infOn=false;
playSound ("shake");
mouseMove ();
return;
}
if (!button)
{
if (turn==4)
{
if (mypoint.x>=mXar [0] && mypoint.x<mXar [8] && mypoint.y>=mYar [0] && mypoint.y<mYar [8])
{
memcpy (init_d, init_p, 64);
playSound ("board");
SetCursor (curArrow);
turn=1;
cPlayer=2;
cCPU=2;
}
}
else
{
if (rvOn || (turn!=1 && turn!=4))
{
SetCursor (curWait);
return;
}
playerMove ();
}
}
else if (button==1)
{
sndVol++;
if (sndVol>4)
sndVol=0;
soundVol=sndVol*250;
if (sndVol!=0)
{
if (sndVol==1)
soundOn=true;
playSound ("turn_on");
}
else
{
soundOn=false;
playSound ("turn_off", 100, 25);
}
}
else if (button==2)
{
melVol++;
if (melVol>4)
melVol=0;
if (melVol==0)
{
meloTurnOff=true;
playSound ("turn_off");
}
else if (melVol==1)
meloTurnOn=true;
if (melVol>0)
playSound ("turn_on");
meloVol=0;
SetTimer (hWnd, TIMER_MELON, 1000, NULL);
}
else if (button==3)
{
AI++;
if (AI>2)
AI=0;
if (AI==0)
playSound ("turn_off");
else
playSound ("turn_on");
}
else if (button==4)
{
if (!infOn)
{
infOn=true;
playSound ("shake");
}
else
{
infOn=false;
playSound ("shake");
}
}
else if (button==5)
{
if (qC==0)
{
qC=1;
playSound ("turn_on");
SetTimer (hWnd, TIMER_QUIT, 1000, NULL);
}
else
{
KillTimer (hWnd, TIMER_QUIT);
qC=0;
playSound ("turn_off");
}
}
}
int getPos (int x, int y)
{
int p;
if (x>-1 && x<8 && y>-1 && y<8)
p=y*8+x;
else
p=0;
return p;
}
void playerMove ()
{
if (posHL)
{
moveOff=0;
memcpy (rv_d, init_d, 64);
reverse (posX, posY, 1, 1);
memcpy (init_d, rv_d, 64);
init_d [getPos (posX, posY)]=1;
rvC=0.0f;
rvX=posX;
rvY=posY;
rvSide=1;
rvAngle=0.0f;
rvWidth=0.0f;
rvWstep=rvWmx*2.0f/rvSteps;
rvOn=true;
SetCursor (curWait);
cCPU-=cMove;
cPlayer+=cMove+1;
char t [16];
sprintf (t, "move%d", (rand ()%5+1));
playSound (t);
cellInfo ();
}
else
playSound ("break");
}
int reverse (int x, int y, int side, int mode)
{
int xi, yi, c, c1, c2, s1, s2, r=0;
if (rv_d [getPos (x, y)]!=0)
return 0;
if (side==1)
{
s1=1;
s2=2;
}
else
{
s1=2;
s2=1;
}
int ar [8] [6]={x+1, 8, 1, y, -1, 0,
x-1, -1, -1, y, -1, 0,
x, -1, 0, y+1, 8, 1,
x, -1, 0, y-1, -1, -1,
x+1, 8, 1, y+1, 8, 1,
x+1, 8, 1, y-1, -1, -1,
x-1, -1, -1, y+1, 8, 1,
x-1, -1, -1, y-1, -1, -1
};
c1=0;
while (c1<8)
{
xi=ar [c1] [0];
yi=ar [c1] [3];
if (!(xi<0 || xi>7 || yi<0 || yi>7))
{
c=0; c2=0;
while ((xi!=ar [c1] [1] || ar [c1] [2]==0) && (yi!=ar [c1] [4] || ar [c1] [5]==0))
{
if (rv_d [getPos (xi, yi)]==0)
break;
else if (rv_d [getPos (xi, yi)]==s1)
{
if (c)
{
c++;
r+=c2;
}
break;
}
else if (rv_d [getPos (xi, yi)]==s2)
{
c=1;
c2++;
}
xi+=ar [c1] [2];
yi+=ar [c1] [5];
}
if (mode!=0 && c==2)
{
xi=ar [c1] [0];
yi=ar [c1] [3];
while ((xi!=ar [c1] [1] || ar [c1] [2]==0) && (yi!=ar [c1] [4] || ar [c1] [5]==0))
{
if (rv_d [getPos (xi, yi)]==s2)
rv_d [getPos (xi, yi)]=(mode==1 ? s1+2 : s1);
else if (rv_d [getPos (xi, yi)]==s1)
break;
xi+=ar [c1] [2];
yi+=ar [c1] [5];
}
}
}
c1++;
}
return r;
}
void cellInfo ()
{
int r;
posXl=posX;
posYl=posY;
memcpy (rv_d, init_d, 64);
cMove=reverse (posX, posY, 1);
if (cMove)
posHL=1;
else
posHL=0;
}
float fpsTweak ()
{
if (!clockTweak)
return 1.0f;
else
return clockD/15.0f;}
void fpsC ()
{
paintC++;
if (clock ()-timeS>=1000)
{
fps=paintC;
paintC=0;
timeS=clock ();
if (fpsOn<10)
fpsOn++;
}
clockTweak=false;
if (clockL!=0)
clockTweak=true;
clockD=(float)clock ()-(float)clockL;
clockL=clock ();
}
void statusBar ()
{
if (fps>-1)
{
literaY=0.75f;
literaX=-0.75f;
literaScale=0.17f;
glColor3f (1.0f, 0.5f, 0.0f);
if (strlen (mb)!=0)
{
glDisable (GL_DEPTH_TEST); sprintf (literaText, "%s", mb);
glPrintLitera (); glEnable (GL_DEPTH_TEST); return;
}
glDisable (GL_DEPTH_TEST); sprintf (literaText, "FPS:%d X:%d Y:%d", fps, posX, posY);
glPrintLitera (); glEnable (GL_DEPTH_TEST); }
}
void loading ()
{
bool fileIs=true;
char url [_MAX_PATH];
int px, py, dx, dy, bx, by, off=55;
sprintf (url, "%s\\data\\textures\\sky.jpg", AppDir);
FILE * file;
file=fopen (url, "r");
if (file==NULL)
fileIs=false;
fclose (file);
if (fileIs==true)
{
WCHAR ts [256];
MultiByteToWideChar (CP_ACP, 0, url, -1, ts, 256);
imagesH=new Gdiplus::Image (ts, true);
px=imagesH->GetWidth ();
if (px>0)
{
py=px; if (cx>cy)
{
off=(sqrt (pow (cx, 2)+pow (cy, 2))-cx)*120/100;
dx=px*cx/(cx+off);
dy=py*dx/px*cy/cx;
bx=(px-dx)/2;
by=(py-dy)/2;
}
else
{
off=(sqrt (pow (cx, 2)+pow (cy, 2))-cy)*120/100;
dy=py*cy/(cy+off);
dx=px*dy/py*cx/cy;
by=(py-dy)/2;
bx=(px-dx)/2;
}
hDC=GetDC (hWnd);
gDC=new Gdiplus::Graphics (hDC);
gDC->SetPageUnit(Gdiplus::UnitPixel);
gDC->SetCompositingMode(Gdiplus::CompositingModeSourceCopy);
gDC->SetCompositingQuality(Gdiplus::CompositingQualityAssumeLinear);
gDC->SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
gDC->SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
gDC->SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
Gdiplus::RectF bounds(0, 0, cx, cy);
Gdiplus::ImageAttributes attr;
attr.SetWrapMode(Gdiplus::WrapModeTile);
gDC->DrawImage (imagesH, bounds, bx, by, dx, dy, Gdiplus::UnitPixel, &attr);
DeleteObject (&attr);
DeleteObject (&bounds);
ReleaseDC (hWnd, hDC);
delete imagesH;
}
}
}
void saveConf()
{
FILE *file;
int i;
char conf [1024];
sprintf (conf, "Sound:%d\r\nMelody:%d\r\nAI:%d\r\n",
sndVol, melVol, AI);
char path [_MAX_PATH];
sprintf (path, "%s%s", AppDir, "data\\config.txt");
file=fopen (path, "wb");
if (file!=NULL)
{
fwrite (conf, 1, strlen (conf), file);
fclose (file);
}
}
void loadConf ()
{
FILE *file;
int i, i2, n=0, n2, fS, confMx=1024, parMx=32, parL;
char conf [1024], par [32], par0 [32], par1 [32];
memset (conf, 0, confMx);
char path [_MAX_PATH];
sprintf (path, "%s%s", AppDir, "data\\config.txt");
file=fopen (path, "rb");
if (file!=NULL)
{
fseek (file, 0, SEEK_END); fS=ftell (file); fseek (file, 0, SEEK_SET); if (fS<confMx-2)
fread (conf, 1, fS, file);
else
fread (conf, 1, confMx-2, file);
fclose (file);
}
strcat (conf, "\n");
for (i2=0; i2<strlen (conf); i2++)
{
if (conf [i2]!='\n' && conf [i2]!='\r')
break;
}
n=i2;
for (i=n; i<strlen (conf); i++)
{
if (conf [i]=='\n' || conf [i]=='\r')
{
memset (par, 0, parMx);
for (i2=n; i2<i; i2++)
par [i2-n]=conf [i2];
for (i2=i+1; i2<strlen (conf); i2++)
{
if (conf [i2]!='\n' && conf [i2]!='\r')
break;
}
n=i2;
i=i2;
parL=strlen (par);
if (parL>parMx)
parL=parMx;
memset (par0, 0, parMx);
memset (par1, 0, parMx);
n2=0;
for (i2=0; i2<parL; i2++)
{
if (par [i2]==':')
{
n2=i2;
break;
}
}
if (n2)
{
memcpy (par0, par, i2);
for (i2=n2+1; i2<parL; i2++)
par1 [i2-n2-1]=par [i2];
}
if (!strcmp (par0, "Sound"))
{
sndVol=atoi (par1);
soundVol=sndVol*250;
if (soundVol>1000)
soundVol=1000;
if (soundVol<0)
soundVol=0;
if (soundVol)
soundOn=true;
else
soundOn=false;
}
else if (!strcmp (par0, "Melody"))
{
melVol=atoi (par1);
meloVol=melVol*250;
if (meloVol>1000)
meloVol=1000;
if (meloVol<0)
meloVol=0;
if (meloVol)
meloIs=true;
else
meloIs=false;
}
else if (!strcmp (par0, "AI"))
{
AI=atoi (par1);
if (AI!=0 && AI!=1 && AI!=2)
AI=1;
}
}
}
}