【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-appProc.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// appProc.cpp: implementation of the appProc class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "canvasr.h"
#include "appProc.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
appProc *app_Proc = NULL ;
void appProc::Run()
{
}
void appProc::Render()
{
}
/*///////////////////////////////////////////
よ遏ず甧
/*///////////////////////////////////////////
static const POINT app_TetrisBox[7][4] =
{
/*0
〖〖〖〖
*/{ { 0 , 1 }, { 1 , 1 } , { 2 , 1 } , { 3 , 1 } },
/*1
〖〖
〖〖
*/{ { 0 , 1 }, { 1 , 1 } , { 2 , 1 } , { 2 , 2 } },
/*2
〖〖
〖〖
*/{ { 0 , 2 }, { 1 , 2 } , { 1 , 1 } , { 2 , 1 } },
/*3
〖〖〖
〖
*/{ { 0 , 1 } ,{ 1 , 1 } , { 2 , 1 } , { 2 , 2 } },
/*4
〖
〖〖〖
*/{ { 0 , 2 } ,{ 1 , 2 } , { 2 , 2 } , { 2 , 1 } },
/*5
〖〖
〖〖
*/{ { 1 , 1 }, { 2 , 1 } , { 2 , 2 } , { 1 , 2 } },
/*6
〖
〖〖〖
*/{ { 2 , 1 }, { 1 , 2 } , { 2 , 2 } , { 3 , 2 } },
};
/*///////////////////////////////////////////
笴栏戈挡篶
/*///////////////////////////////////////////
typedef struct _TETRIS_DATA
{
BYTE Data[10][20] ;//┏戈
POINT NowBox[4] ;//ヘ玡よ遏
POINT NowPoint ;
int BoxNextIndex ;//よ遏
int BoxNowIndex ;//ヘ玡よ遏
int TimeNextGrid ;
int TimeGridNow ;
int sLV ;//闽
int sNLV ;//闽璶︽计
int sScore ;//眔だ
int sDel ;//︽计
}TETRIS_DATA ;
TETRIS_DATA ts_DA ;
//璉春
d3dTexture ts_Back ;
//よ遏
d3dTexture ts_Box[7] ;
//夹肈
d3dTexture ts_Title ;
/*///////////////////////////////////////////
笴栏秈︽い
/*///////////////////////////////////////////
Tetris app_Tetris ;
void appTetrisRun()
{
app_Proc = &app_Tetris ;
//﹚﹍戈
ts_DA.sLV = 1 ;
ts_DA.sNLV = 6 ;
// app_Tetris.Updata();
}
//
//
//﹍て
void Tetris::Updata()
{
int i ;
char ch[256] ;
//秨﹍
memset( &ts_DA , 0 , sizeof( ts_DA ));
//更璉春
ts_Back.Create( "璉春.tga" );
//輘よ遏
for( i = 0 ; i < 7 ; i++ )
{
wsprintf( ch , "よ遏%2.2d.bmp" , i );
ts_Box[i].Create( ch );
}
//材よ遏
ts_DA.BoxNextIndex = rand()%7 ;
GetBox();
//丁
ts_DA.TimeNextGrid = 560 ;
//酶籹家Α
d3d_Device->SetTextureStageState( 0 , D3DTSS_ALPHAARG1 , D3DTA_TEXTURE );
d3d_Device->SetTextureStageState( 0 , D3DTSS_ALPHAARG2 , D3DTA_DIFFUSE );
d3d_Device->SetTextureStageState( 0 , D3DTSS_COLORARG1 , D3DTA_TEXTURE );
d3d_Device->SetTextureStageState( 0 , D3DTSS_COLORARG2 , D3DTA_DIFFUSE );
}
//
//
//癹伴
void Tetris::Run()
{
//辅
BoxDown();
//簿
Move();
//臂锣
Rotation();
//酶籹
Render();
}
//
//
//酶籹
void Tetris::Render()
{
//礶ン
RenderBack();
//Θ钩
d3d_Device->Present( NULL , NULL , NULL , NULL );
}
void Tetris::RenderBack()
{
d3dTexture d3dRt ;
//睲
d3dClear();
//秨﹍酶籹
d3d_Device->BeginScene();
d3d_Device->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA );
d3d_Device->SetRenderState( D3DRS_DESTBLEND , D3DBLEND_INVSRCALPHA );
d3d_Device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
d3d_Device->SetTextureStageState( 0 , D3DTSS_ALPHAOP , D3DTOP_SELECTARG2 );
//礶璉春
ts_Back.BltFast( 0 , 0 );
//礶┏
d3dRt.BltFast( 220 , 40 , 420 , 440 , 0x8FFFFFFF );
//ゅ
d3dRt.BltFast( 100 , 100 , 200 , 200 , 0X8F000000 );
//よ遏
d3dRt.BltFast( 440 , 60 , 560 , 180 , 0x4F000000 );
//礶よ遏
DrawNowBox();
d3d_Device->EndScene();
//酶籹ゅ
DrawText();
}
//礶ゅ
void Tetris::DrawText()
{
int len ;
char ch[256] ;
//ゅ
d3dHdc hdc ;
SetBkMode( hdc , 1 );
SetTextColor( hdc , RGB( 255 , 255 , 255 ));
//ヘ玡だ计
len = wsprintf( ch , "だ计%d" , ts_DA.sScore );
TextOut( hdc , 110 , 105 , ch , len );
//︽计
len = wsprintf( ch , "︽计%d" , ts_DA.sDel );
TextOut( hdc , 110 , 125 , ch , len );
//闽
len = wsprintf( ch , "闽%d" , ts_DA.sLV );
TextOut( hdc , 110 , 145 , ch , len );
}
//礶よ遏
void Tetris::DrawBox(int gx, int gy , int index )
{
int x , y ;
if(( index >= 0 )&&( index < 7 ))
{
x = gx * 20 + 220 ;
y = gy * 20 + 40 ;
ts_Box[index].BltFast( x , y );
}
}
void Tetris::GetBox()
{
int i ;
//﹚北膀非翴﹍竚
ts_DA.NowPoint.x = 3 ;
ts_DA.NowPoint.y = -3 ;
//﹚よ遏竚
ts_DA.BoxNowIndex = ts_DA.BoxNextIndex ;
for( i = 0 ; i < 4 ; i++ )
{
ts_DA.NowBox[i].x = app_TetrisBox[ ts_DA.BoxNowIndex ][i].x ;
ts_DA.NowBox[i].y = app_TetrisBox[ ts_DA.BoxNowIndex ][i].y ;
}
//よ遏
ts_DA.BoxNextIndex = rand()%7;
//丁﹍て
ts_DA.TimeGridNow = ts_DA.TimeNextGrid ;
}
void Tetris::DrawNowBox()
{
int i , j ;
int gx , gy ;
BYTE index ;
//礶┏よ遏
for( i = 0 ; i < 10 ; i++ )
for( j = 0 ; j < 20 ; j++ )
if( index = ts_DA.Data[i][j] )
DrawBox( i , j , index - 1 );
//礶ヘ玡よ遏
for( i = 0 ; i < 4 ; i++ )
{
gx = ts_DA.NowBox[i].x + ts_DA.NowPoint.x ;
gy = ts_DA.NowBox[i].y + ts_DA.NowPoint.y ;
if( IsInRect( gx , gy ))
DrawBox( gx , gy , ts_DA.BoxNowIndex );
}
//礶よ遏
for( i = 0 ; i < 4 ; i++ )
DrawBox( app_TetrisBox[ts_DA.BoxNextIndex][i].x + 12 , app_TetrisBox[ts_DA.BoxNextIndex][i].y + 2 , ts_DA.BoxNextIndex );
}
void Tetris::BoxDown()
{
int i ;
int gx , gy ;
//辅丁
if( di_DDD.News4ing == 1 )
ts_DA.TimeGridNow -= ( di_DDD._time * 5 );
else
ts_DA.TimeGridNow -= ( di_DDD._time );
//辅Θ
while( ts_DA.TimeGridNow < 0 )
{
ts_DA.TimeGridNow += ts_DA.TimeNextGrid ;
if( IsDown( ts_DA.NowPoint.x , ts_DA.NowPoint.y + 1 ))
ts_DA.NowPoint.y ++ ;
else
{
//氨ㄓよ遏璝ゼ秈ず笴栏挡
for( i = 0 ; i < 4 ; i++ )
if( !IsInRect( ts_DA.NowBox[i].x + ts_DA.NowPoint.x , ts_DA.NowBox[i].y + ts_DA.NowPoint.y ))
{
appTetrisGameOverRun();
return ;
}
//戈絯侥跋
for( i = 0 ; i < 4 ; i++ )
{
gx = ts_DA.NowBox[i].x + ts_DA.NowPoint.x ;
gy = ts_DA.NowBox[i].y + ts_DA.NowPoint.y ;
ts_DA.Data[gx][gy] = ts_DA.BoxNowIndex + 1 ;
}
//耞琌埃
ListDelIs();
//よ遏
GetBox();
//挡
return ;
}
}
}
BOOL Tetris::IsDown( int nx , int ny )
{
int i ;
int gx , gy ;
//
for( i = 0 ; i < 4 ; i++ )
{
gx = ts_DA.NowBox[i].x + nx ;
gy = ts_DA.NowBox[i].y + ny ;
//琌┏
if( gy >= 20 )
return false ;
//琌ず
if( gy >= 0 )
if( !IsInRect( gx , gy ))
return false ;
//琌Τよ遏
else if( ts_DA.Data[gx][gy] )
return false ;
}
//
return true ;
}
BOOL Tetris::IsInRect(int gx, int gy)
{
if(( gx >= 0 )&&( gx < 10 ))
if(( gy >= 0 )&&( gy < 20 ))
return true ;
return false ;
}
//簿笆
void Tetris::Move()
{
if( di_DDD.News4 == 3 )//△
{
if( IsDown( ts_DA.NowPoint.x + 1 , ts_DA.NowPoint.y ))
ts_DA.NowPoint.x ++ ;
}else if( di_DD
上一篇:
APPOCTETSTREAM.CPP
下一篇:
应用数学学报编辑部联系方式