超级玛丽c++代码(经典小游戏)


自己用c++在windows下写的超级玛丽,基本功能实现的比较完全
资源截图
代码片段和文件信息
#include “Monster.h“
#include “Player.h“

extern CPlayer * player;
extern int stage;
extern int bufferX;
extern int bufferY;
extern int mapIndex[2800];
extern int gameStep;
extern HDC hMemDc;
extern HINSTANCE hInstance;

CMonster::CMonster(void)
: monsterNumber(3)
 flatLoop(0)
{
HBITMAP hMonBitmap;
BITMAP bmp;
hMonDc = CreateCompatibleDC(hMemDc);
hMonBitmap = LoadBitmap(hInstanceMAKEINTRESOURCE(IDB_MONSTER));
Selectobject(hMonDchMonBitmap);
SetBkColor(hMonDcRGB(255255255));
Getobject(hMonBitmapsizeof(BITMAP)&bmp);

hMaskDc = CreateCompatibleDC(hMemDc);
Selectobject(hMaskDcCreateBitmap(bmp.bmWidthbmp.bmHeight11NULL));
BitBlt(hMaskDc00bmp.bmWidthbmp.bmHeighthMonDc00SRCCOPY);

Reset();
}

CMonster::~CMonster(void)
{
DeleteDC(hMonDc);
DeleteDC(hMaskDc);
}

// 绘制怪物
void CMonster::Draw(void)
{
if (gameStep == GAME_RUN)
{
for(int i = 0;i < monsterNumber;i++)
{
if(temp[i].visble)
drawMonster(temp[i].typetemp[i].xtemp[i].y);
if (temp[i].type == 8)
{
flatLoop++;
if (flatLoop == 8)
{
temp[i].visble = false;
flatLoop = 0;
}
}
}
}
}

// 画不同种类的怪
void CMonster::drawMonster(int typeint xint y)
{
if (type == 1 || type == 3)
{
BitBlt(hMemDcx+bufferXy+bufferY-123042hMonDc33*type0SRCINVERT);
BitBlt(hMemDcx+bufferXy+bufferY-123042hMaskDc33*type0SRCAND);
BitBlt(hMemDcx+bufferXy+bufferY-123042hMonDc33*type0SRCINVERT);
}
else
{
BitBlt(hMemDcx+bufferXy+bufferY3030hMonDc33*type0SRCINVERT);
BitBlt(hMemDcx+bufferXy+bufferY3030hMaskDc33*type0SRCAND);
BitBlt(hMemDcx+bufferXy+bufferY3030hMonDc33*type0SRCINVERT);
}
}

// 刷新怪物
void CMonster::Update(void)
{
int pxcollodeResult;
px = player->getX();
if (temp[0].life && px > 125)
{
temp[0].bMove = true;
}
if (temp[2].life && px > 2400)
{
temp[2].bMove = true;
}
for (int i = 0;i < monsterNumber;i++)
{
if (temp[i].life)
{
Move(i);
}
}
}

// 怪物移动
void CMonster::Move(int index)
{
MONTSTER mM;
mM = temp[index];
switch(mM.type)
{
case 0:
case 1:
if (mM.bMove)
{
if(mM.x > -30)
{
if (mapIndex[(mM.x+29)/30+(mM.y+30)/30*200] == 0 && mapIndex[(mM.x+5)/30+(mM.y+30)/30*200] == 0 )
{
mM.y += 5;
if(mM.y>CLIENT_HEIGHT)
mM.life = false;
}
else 
mM.x -= 2;
}
else
{
mM.bMove = false;
}
}
break;
case 3:
if (mM.bMove)
{
if (mM.y<150)
{
mM.bMove = false;
}
else
mM.y -= 5;
}
else
{
if (mM.y>CLIENT_HEIGHT-30)
{
mM.bMove = true;
}
else
mM.y += 5;
}
break;
}
temp[index] = mM;
}

// 重置怪物数据
void CMonster::Reset(void)
{
temp[0].type = 0;
temp[0].x = 690;
temp[0].y = CLIENT_HEIGHT-210;
temp[0].life = true;
temp[0].bMove = false;
temp[0].visble = true;

temp[1].type = 3;
temp[1].x = 2070;
t

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11200  2009-07-15 16:38  SuperMaridebug.map

     文件      11200  2009-07-14 18:45  SuperMaridebug1.map

     文件      11200  2009-07-14 18:41  SuperMaridebug2.map

     文件      32326  2009-07-14 21:21  SuperMaridebugrockbreak.wav

     文件      42668  2009-07-14 16:41  SuperMaridebugcoin.wav

     文件     315692  2009-07-14 16:58  SuperMaridebugdeath.wav

     文件     243116  2009-07-14 17:33  SuperMaridebuggoal.wav

     文件      20780  2009-07-15 12:01  SuperMaridebughumi.wav

     文件      27692  2009-07-14 16:58  SuperMaridebugjump.wav

     文件       9286  2009-07-14 16:58  SuperMaridebugjumpBlock.wav

     文件    1208320  2009-07-16 20:23  SuperMaridebugSuperMari.exe

     文件     374028  2009-07-16 20:23  SuperMaridebugSuperMari.ilk

     文件     257024  2009-07-16 20:23  SuperMaridebugSuperMari.pdb

     文件    2228202  2009-07-10 23:42  SuperMaridebugsupermario.mp3

     文件      11200  2009-07-15 16:38  SuperMariSuperMari.map

     文件      11200  2009-07-14 18:45  SuperMariSuperMari1.map

     文件      22400  2009-07-14 18:35  SuperMariSuperMari2.map

     文件      32326  2009-07-14 21:21  SuperMariSuperMarirockbreak.wav

     文件      42668  2009-07-14 16:41  SuperMariSuperMaricoin.wav

     文件     315692  2009-07-14 16:58  SuperMariSuperMarideath.wav

     文件      14668  2009-07-16 20:23  SuperMariSuperMariDebugBuildLog.htm

     文件      14863  2009-07-16 20:23  SuperMariSuperMariDebugMonster.obj

     文件         65  2009-07-16 20:23  SuperMariSuperMariDebugmt.dep

     文件      25433  2009-07-16 20:23  SuperMariSuperMariDebugPlayer.obj

     文件      26719  2009-07-16 20:23  SuperMariSuperMariDebugScence.obj

     文件        403  2009-07-16 20:23  SuperMariSuperMariDebugSuperMari.exe.embed.manifest

     文件        468  2009-07-16 20:23  SuperMariSuperMariDebugSuperMari.exe.embed.manifest.res

     文件        385  2009-07-16 20:23  SuperMariSuperMariDebugSuperMari.exe.intermediate.manifest

     文件      22147  2009-07-16 20:23  SuperMariSuperMariDebugSuperMari.obj

     文件     957928  2009-07-16 20:23  SuperMariSuperMariDebugSuperMari.res

............此处省略54个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)