📄 gift.c
字号:
/*
gift.c
随机物品相关函数实现
最后修改: 2007-06-19
*/
#include "gift.h"
#include "graph.h"
#include "map.h"
#ifndef NULL
#define NULL 0
#endif
char g_byGift[7][16][16] =
{
{
/* 坦克 */
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 10, 10, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 10, 10, 13, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 10, 10, 13, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 10, 13, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 10, 13, 10, 10, 10, 10, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 10, 13, 13, 10, 10, 13, 13, 13, 13, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
},
{
/* 手枪 */
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 4, 4, 4, 4, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 4, 4, 4, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 4, 4, 4, 4, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 4, 4, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 4, 4, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 4, 4, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 4, 4, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 4, 4, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 4, 4, 4, 4, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 11},
{11, 13, 13, 13, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 11},
{11, 13, 13, 13, 4, 4, 4, 13, 13, 13, 13, 4, 4, 4, 4, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
},
{
/* 定时 */
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
{11, 13, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 13, 13, 13, 11},
{11, 13, 13, 9, 9, 13, 13, 13, 13, 13, 13, 9, 9, 13, 13, 11},
{11, 13, 9, 9, 13, 13, 13, 13, 13, 13, 13, 13, 9, 9, 13, 11},
{11, 9, 9, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 9, 11},
{11, 9, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 11},
{11, 9, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 11},
{11, 9, 13, 4, 4, 4, 4, 4, 4, 13, 13, 13, 13, 13, 9, 11},
{11, 9, 13, 13, 13, 13, 13, 13, 4, 13, 13, 13, 13, 13, 9, 11},
{11, 9, 13, 13, 13, 13, 13, 13, 4, 13, 13, 13, 13, 13, 9, 11},
{11, 9, 13, 13, 13, 13, 13, 13, 4, 13, 13, 13, 13, 13, 9, 11},
{11, 9, 9, 13, 13, 13, 13, 13, 4, 13, 13, 13, 13, 9, 9, 11},
{11, 13, 9, 9, 13, 13, 13, 13, 4, 13, 13, 13, 9, 9, 13, 11},
{11, 13, 13, 9, 9, 13, 13, 13, 13, 13, 13, 9, 9, 13, 13, 11},
{11, 13, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 13, 13, 13, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
},
{
/* 炸弹 */
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 9, 9, 9, 9, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 13, 13, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 13, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 13, 18, 18, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 18, 18, 18, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 18, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 18, 13, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 13, 18, 13, 13, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11},
{11, 13, 13, 4, 4, 13, 9, 9, 9, 9, 9, 9, 9, 9, 13, 11},
{11, 13, 13, 4, 13, 13, 13, 13, 9, 9, 9, 9, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
},
{
/* 船 */
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 9, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 7, 13, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 7, 7, 13, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 13, 7, 7, 7, 7, 13, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 9, 9, 13, 11},
{11, 13, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 7, 7, 7, 7, 7, 7, 13, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 13, 7, 7, 7, 7, 13, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 7, 7, 13, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 7, 13, 9, 9, 9, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 9, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
},
{
/* 坦克无敌 */
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 11},
{11, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 10, 13, 11},
{11, 13, 10, 13, 13, 13, 10, 10, 10, 10, 13, 13, 13, 10, 13, 11},
{11, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 10, 13, 11},
{11, 13, 10, 13, 10, 13, 13, 13, 13, 13, 13, 10, 13, 10, 13, 11},
{11, 13, 10, 13, 10, 13, 13, 13, 13, 13, 13, 10, 13, 10, 13, 11},
{11, 13, 10, 13, 10, 13, 13, 13, 13, 13, 13, 10, 13, 10, 13, 11},
{11, 13, 10, 13, 10, 13, 13, 13, 13, 13, 13, 10, 13, 10, 13, 11},
{11, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 10, 13, 11},
{11, 13, 10, 13, 13, 13, 10, 10, 10, 10, 13, 13, 13, 10, 13, 11},
{11, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 10, 13, 11},
{11, 13, 13, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
},
{
/* 老家无敌 */
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 8, 8, 8, 8, 8, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 8, 8, 8, 7, 7, 7, 8, 13, 11},
{11, 13, 13, 13, 13, 13, 8, 8, 7, 7, 7, 7, 7, 8, 13, 11},
{11, 13, 13, 13, 13, 8, 8, 7, 7, 7, 7, 7, 7, 8, 13, 11},
{11, 13, 13, 13, 13, 13, 8, 8, 7, 7, 7, 7, 8, 8, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 8, 7, 7, 7, 7, 8, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 8, 7, 8, 8, 7, 8, 8, 13, 13, 11},
{11, 13, 13, 13, 13, 8, 7, 8, 13, 8, 8, 8, 13, 13, 13, 11},
{11, 13, 13, 13, 8, 7, 8, 13, 13, 13, 8, 13, 13, 13, 13, 11},
{11, 13, 8, 8, 7, 8, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 8, 8, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 8, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
}
};
CGift *g_pGift[60][60];
CGift *g_pTheGift=NULL;
char g_byStopTank=0, g_byProtectBase=0; /* 0-无 1-玩家获取 2-敌方获取*/
int g_cntStopTank=-1, g_cntProtectBase=-1;
/*
void SetStopTank(char byType)
{
g_byStopTank=byType;
g_cntStopTank=1800;
}
char GetStopTank()
{
return g_byStopTank;
}
void SetProtectBase(char byType)
{
g_byProtectBase=byType;
g_cntProtectBase=1800;
}
*/
void DrawGift(CGift *pThis) /* 画随机物品 */
{
int i, j;
for(i=0;i<16;i++)
{
for(j=0;j<16;j++)
{
PutPix(pThis->m_nX*8+i, pThis->m_nY*8+j, g_byGift[pThis->m_byType][i][j]);
}
}
g_pGift[pThis->m_nX ][pThis->m_nY ]=pThis;
g_pGift[pThis->m_nX+1][pThis->m_nY ]=pThis;
g_pGift[pThis->m_nX ][pThis->m_nY+1]=pThis;
g_pGift[pThis->m_nX+1][pThis->m_nY+1]=pThis;
}
void ClearGift(CGift *pThis) /* 清除随机物品 */
{
g_pGift[pThis->m_nX ][pThis->m_nY ]=NULL;
g_pGift[pThis->m_nX+1][pThis->m_nY ]=NULL;
g_pGift[pThis->m_nX ][pThis->m_nY+1]=NULL;
g_pGift[pThis->m_nX+1][pThis->m_nY+1]=NULL;
RestoreMapUnit(pThis->m_nX, pThis->m_nY );
RestoreMapUnit(pThis->m_nX+1, pThis->m_nY );
RestoreMapUnit(pThis->m_nX, pThis->m_nY+1);
RestoreMapUnit(pThis->m_nX+1, pThis->m_nY+1);
}
void DeleteGift(CGift *pThis) /* 删除随机物品 */
{
ClearGift(pThis);
free(pThis);
g_pTheGift=NULL;
}
void CreateGift(int nLX, int nLY, int byType) /* 创建随机物品 */
{
if(g_pTheGift!=NULL) DeleteGift(g_pTheGift);
g_pTheGift=(CGift *)malloc(sizeof(CGift));
g_pTheGift->m_nX=nLX;
g_pTheGift->m_nY=nLY;
g_pTheGift->m_byType=byType;
g_pTheGift->m_byTiming=1800;
DrawGift(g_pTheGift);
}
void GiftTimer() /* 计时,每周期被执行一次 */
{
if(g_pTheGift!=NULL) /* 随机物品的消失 */
{
(g_pTheGift->m_byTiming)--;
if(g_pTheGift->m_byTiming<0)
{
DeleteGift(g_pTheGift);
}
}
if(g_byStopTank!=0) /* 坦克定时计时 */
{
if(g_cntStopTank==0)
{
g_byStopTank=0;
}
g_cntStopTank--;
}
if(g_byProtectBase!=0) /* 基地保护计时 */
{
if(g_cntProtectBase==1800)
{
char t=(g_byProtectBase==1)?2:0;
SetMap(28, 58, t);
SetMap(28, 59, t);
SetMap(29, 58, t);
SetMap(30, 58, t);
SetMap(31, 58, t);
SetMap(31, 59, t);
RestoreMapUnit(28, 58);
RestoreMapUnit(28, 59);
RestoreMapUnit(29, 58);
RestoreMapUnit(30, 58);
RestoreMapUnit(31, 58);
RestoreMapUnit(31, 59);
}
else if(g_cntProtectBase==0)
{
SetMap(28, 58, 1);
SetMap(28, 59, 1);
SetMap(29, 58, 1);
SetMap(30, 58, 1);
SetMap(31, 58, 1);
SetMap(31, 59, 1);
RestoreMapUnit(28, 58);
RestoreMapUnit(28, 59);
RestoreMapUnit(29, 58);
RestoreMapUnit(30, 58);
RestoreMapUnit(31, 58);
RestoreMapUnit(31, 59);
g_byProtectBase=0;
}
g_cntProtectBase--;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -