資源簡介
用VC設計的貪吃魚游戲,對于游戲的學習很有幫助。

代碼片段和文件信息
/************************************************************************/
/* */
/*?由圖塊組成的游戲地圖處理類?????????? ????????????*/
/*?作者:萬立中 (C)2011-06-3 */
/*?www.wanlizhong.com */
/* */
/************************************************************************/
#pragma?once
#include?“stdafx.h“
#include?“CImageMap.h“
//靜態圖像背景
CImageMap::CImageMap(LPTSTR?fileName?HWND?hWnd):RhlCGdiBmp(fileName)
{
MainWnd?=?hWnd;
RECT?wRect;
GetWindowRect(hWnd?&wRect);
GameWinSize.cx?=?wRect.right-wRect.left;
GameWinSize.cy?=?wRect.bottom-wRect.top;
POINT?pos;
if(this->getbmpWidth()?>?GameWinSize.cx)
pos.x?=?-(this->getbmpWidth()-GameWinSize.cx)/2;
else
pos.x?=?(GameWinSize.cx?-?this->getbmpWidth())/2;
if(this->getBmpHeight()?>?GameWinSize.cy)
pos.y?=?-(this->getBmpHeight()?-?GameWinSize.cy)/2;
else
pos.y?=?(GameWinSize.cy?-?this->getBmpHeight())/2;
NowMapPos?=?pos;
MapOriginPoint?=?pos;
RECT?rec;
GetClientRect(MainWnd?&rec);?
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++???
//如果魚在NoScrollArea的邊界則只移動背景?魚不移動
//如果魚在NoScrollArea的邊界以內?魚移動?背景不移動
//如果背景到達了邊緣則魚可以移動
int?EdgeH?=?rec.right/5;
int?EdgeV?=?rec.bottom/5;
NoScrollArea.left?=?EdgeH;
NoScrollArea.top?=?EdgeV;
NoScrollArea.right?=?rec.right?-?EdgeH;
NoScrollArea.bottom?=?rec.bottom?-?EdgeV;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++???
}
CImageMap::~CImageMap()
{
}
void?CImageMap::DrawGameMap(HDC?hdc)
{
this->DrawMirror(hdc?NowMapPos.x?NowMapPos.y?0);
}
BOOL?CImageMap::ScrollMap(int?nowPlayerDir?int?playerSpeed?
??POINT?nowPlayerPos?SpriteSet&?EnemySpriteSet)
{
BOOL?MapScrolling?=?FALSE;
bool?enemyScrolled?=?false;
int?xSpeed?=?playerSpeed;
double?ratio?=?(double)this->getBmpHeight()/(double)this->getbmpWidth();
int?ySpeed?=?ratio?*?playerSpeed;
SIZE?BackSize;
BackSize.cx?=?this->getbmpWidth();
BackSize.cy?=?this->getBmpHeight();
switch(nowPlayerDir)
{
case?RhlCSprite::DIR_UP://上
if(nowPlayerPos.y? {
enemyScrolled?=?true;
MapScrolling?=?TRUE;
NowMapPos.y?=?NowMapPos.y?+?playerSpeed;
if(NowMapPos.y?>=?0)
{
NowMapPos.y?=?0;
enemyScrolled?=?false;
MapScrolling?=?FALSE;
}
}
break;
case?RhlCSprite::DIR_DOWN://下
if(nowPlayerPos.y?>=?NoScrollArea.bottom)
{
enemyScrolled?=?true;
MapScrolling?=?TRUE;
NowMapPos.y?=?NowMapPos.y?-?playerSpeed;
if(NowMapPos.y?<=?-(BackSize.cy?-?GameWinSize.cy))
{
NowMapPos.y?=?-(BackSize.cy?-?GameWinSize.cy);
enemyScrolled?=?false;
MapScrolling?=?FALSE;
}
}
break;
case?RhlCSprite::DIR_LEFT://左
if( nowPlayerPos.x? {
enemyScrolled?=?true;
MapScrolling?=?TRUE;
NowMapPos.x?=?NowMapPos.x?+?playerSpeed;
if(NowMapPos.x?>=?0)
{
No
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????773??2011-05-22?18:31??RhlFishGame2\StdAfx.h
?????文件????????298??2011-05-22?18:31??RhlFishGame2\StdAfx.cpp
?????文件???????1239??2011-05-22?18:31??RhlFishGame2\ReadMe.txt
?????文件????????530??2011-05-22?18:31??RhlFishGame2\RhlFishGame.dsw
?????文件?????222208??2011-06-10?20:23??RhlFishGame2\RhlFishGame.ncb
?????文件????????289??2011-04-28?23:23??RhlFishGame2\RhlCDesktop.h
?????文件???????8993??2011-04-30?21:16??RhlFishGame2\RhlCDxSound.cpp
?????文件???????2389??2011-04-30?21:16??RhlFishGame2\RhlCDxSound.h
?????文件???????5676??2011-05-11?17:17??RhlFishGame2\RhlCGdiBmp.cpp
?????文件???????1280??2011-05-11?17:17??RhlFishGame2\RhlCGdiBmp.h
?????文件???????7716??2011-05-09?17:16??RhlFishGame2\RhlCSprite.cpp
?????文件??????????0??2011-05-22?18:39??RhlFishGame2\新建?文本文檔.txt
?????文件???????1896??2011-06-10?20:21??RhlFishGame2\RhlFishGame.plg
?????文件????????137??2011-05-22?19:18??RhlFishGame2\RhlFishGame.h
?????文件???????1408??2011-05-22?20:36??RhlFishGame2\RhlCDesktop.cpp
?????文件???????1390??2011-05-23?22:14??RhlFishGame2\RhlFishGame.cpp
?????文件???????8671??2011-05-27?10:40??RhlFishGame2\RhlCEngine.cpp
?????文件???????4996??2011-06-10?11:50??RhlFishGame2\RhlCSprite.h
?????文件???????2359??2011-06-10?11:50??RhlFishGame2\RhlCEngine.h
?????文件???????1288??2011-06-10?11:50??RhlFishGame2\CImageMap.h
?????文件???????5133??2011-06-10?11:53??RhlFishGame2\RhlCManager.h
?????文件???????5228??2011-06-10?11:58??RhlFishGame2\RhlFishGame.dsp
?????文件???????7475??2011-06-10?20:18??RhlFishGame2\CImageMap.cpp
?????文件??????25899??2011-06-10?20:21??RhlFishGame2\RhlCManager.cpp
?????文件??????52736??2011-06-10?20:23??RhlFishGame2\RhlFishGame.opt
?????文件?????312320??2011-06-10?20:22??RhlFishGame2\Debug\vc60.idb
?????文件????2574264??2011-05-22?19:12??RhlFishGame2\Debug\RhlFishGame.pch
?????文件?????356352??2011-06-10?20:21??RhlFishGame2\Debug\vc60.pdb
?????文件?????434057??2011-05-22?19:12??RhlFishGame2\Debug\StdAfx.sbr
?????文件??????55091??2011-05-22?19:12??RhlFishGame2\Debug\StdAfx.obj
............此處省略67個文件信息
- 上一篇:常用算法程序集(C語言描述) 第三版.rar
- 下一篇:《Qt中的C++技術》
評論
共有 條評論