#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 light_pos;
int light_d;
int state=0, sel_x=-1, sel_y=-1, sel_x0=-1, sel_y0=-1;
int leap_x=0, leap_y=0;
char piece [2], draw_move [2];
float move_sx, move_sy, move_sa=0.15f, move_saB;
bool move1=false;
float new_sa=0.025f, new_s;
float off_sa=0.025f, off_s;
int cQ=5;
float cq=1.0f, ca=0.005f, cl=1.0f;
int leaps_c=-1, leaps_n=0;
int leaps_x [100];
int leaps_y [100];
int leaps_x1 [100];
int leaps_y1 [100];
char board3x [1000] [81];
int move_x1, move_y1, move_x2, move_y2;
int lang=0;int sleepTime=50;
float bgAngle=0.0f;
float pLoad=150.0f, pLoad0=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;
float rvSteps=255.0f/1.0f;
float rvH;
int rvDir=1;
bool messOn=false;
int mess=0;
float messStep=1.5f;
float messState;
bool messAfter=false;
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];
long cMoves=0, cScore=0, cPlace1=0, cPlace2=0, cPlace3=0, cFin=0, cRestart=0, cNotfin=0;
bool pl1=false, pl2=false, pl3=false;
char speech1 [8], speech2 [8], speech [16];
bool drawPieces=false;
int button=0;
float colors [7] [3]={0.94f, 0.0f, 0.0f,
1.0f, 0.82f, 0.0f,
0.5f, 0.3f, 0.1f,
0.0f, 0.7f, 0.0f,
0.07f, 0.07f, 0.9f,
0.1f, 0.83f, 0.85f,
0.95f, 0.39f, 0.88f};
float colorRec [4]={1.0f, 0.5f, 0.0f};
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},
colorCellHL2 [4]={0.0f, 0.75f, 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},
colorVol [4]={0.95f, 0.8f, 0.1f}, colorExitT [4]={0.85f, 0.0f, 0.0f},
colorOff [4]={0.85f, 0.85f, 0.85f}, colorOn [4]={0.0f, 1.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 txt [16];
bool resultOff;
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;
int infOn=0;
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);
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;
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 [81];
char szClassName []="OpenGL App";
char title []="LinesGL";
char init_d [81];
char d_off [81];
char d_init [81];
char init_p [81]={
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,
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,
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
};
void paint ();
void mouseMove ();
void mouseClick ();
int getPos (int x, int y);
void cellInfo ();
void windowUp ();
void playerMove ();
bool check_pick (int x, int y);
void newBoard ();
void newQ (int q);
void newOff (int q);
void cCells ();
bool offBoard (int x, int y);
void Restart ();
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);
newBoard ();
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);
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=0;
playSound ("shake");
mouseMove ();
}
break;
case VK_RIGHT:
infOn=0;
if (posX<7)
{
posX++;
cellInfo ();
}
break;
case VK_LEFT:
infOn=0;
if (posX>0)
{
posX--;
cellInfo ();
}
break;
case VK_NEXT:
infOn=0;
if (posX<7 && posY<7)
{
posX++;
posY++;
cellInfo ();
}
break;
case VK_PRIOR:
infOn=0;
if (posX<7 && posY>0)
{
posX++;
posY--;
cellInfo ();
}
break;
case VK_UP:
infOn=0;
if (posY>0)
{
posY--;
cellInfo ();
}
break;
case VK_DOWN:
infOn=0;
if (posY<7)
{
posY++;
cellInfo ();
}
break;
case VK_HOME:
infOn=0;
if (posX>0 && posY>0)
{
posX--;
posY--;
cellInfo ();
}
break;
case VK_END:
infOn=0;
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;
infOn=0;
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);
}
}
bool offBoard (int x, int y)
{
bool r=false;
int tx, ty, q, qc=0, col;
col=d_off [getPos (x, y)];
q=1;
ty=y;
for (tx=x+1; tx<9; tx++)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
}
for (tx=x-1; tx>-1; tx--)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
}
if (q>4)
{
for (tx=x+1; tx<9; tx++)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
}
for (tx=x-1; tx>-1; tx--)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
}
r=true;
qc++;
cScore+=q*10;
}
q=1;
tx=x;
for (ty=y+1; ty<9; ty++)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
}
for (ty=y-1; ty>-1; ty--)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
}
if (q>4)
{
for (ty=y+1; ty<9; ty++)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
}
for (ty=y-1; ty>-1; ty--)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
}
r=true;
qc++;
cScore+=q*10;
}
q=1;
ty=y+1;
for (tx=x+1; tx<9; tx++)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
ty++;
if (ty>8)
break;
}
ty=y-1;
for (tx=x-1; tx>-1; tx--)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
ty--;
if (ty<0)
break;
}
if (q>4)
{
ty=y+1;
for (tx=x+1; tx<9; tx++)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
ty++;
if (ty>8)
break;
}
ty=y-1;
for (tx=x-1; tx>-1; tx--)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
ty--;
if (ty<0)
break;
}
r=true;
qc++;
cScore+=q*10;
}
q=1;
ty=y-1;
for (tx=x+1; tx<9; tx++)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
ty--;
if (ty<0)
break;
}
ty=y+1;
for (tx=x-1; tx>-1; tx--)
{
if (d_off [getPos (tx, ty)]==col)
q++;
else
break;
ty++;
if (ty>8)
break;
}
if (q>4)
{
ty=y-1;
for (tx=x+1; tx<9; tx++)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
ty--;
if (ty<0)
break;
}
ty=y+1;
for (tx=x-1; tx>-1; tx--)
{
if (d_off [getPos (tx, ty)]==col)
d_off [getPos (tx, ty)]=10;
else
break;
ty++;
if (ty>8)
break;
}
r=true;
qc++;
cScore+=q*10;
}
bool speak=false;
if (r)
{
d_off [getPos (x, y)]=10;
if (cScore>cPlace1 && !pl1)
{
sprintf (speech2, "rec");
pl1=true;
pl2=true;
pl3=true;
speak=true;
mess=1;
}
else if (cScore>cPlace2 && !pl2)
{
sprintf (speech2, "2nd");
pl2=true;
pl3=true;
speak=true;
mess=2;
}
else if (cScore>cPlace3 && !pl3)
{
sprintf (speech2, "3rd");
pl3=true;
speak=true;
mess=3;
}
}
if (speak)
{
messOn=true;
messState=255.0f;
if (lang==0)
sprintf (speech1, "ru_");
else
sprintf (speech1, "en_");
sprintf (speech, "%s%s", speech1, speech2);
playSound (speech);
}
else
{
if (qc>1)
playSound ("off2");
else if (qc>0)
playSound ("off1");
}
return r;
}
bool score_done=false;
void Score ()
{
if (score_done)
return;
score_done=true;
if (pl1)
{
cPlace3=cPlace2;
cPlace2=cPlace1;
cPlace1=cScore;
}
else if (pl2)
{
cPlace3=cPlace2;
cPlace2=cScore;
}
else if (pl3)
{
cPlace3=cScore;
}
}
char nCols [3]={0, 0, 0};
void nextColors ()
{
int i;
for (i=0; i<3; i++)
nCols [i]=rand()%7+1;
}
int nPos [5] [2], nXY [81] [2], tXY [81] [2];
int newMx;
void newQ (int q)
{
int i, i2, x, y, c=0, c2=0, c3;
for (y=0; y<9; y++)
{
for (x=0; x<9; x++)
{
if (init_d [c]==0)
{
nXY [c2] [0]=x;
nXY [c2] [1]=y;
c2++;
}
c++;
}
}
int f;
newMx=q;
if (q>c2)
newMx=c2;
for (i=0; i<newMx; i++)
{
f=rand()%c2;
nPos [i] [0]=nXY [f] [0];
nPos [i] [1]=nXY [f] [1];
for (i2=0; i2<c2; i2++)
{
tXY [i2] [0]=nXY [i2] [0];
tXY [i2] [1]=nXY [i2] [1];
}
c3=0;
for (i2=0; i2<c2; i2++)
{
if (i2!=f)
{
nXY [c3] [0]=tXY [i2] [0];
nXY [c3] [1]=tXY [i2] [1];
c3++;
}
}
c2=c3;
}
}
void newOff (int q)
{
char d_ar [5] [81];
memcpy (d_init, init_d, 81);
int i, i2, c=0, c2;
for (i=0; i<q; i++)
{
memcpy (d_off, init_d, 81);
if (offBoard (nPos [i] [0], nPos [i] [1]))
{
memcpy (d_ar [c], d_off, 81);
c++;
}
}
if (c>0)
{
memcpy (d_off, init_d, 81);
for (i=0; i<c; i++)
{
c2=0;
for (i2=0; i2<81; i2++)
{
if (d_ar [i] [i2]==10)
{
d_off [i2]=10;
init_d [i2]=0;
}
}
}
off_s=1.0f;
state=4;
}
}
void newBoard ()
{
int i;
memset (init_d, 0, 81);
newQ (5);
for (i=0; i<5; i++)
init_d [getPos (nPos [i] [0], nPos [i] [1])]=rand()%7+1;
newOff (5);
nextColors ();
}
void cCells ()
{
int i;
cQ=0;
for (i=0; i<81; i++)
{
if (init_d [i]!=0)
cQ++;
}
}
void Restart ()
{
move1=false;
sel_x0=-1;
sel_y0=-1;
sel_x=-1;
sel_y=-1;
Score ();
cScore=0;
score_done=false;
resultOff=false;
pl1=false;
pl2=false;
pl3=false;
if (state<10)
cRestart++;
cQ=5;
state=0;
newBoard ();
infOn=0;
playSound ("board");
}
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); glDisable (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=-1; i<9; i++)
mXar0 [i+1]=cx/2-(float)cy*4.5f/9.0f+cy*i/9;
for (i=-1; i<9; i++)
mYar0 [i+1]=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=dmBs; 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 ; int ave, inc, alf;
char texs [25] [32]={"blank.gif", "bar.jpg", "",
"", "bg.jpg",
"tooltip.jpg", "sky.jpg",
"", "lits.jpg"
};
char texd [16]={"data\\textures"};
char txt [_MAX_PATH];
int i2, xi, yi, cl, ri;
for (i2=0; i2<9; i2++)
{
if (strlen (texs [i2])==0)
{
}
else if (i2==1 || i2==8) {
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==1)
{
lWidthPixels=256;
lHeightPixels=256;
lWidth2=gWidth;
lHeight2=gHeight;
}
else if (i2==8)
{
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==1)
{
i3from=0;
i3to=10;
rows=1;
}
for (i3=i3from; i3<i3to; i3++)
{
if (!(i2==8 && i3>126 && i3<161))
{
i3x=i3;
if (i2==1)
{
if (xi2==0)
i3x=2;
else if (xi2==1)
i3x=1;
else if (xi2==2)
i3x=16;
else if (xi2==3)
i3x=17;
else if (xi2==4)
i3x=10;
else if (xi2==5)
i3x=11;
else if (xi2==6)
i3x=14;
else if (xi2==7)
i3x=12;
else if (xi2==8)
i3x=9;
else if (xi2==9)
i3x=19;
}
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==1 && xi2==0)
{
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==1 && 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==1 && xi2==9)
{
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==1)
{
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==8)
{
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]); 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==8 && xi2>=rows)
{
xi2=0;
yi2++;
}
}
}
DeleteObject (hbmpTemp); DeleteDC (hdcTemp); pPicture->Release(); }
}
}
}
else
{
int i2x=i2;
if (i2==4)
i2x=13;
else if (i2==5)
i2x=15;
else if (i2==6)
i2x=18;
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;
if (i2x==8)
{
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
{
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, dmBs, 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);
glNormal3f (0.0f, 0.0f, 1.0f);
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;
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 (5); 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 [18]);
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;
}
bool xy_check (int x, int y)
{
if (x>=0 && x<=8 && y>=0 && y<=8)
return true;
else
return false;
}
bool check_any (char d [81], int x, int y)
{
if (d [getPos (x, y)]==0)
return false;
int ca_ar [8]={-1,0, 0,-1, 1,0, 0,1};
int i, tx, ty;
for (i=0; i<4; i++)
{
tx=x+ca_ar [i*2];
ty=y+ca_ar [i*2+1];
if (xy_check (tx, ty))
{
if (d [getPos (tx, ty)]==0)
return true;
}
}
return false;
}
void leaps (int x1, int y1, int x2, int y2)
{
char d2 [81];
int i, c, n=0, tx1, ty1;
int ar_x [100], ar_y [100], ar_parent [100];
memcpy (d2, init_d, 81);
c=0;
ar_x [c]=x1;
ar_y [c]=y1;
d2 [getPos (x1, y1)]=8;
d2 [getPos (x2, y2)]=0;
for (i=0; i<=c; i++)
{
tx1=ar_x [i];
ty1=ar_y [i];
if (tx1<8)
{
if ( d2 [getPos (tx1+1, ty1)]==0 )
{
c++;
ar_x [c]=tx1+1;
ar_y [c]=ty1;
ar_parent [c]=i;
d2 [getPos (tx1+1, ty1)]=8;
if ( (tx1+1)==x2 && ty1==y2 )
{
n=c;
break;
}
}
}
if (tx1>0)
{
if ( d2 [getPos (tx1-1, ty1)]==0 )
{
c++;
ar_x [c]=tx1-1;
ar_y [c]=ty1;
ar_parent [c]=i;
d2 [getPos (tx1-1, ty1)]=8;
if ( (tx1-1)==x2 && ty1==y2 )
{
n=c;
break;
}
}
}
if (ty1<8)
{
if ( d2 [getPos (tx1, ty1+1)]==0 )
{
c++;
ar_x [c]=tx1;
ar_y [c]=ty1+1;
ar_parent [c]=i;
d2 [getPos (tx1, ty1+1)]=8;
if ( tx1==x2 && (ty1+1)==y2 )
{
n=c;
break;
}
}
}
if (ty1>0)
{
if ( d2 [getPos (tx1, ty1-1)]==0 )
{
c++;
ar_x [c]=tx1;
ar_y [c]=ty1-1;
ar_parent [c]=i;
d2 [getPos (tx1, ty1-1)]=8;
if ( tx1==x2 && (ty1-1)==y2 )
{
n=c;
break;
}
}
}
}
leaps_c=-1;
if (n!=0)
{
for (i=c; i>=0; i--)
{
if (i==n)
{
leaps_c++;
leaps_x [leaps_c]=ar_x [i];
leaps_y [leaps_c]=ar_y [i];
n=ar_parent [i];
}
}
int i2=-1;
for (i=leaps_c-1; i>=0; i--)
{
i2++;
leaps_x1 [i2]=leaps_x [i];
leaps_y1 [i2]=leaps_y [i];
}
leaps_c=i2;
}
leaps_n=0;
}
bool check_move (int tx, int ty)
{
leaps (sel_x0, sel_y0, tx, ty);
if (leaps_c>-1)
return true;
return false;
}
void paint ()
{
if (pC<10 && !(pLoad>0.0f))
pC++;
glPushMatrix ();
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
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;
cq=(float)(86-cQ)/(float)81;
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 ()*3;
glTranslatef (0.0f, 0.0f, loadFar);
glRotatef (-loadAngle, 0.0f, 0.0f, 1.0f);
loadFar+=loadFarStep*fpsTweak ()*3;
loadAngle+=loadAngleStep*fpsTweak ()*3;
SetCursor (curWait);
glEnable (GL_BLEND);
}
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=1;
for (yi=0; yi<9; yi++)
{
c+=2;
for (xi=0; xi<9; xi++)
{
c++;
if (c%2)
{
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+(xi-1)*brdCell, brdT2-(yi+0)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xi+0)*brdCell, brdT2-(yi+0)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xi+0)*brdCell, brdT2-(yi-1)*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+(xi-1)*brdCell, brdT2-(yi-1)*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;
if (xs<0)
xs=0;
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==9)
break;
}
}
}
if (c==9)
{
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<10; i++)
{
mxd=abs (mXar1 [i]-mXar0 [i]);
if (mxd>mx)
mx=mxd;
}
if (mx<25)
{
for (i=0; i<10; i++)
mXar [i]=mXar1 [i];
}
else
{
for (i=0; i<10; i++)
mXar [i]=mXar0 [i];
}
ys=0; 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==9)
break;
}
}
}
if (c==9)
{
mYar1 [c]=cy;
for (i=yi+10; i<cy+10; i++)
{
pixel=GetPixel (hDC, xs, i);
if (!isWhite (pixel))
{
mYar1 [c]=i;
break;
}
}
}
for (i=0; i<10; i++)
{
mxd=abs (mYar1 [i]-mYar0 [i]);
if (mxd>mx)
mx=mxd;
}
if (mx<25)
{
for (i=0; i<10; i++)
mYar [i]=mYar1 [i];
}
else
{
for (i=0; i<10; i++)
mYar [i]=mYar0 [i];
}
mouseMove ();
SetTimer (hWnd, TIMER_MEL, 1000, NULL);
playSound ("board");
SetCursor (curArrow);
}
if (pC>1)
{
if (state>1)
glColor3f (colorCellOff [0], colorCellOff [1], colorCellOff [2]);
else if (posHL==1)
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
else if (posHL==2)
glColor3f (colorCellHL2 [0], colorCellHL2 [1], colorCellHL2 [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-1)*brdCell, brdT2-(posY+0)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(posX+0)*brdCell, brdT2-(posY+0)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(posX+0)*brdCell, brdT2-(posY-1)*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+(posX-1)*brdCell, brdT2-(posY-1)*brdCell, brdZ); glEnd ();
if (state==1 || state==2)
{
if (state==2)
rvDir=-1;
rvH+=brdCell*rvDir/rvSteps*fpsTweak ();
if (rvH>brdCell/10.0f)
{
rvH=brdCell/10.0f;
rvDir*=-1;
}
else if (rvH<0.0f)
{
rvH=0.0f;
rvDir*=-1;
}
}
glLoadIdentity (); glEnable (GL_BLEND);
int xi, yi, c=0;
for (yi=0; yi<9; yi++)
{
for (xi=0; xi<9; xi++)
{
if (init_d [c]>0 && init_d [c]<8 && !(xi==sel_x0 && yi==sel_y0 && (state==1 || state==2)))
{
glBindTexture (GL_TEXTURE_2D, texture [19]);
glColor3f (colors [init_d [c]-1] [0], colors [init_d [c]-1] [1], colors [init_d [c]-1] [2]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (brdL2+(xi-1)*brdCell, brdT2-(yi+0)*brdCell, brdZ); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdL2+(xi+0)*brdCell, brdT2-(yi+0)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xi+0)*brdCell, brdT2-(yi-1)*brdCell, brdZ); glTexCoord2f (0.0f, 1.0f); glVertex3f (brdL2+(xi-1)*brdCell, brdT2-(yi-1)*brdCell, brdZ); glEnd ();
}
c++;
}
}
float xr=8.1f, yr=-1.0f;
glLoadIdentity (); glTranslatef (brdL2+(xr+1)*brdCell-brdCell/2.0f, brdT2-(yr+1)*brdCell+brdCell/2.0f, brdZ);
glBindTexture (GL_TEXTURE_2D, texture [19]);
glColor3f (colors [nCols [0]-1] [0], colors [nCols [0]-1] [1], colors [nCols [0]-1] [2]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f), brdCell/2.0f, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f), brdCell/2.0f, 0.0f); glEnd ();
yr=0.0f;
glLoadIdentity (); glTranslatef (brdL2+(xr+1)*brdCell-brdCell/2.0f, brdT2-(yr+1)*brdCell+brdCell/2.0f, brdZ);
glBindTexture (GL_TEXTURE_2D, texture [19]);
glColor3f (colors [nCols [1]-1] [0], colors [nCols [1]-1] [1], colors [nCols [1]-1] [2]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f), brdCell/2.0f, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f), brdCell/2.0f, 0.0f); glEnd ();
xr=8.975f; yr=-0.5f;
glLoadIdentity (); glTranslatef (brdL2+(xr+1)*brdCell-brdCell/2.0f, brdT2-(yr+1)*brdCell+brdCell/2.0f, brdZ);
glBindTexture (GL_TEXTURE_2D, texture [19]);
glColor3f (colors [nCols [2]-1] [0], colors [nCols [2]-1] [1], colors [nCols [2]-1] [2]);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f), brdCell/2.0f, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f), brdCell/2.0f, 0.0f); glEnd ();
xr=8.1f;
glLoadIdentity (); xr=8.1f, yr=1.0f;
glBindTexture (GL_TEXTURE_2D, texture [16]);
glBegin (GL_QUADS);
if (button!=1)
{
if (state==12)
glColor3f (colorOn [0], colorOn [1], colorOn [2]);
else
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=2.0f;
glBindTexture (GL_TEXTURE_2D, texture [17]);
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=3.0f;
glBindTexture (GL_TEXTURE_2D, texture [10]);
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=4.0f;
glBindTexture (GL_TEXTURE_2D, texture [11]);
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=5.0f;
glBindTexture (GL_TEXTURE_2D, texture [14]);
glBegin (GL_QUADS);
if (button!=5)
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!=6)
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!=7)
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);
xr=8.8f; yr=-1.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
literaScale=0.12f;
yr=2.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
if (lang==0)
sprintf (literaText, "Ru");
else if (lang==1)
sprintf (literaText, "En");
if (button!=2)
glColor3f (colorVol [0], colorVol [1], colorVol [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glPrintLitera (); yr=3.0f;
literaY=brdT2-brdCell/2.0f-brdCell*yr;
literaX=brdL2+brdCell/2.0f+brdCell*xr;
sprintf (literaText, "%d", sndVol*25);
if (button!=3)
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*25);
if (button!=4)
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!=7)
glColor3f (colorExitT [0], colorExitT [1], colorExitT [2]);
else
glColor3f (colorCellHL1 [0], colorCellHL1 [1], colorCellHL1 [2]);
glPrintLitera (); }
if (state==1)
{
xr=sel_x0;
yr=sel_y0;
glLoadIdentity (); glEnable (GL_BLEND);
glTranslatef (brdL2+(xr+0)*brdCell-brdCell/2.0f, brdT2-(yr+0)*brdCell+brdCell/2.0f, brdZ);
glBindTexture (GL_TEXTURE_2D, texture [19]);
glBegin (GL_QUADS);
glColor3f (colors [init_d [getPos (xr, yr)]-1] [0], colors [init_d [getPos (xr, yr)]-1] [1], colors [init_d [getPos (xr, yr)]-1] [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f), -brdCell/2.0f+rvH, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f), -brdCell/2.0f+rvH, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f), brdCell/2.0f-rvH, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f), brdCell/2.0f-rvH, 0.0f); glEnd ();
glDisable (GL_BLEND);
}
else if (state==4)
{
off_s-=off_sa*fpsTweak ();
if (off_s<0.0f)
off_s=0.0f;
int x, y;
for (y=0; y<9; y++)
{
for (x=0; x<9; x++)
{
if (d_off [getPos (x, y)]==10)
{
xr=x;
yr=y;
glLoadIdentity (); glEnable (GL_BLEND);
glTranslatef (brdL2+(xr+0)*brdCell-brdCell/2.0f, brdT2-(yr+0)*brdCell+brdCell/2.0f, brdZ);
glBindTexture (GL_TEXTURE_2D, texture [19]);
glBegin (GL_QUADS);
glColor4f (colors [d_init [getPos (x, y)]-1] [0], colors [d_init [getPos (x, y)]-1] [1], colors [d_init [getPos (x, y)]-1] [2], off_s);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f), brdCell/2.0, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f), brdCell/2.0f, 0.0f); glEnd ();
glDisable (GL_BLEND);
}
}
}
if (off_s==0.0f)
{
cCells ();
if (cQ==0)
{
newQ (3);
new_s=0.0f;
state=5;
}
else
{
state=0;
SetCursor (curArrow);
cellInfo ();
}
}
}
else if (state==5)
{
new_s+=new_sa*fpsTweak ();
if (new_s>1.0f)
new_s=1.0f;
int i;
for (i=0; i<newMx; i++)
{
xr=nPos [i] [0];
yr=nPos [i] [1];
glLoadIdentity (); glEnable (GL_BLEND);
glTranslatef (brdL2+(xr+0)*brdCell-brdCell/2.0f, brdT2-(yr+0)*brdCell+brdCell/2.0f, brdZ);
glBindTexture (GL_TEXTURE_2D, texture [19]);
glBegin (GL_QUADS);
glColor4f (colors [nCols [i]-1] [0], colors [nCols [i]-1] [1], colors [nCols [i]-1] [2], new_s);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f), -brdCell/2.0f, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f), brdCell/2.0, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f), brdCell/2.0f, 0.0f); glEnd ();
glDisable (GL_BLEND);
}
if (new_s==1.0f)
{
for (i=0; i<newMx; i++)
init_d [getPos (nPos [i] [0], nPos [i] [1])]=nCols [i];
newOff (3);
nextColors ();
if (state!=4)
{
bool again=true;
for (i=0; i<81; i++)
{
if (init_d [i]==0)
again=false;
}
if (again)
{
cFin++;
Score ();
messState=0.0f;
messAfter=false;
state=10;
}
else
{
cCells ();
state=0;
SetCursor (curArrow);
cellInfo ();
}
}
}
}
else if (state==2)
{
int sel_x1, sel_y1, sel_x10, sel_y10;
char tmp [1]={init_d [getPos (sel_x0, sel_y0)]};
if (leaps_c>-1)
{
sel_x1=(float)leaps_x1 [leaps_n];
sel_y1=(float)leaps_y1 [leaps_n];
if (leaps_c>0 && leaps_n>0)
{
sel_x10=(float)leaps_x1 [leaps_n-1];
sel_y10=(float)leaps_y1 [leaps_n-1];
}
else
{
sel_x10=(float)sel_x0;
sel_y10=(float)sel_y0;
}
}
else
{
sel_x1=(float)sel_x;
sel_y1=(float)sel_y;
sel_x10=(float)sel_x0;
sel_y10=(float)sel_y0;
}
if (sel_x1>sel_x10)
{
move_sx+=move_sa*fpsTweak ();
if (move_sx>=(float)sel_x1)
move_sx=(float)sel_x1;
}
else
{
move_sx-=move_sa*fpsTweak ();
if (move_sx<=(float)sel_x1)
move_sx=(float)sel_x1;
}
if (sel_y1>sel_y10)
{
move_sy+=move_sa*fpsTweak ();
if (move_sy>=(float)sel_y1)
move_sy=(float)sel_y1;
}
else
{
move_sy-=move_sa*fpsTweak ();
if (move_sy<=(float)sel_y1)
move_sy=(float)sel_y1;
}
if (move_sx==(float)sel_x1 && move_sy==(float)sel_y1)
{
if (leaps_n<leaps_c)
leaps_n++;
else
{
char t [16];
if ((abs(sel_x-sel_x0)==1 && abs(sel_y-sel_y0)==0) || (abs(sel_x-sel_x0)==0 && abs(sel_y-sel_y0)==1))
sprintf (t, "dash");
else
sprintf (t, "move%d", (rand ()%5+1));
playSound (t);
cMoves++;
move1=true;
init_d [getPos (sel_x, sel_y)]=init_d [getPos (sel_x0, sel_y0)];
init_d [getPos (sel_x0, sel_y0)]=0;
memcpy (d_off, init_d, 81);
memcpy (d_init, init_d, 81);
if (offBoard (sel_x, sel_y))
{
int c;
for (c=0; c<81; c++)
{
if (d_off [c]==10)
init_d [c]=0;
}
off_s=1.0f;
state=4;
}
else
{
newQ (3);
new_s=0.0f;
state=5;
}
}
}
xr=move_sx;
yr=move_sy;
glLoadIdentity (); glEnable (GL_BLEND);
glTranslatef (brdL2+(xr+0)*brdCell-brdCell/2.0f, brdT2-(yr+0)*brdCell+brdCell/2.0f, brdZ);
glBindTexture (GL_TEXTURE_2D, texture [19]);
glBegin (GL_QUADS);
glColor3f (colors [tmp [0]-1] [0], colors [tmp [0]-1] [1], colors [tmp [0]-1] [2]);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-brdCell/(2.0f), -brdCell/2.0f+rvH, 0.0f); glTexCoord2f (1.0f, 0.0f); glVertex3f (brdCell/(2.0f), -brdCell/2.0f+rvH, 0.0f); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdCell/(2.0f), brdCell/2.0f-rvH, 0.0f); glTexCoord2f (0.0f, 1.0f); glVertex3f (-brdCell/(2.0f), brdCell/2.0f-rvH, 0.0f); glEnd ();
glDisable (GL_BLEND);
}
if (messOn && state<10)
{
messState-=messStep*fpsTweak ();
if (messState<0.0f)
messOn=false;
else
{
glLoadIdentity (); if (lang==0)
{
if (mess==1)
{
literaX=-0.717f;
sprintf (txt, "Рекорд!");
}
else if (mess==2)
{
literaX=-0.788f;
sprintf (txt, "2 место!");
}
else if (mess==3)
{
literaX=-0.788f;
sprintf (txt, "3 место!");
}
}
else
{
if (mess==1)
{
literaX=-0.716f;
sprintf (txt, "Record!");
}
else if (mess==2)
{
literaX=-0.788f;
sprintf (txt, "2 place!");
}
else if (mess==3)
{
literaX=-0.788f;
sprintf (txt, "3 place!");
}
}
literaY=-0.082f;
literaScale=0.32f;
sprintf (literaText, "%s", txt);
glColor4f (colorRec [0], colorRec [1], colorRec [2], messState/255.0f);
glPrintLitera (); }
}
if (state==10 || state==12)
{
glLoadIdentity (); glEnable (GL_BLEND);
if (messAfter)
glColor4f (1.0f, 1.0f, 1.0f, 0.65f);
else
glColor4f (1.0f, 1.0f, 1.0f, 0.0f+0.65f*(messState/255.0f));
glCallList (infList);
glDisable (GL_BLEND);
if (lang==0)
{
literaX=-0.471f;
sprintf (txt, "Ещё?");
}
else
{
literaX=-0.556f;
sprintf (txt, "More?");
}
if (!resultOff)
{
resultOff=true;
if (lang==0)
sprintf (speech1, "ru_");
else
sprintf (speech1, "en_");
sprintf (speech2, "over");
sprintf (speech, "%s%s", speech1, speech2);
playSound (speech);
SetCursor (curNew);
light_pos=0.65f;
light_d=1;
state=12;
}
literaY=-0.082f;
literaScale=0.32f;
sprintf (literaText, "%s", txt);
if (messAfter)
{
GLfloat LightDiffuse []={colorH [0]*1.5f, colorH [1]*1.5f, colorH [2]*0.5f, light_pos*1.5f}; GLfloat LightPosition []={light_pos, light_pos, -light_pos, 1.0f}; light_pos+=light_d*0.01f*fpsTweak ();
if (light_pos>1.0f)
{
light_d=-1;
light_pos=1.0f;
}
else if (light_pos<0.0f)
{
light_d=1;
light_pos=0.0f;
}
glLightfv (GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv (GL_LIGHT1, GL_POSITION, LightPosition); glEnable (GL_LIGHT1); glEnable (GL_LIGHTING); glColor4f (colorH [0], colorH [1], colorH [2], 1.0f);
glPrintLitera (); glDisable (GL_LIGHTING); }
else
{
messState+=messStep*fpsTweak ();
if (messState>255.0f)
{
messState=255.0f;
messAfter=true;
}
glColor4f (colorH [0], colorH [1], colorH [2], messState/255.0f);
glPrintLitera (); }
}
if (button)
{
if (button==1)
{
yr=1.0f;
if (lang==0)
sprintf (txt, " сначала");
else
sprintf (txt, " restart");
}
else if (button==2)
{
yr=2.0f;
if (lang==0)
sprintf (txt, " язык");
else
sprintf (txt, " language");
}
else if (button==3)
{
yr=3.0f;
if (lang==0)
sprintf (txt, " звук");
else
sprintf (txt, " sound");
}
else if (button==4)
{
yr=4.0f;
if (lang==0)
sprintf (txt, " мелодия");
else
sprintf (txt, " melody");
}
else if (button==5)
{
yr=5.0f;
if (lang==0)
sprintf (txt, " достижения");
else
sprintf (txt, "achievements");
}
else if (button==6)
{
yr=6.0f;
if (lang==0)
sprintf (txt, " о программе");
else
sprintf (txt, " about");
}
else if (button==7)
{
yr=7.0f;
if (lang==0)
sprintf (txt, " выход");
else
sprintf (txt, " quit");
}
xr=4.0f;
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+4)*brdCell, brdT2-(yr+1)*brdCell, brdZ); glTexCoord2f (1.0f, 1.0f); glVertex3f (brdL2+(xr+4)*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);
literaScale=0.32f;
literaY=0.55f;
if (infOn==1)
{
if (lang==0)
{
literaX=-0.564f;
sprintf (literaText, "Линии");
}
else
{
literaX=-0.564f;
sprintf (literaText, "Lines");
}
}
else
{
if (lang==0)
{
literaX=-0.554f;
sprintf (literaText, "Итоги");
}
else
{
literaX=-0.734f;
sprintf (literaText, "Summary");
}
}
glColor3f (colorH [0], colorH [1], colorH [2]);
glPrintLitera (); yr=1.75f;
char infTxt [10] [100];
if (infOn==1)
{
if (lang==0)
{
xr=-0.25f; char infTxt1 [10] [100]={" Задача - как можно дольше не позволять",
"заполняться игровому полю. Для этого надо",
"составлять горизонтальные, вертикальные",
"и диагональные линии. Если выстроить в ряд",
"от 5 одноцветных шариков, они исчезнут.",
"Иначе на доске появятся ещё 3 шарика.",
"Их цвета видны в правом вернем углу.",
"Удачной игры!"
};
memcpy (infTxt, infTxt1, 1000);
}
else
{
xr=-0.5f; char infTxt1 [10] [100]={" Goal is to keep the field from filling up",
"as long as possible. To do this, you need",
"to align horizontal, vertical and diagonal",
"lines. If you line up 5 or more balls of the",
"same color, they will disappear. Otherwise,",
"3 more balls will appear on the board. Their",
"colors are shown in the upper-right corner.",
"Lucky playing!"
};
memcpy (infTxt, infTxt1, 1000);
}
}
else
{
xr=-0.15f;
if (lang==0)
{
char infTxt1 [10] [100]={" Очки:",
" 1 место:",
" 2 место:",
" 3 место:",
" Сначала:",
" Недоиграно:",
" Доиграно:",
" Ходов:"
};
memcpy (infTxt, infTxt1, 1000);
}
else
{
char infTxt1 [10] [100]={" Score:",
" 1 place:",
" 2 place:",
" 3 place:",
" Restarted:",
" Not finished:",
" Finished:",
" Moves:"
};
memcpy (infTxt, infTxt1, 1000);
}
}
glColor3f (colorTxt [0], colorTxt [1], colorTxt [2]);
for (yi=0; yi<8; 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 (); }
if (infOn==2)
{
xr=3.25f; yr=1.76f;
long stats [10]={cScore, cPlace1, cPlace2, cPlace3, cRestart, cNotfin, cFin, cMoves};
glColor3f (colorVol [0], colorVol [1], colorVol [2]);
for (yi=0; yi<8; 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, "%d", stats [yi]);
glPrintLitera (); }
glColor3f (colorTxt [0], colorTxt [1], colorTxt [2]);
}
xr=-0.25f; yr=1.75f;
if (infOn==1)
{
literaY=brdT2-brdCell/2.0f-brdCell*(yr+9*0.5f)-0.0025f;
literaX=brdL2+brdCell/2.0f+brdCell*xr-0.0025f;
if (lang==0)
sprintf (literaText, " Маркичев Д. 2021-2022");
else
sprintf (literaText, " D. Markichev, 2021-2022");
glColor3f (colorTxtB [0], colorTxtB [1], colorTxtB [2]);
glPrintLitera (); }
}
}
fpsC ();
glPopMatrix ();
SwapBuffers (hDC);
}
void mouseMove ()
{
int xi, yi;
if (blur_on)
return;
GetCursorPos (&mypoint);
if (infOn && mypoint.x>=mXar [0]-(mXar [1]-mXar [0]) && mypoint.x<mXar [9] && mypoint.y>=mYar [0]-(mYar [1]-mYar [0]) && mypoint.y<mYar [9])
{
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;
}
cellInfo ();
int bL=button;
button=0;
float ri, qi=float(mXar [8]-mXar [7])/25.0f;
if ((mypoint.x>(mXar [9]+(mXar [8]-mXar [7])/10) && mypoint.x<(mXar [9]+(mXar [8]-mXar [7])*11/10)))
{
if (mypoint.y>=mYar [8] && mypoint.y<mYar [9])
{
xi=abs ((float)mypoint.x-((float)mXar [9]+float(mXar [8]-mXar [7])*6.0f/10.0f));
yi=abs ((float)mypoint.y-((float)mYar [8]+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=7;
}
if (mypoint.y>=mYar [7] && mypoint.y<mYar [8])
{
xi=abs ((float)mypoint.x-((float)mXar [9]+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=6;
}
if (mypoint.y>=mYar [6] && mypoint.y<mYar [7])
{
xi=abs ((float)mypoint.x-((float)mXar [9]+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=5;
}
if (mypoint.y>=mYar [5] && mypoint.y<mYar [6])
{
xi=abs ((float)mypoint.x-((float)mXar [9]+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=4;
}
if (mypoint.y>=mYar [4] && mypoint.y<mYar [5])
{
xi=abs ((float)mypoint.x-((float)mXar [9]+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=3;
}
if (mypoint.y>=mYar [3] && mypoint.y<mYar [4])
{
xi=abs ((float)mypoint.x-((float)mXar [9]+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=2;
}
if (mypoint.y>=mYar [2] && mypoint.y<mYar [3])
{
xi=abs ((float)mypoint.x-((float)mXar [9]+float(mXar [8]-mXar [7])*6.0f/10.0f));
yi=abs ((float)mypoint.y-((float)mYar [2]+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 (button!=0)
SetCursor (curArrow);
else if (state==10)
SetCursor (curWait);
else if (state==12)
SetCursor (curNew);
else if (state!=0 && state!=1 && !button)
SetCursor (curWait);
}
void mouseClick ()
{
GetCursorPos (&mypoint);
if (infOn && mypoint.x>=mXar [0]-(mXar [1]-mXar [0]) && mypoint.x<mXar [9] && mypoint.y>=mYar [0]-(mYar [1]-mYar [0]) && mypoint.y<mYar [9])
{
infOn=0;
playSound ("shake");
mouseMove ();
return;
}
if (!button)
playerMove ();
else if (button==1)
Restart ();
else if (button==2)
{
if (lang==0)
lang=1;
else
lang=0;
playSound ("turn_on");
}
else if (button==3)
{
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==4)
{
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==5)
{
if (infOn!=2)
{
infOn=2;
playSound ("shake");
}
else
{
infOn=0;
playSound ("shake");
}
}
else if (button==6)
{
if (infOn!=1)
{
infOn=1;
playSound ("shake");
}
else
{
infOn=0;
playSound ("shake");
}
}
else if (button==7)
{
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<9 && y>-1 && y<9)
p=y*9+x;
else
p=0;
return p;
}
void playerMove ()
{
if (state>=10)
Restart ();
else
{
if (state!=0 && state!=1)
{
SetCursor (curWait);
return;
}
if (state==0)
{
if (posHL==0)
playSound ("break");
else
{
sel_x0=posXl;
sel_y0=posYl;
piece [0]=init_d [getPos (sel_x0, sel_y0)];
draw_move [0]=piece [0];
rvH=0.0f;
rvDir=1;
state=1;
playSound ("ready");
}
}
else if (state==1)
{
if (init_d [getPos (posXl, posYl)]>0)
{
if (sel_x0==posXl && sel_y0==posYl)
{
state=0;
playSound ("drop");
}
else
{
if (posHL==0)
playSound ("break");
else
{
sel_x0=posXl;
sel_y0=posYl;
piece [0]=init_d [getPos (sel_x0, sel_y0)];
draw_move [0]=piece [0];
rvH=0.0f;
rvDir=1;
playSound ("ready");
}
}
}
else if (posHL==2)
{
move_sx=(float)sel_x0;
move_sy=(float)sel_y0;
sel_x=posXl;
sel_y=posYl;
leaps_n=0;
SetCursor (curWait);
state=2;
}
else
playSound ("break");
}
}
}
void cellInfo ()
{
int r;
int tx=posX;
int ty=posY;
posXl=posX;
posYl=posY;
posHL=0;
if (state==0)
{
if (check_any (init_d, tx, ty))
posHL=1;
}
else if (state==1)
{
if (posX==sel_x0 && posY==sel_y0)
posHL=1;
else if (init_d [getPos (posXl, posYl)]>0)
posHL=1;
else if (check_move (posX, posY))
posHL=2;
}
}
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)
{
glLoadIdentity (); literaY=0.75f;
literaX=-0.75f;
literaScale=0.17f;
glColor3f (1.0f, 0.5f, 0.0f);
if (strlen (mb)!=0)
{
sprintf (literaText, "%s", mb);
glPrintLitera (); return;
}
sprintf (literaText, "FPS:%d X:%d Y:%d", fps, posX, posY);
glPrintLitera (); }
}
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], conf1 [1024], conf2 [1024];
Score ();
if (move1 && state<10)
cNotfin++;
sprintf (conf1, "Sound:%d\r\nMelody:%d\r\nLanguage:%d\r\n",
sndVol, melVol, lang);
sprintf (conf2, "1:%d\r\n2:%d\r\n3:%d\r\nRestarted:%d\r\nNotFinished:%d\r\nFinished:%d\r\nMoves:%d\r\n",
cPlace1, cPlace2, cPlace3, cRestart, cNotfin, cFin, cMoves);
sprintf (conf, "%s\r\n%s", conf1, conf2);
char path [_MAX_PATH];
sprintf (path, "%s%s", AppDir, "data\\save.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\\save.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, "Language"))
{
lang=atoi (par1);
if (lang!=0 && lang!=1)
lang=0;
}
else if (!strcmp (par0, "1"))
{
cPlace1=atoi (par1);
if (cPlace1<0)
cPlace1=0;
}
else if (!strcmp (par0, "2"))
{
cPlace2=atoi (par1);
if (cPlace2<0)
cPlace2=0;
}
else if (!strcmp (par0, "3"))
{
cPlace3=atoi (par1);
if (cPlace3<0)
cPlace3=0;
}
else if (!strcmp (par0, "Restarted"))
{
cRestart=atoi (par1);
if (cRestart<0)
cRestart=0;
}
else if (!strcmp (par0, "NotFinished"))
{
cNotfin=atoi (par1);
if (cNotfin<0)
cNotfin=0;
}
else if (!strcmp (par0, "Finished"))
{
cFin=atoi (par1);
if (cFin<0)
cFin=0;
}
else if (!strcmp (par0, "Moves"))
{
cMoves=atoi (par1);
if (cMoves<0)
cMoves=0;
}
}
}
}