资源简介
自己用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 SuperMari\debug\0.map
文件 11200 2009-07-14 18:45 SuperMari\debug\1.map
文件 11200 2009-07-14 18:41 SuperMari\debug\2.map
文件 32326 2009-07-14 21:21 SuperMari\debug\brockbreak.wav
文件 42668 2009-07-14 16:41 SuperMari\debug\coin.wav
文件 315692 2009-07-14 16:58 SuperMari\debug\death.wav
文件 243116 2009-07-14 17:33 SuperMari\debug\goal.wav
文件 20780 2009-07-15 12:01 SuperMari\debug\humi.wav
文件 27692 2009-07-14 16:58 SuperMari\debug\jump.wav
文件 9286 2009-07-14 16:58 SuperMari\debug\jumpBlock.wav
文件 1208320 2009-07-16 20:23 SuperMari\debug\SuperMari.exe
文件 374028 2009-07-16 20:23 SuperMari\debug\SuperMari.ilk
文件 257024 2009-07-16 20:23 SuperMari\debug\SuperMari.pdb
文件 2228202 2009-07-10 23:42 SuperMari\debug\supermario.mp3
文件 11200 2009-07-15 16:38 SuperMari\SuperMari\0.map
文件 11200 2009-07-14 18:45 SuperMari\SuperMari\1.map
文件 22400 2009-07-14 18:35 SuperMari\SuperMari\2.map
文件 32326 2009-07-14 21:21 SuperMari\SuperMari\brockbreak.wav
文件 42668 2009-07-14 16:41 SuperMari\SuperMari\coin.wav
文件 315692 2009-07-14 16:58 SuperMari\SuperMari\death.wav
文件 14668 2009-07-16 20:23 SuperMari\SuperMari\Debug\BuildLog.htm
文件 14863 2009-07-16 20:23 SuperMari\SuperMari\Debug\Monster.obj
文件 65 2009-07-16 20:23 SuperMari\SuperMari\Debug\mt.dep
文件 25433 2009-07-16 20:23 SuperMari\SuperMari\Debug\Pla
文件 26719 2009-07-16 20:23 SuperMari\SuperMari\Debug\Scence.obj
文件 403 2009-07-16 20:23 SuperMari\SuperMari\Debug\SuperMari.exe.em
文件 468 2009-07-16 20:23 SuperMari\SuperMari\Debug\SuperMari.exe.em
文件 385 2009-07-16 20:23 SuperMari\SuperMari\Debug\SuperMari.exe.intermediate.manifest
文件 22147 2009-07-16 20:23 SuperMari\SuperMari\Debug\SuperMari.obj
文件 957928 2009-07-16 20:23 SuperMari\SuperMari\Debug\SuperMari.res
............此处省略54个文件信息
评论
共有 条评论