Skip to content

Commit 158fa83

Browse files
committed
Release V1.3
1 parent 70af587 commit 158fa83

12 files changed

+127
-102
lines changed

Classes/AppDelegate.cpp

+5-55
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33

44
USING_NS_CC;
55

6-
static cocos2d::Size designResolutionSize = cocos2d::Size(640, 1138);
7-
static cocos2d::Size smallResolutionSize = cocos2d::Size(384, 640);
8-
static cocos2d::Size mediumResolutionSize = cocos2d::Size(768, 1280);
9-
static cocos2d::Size largeResolutionSize = cocos2d::Size(1536, 2560);
10-
116
AppDelegate::AppDelegate() {
127

138
}
@@ -16,71 +11,26 @@ AppDelegate::~AppDelegate()
1611
{
1712
}
1813

19-
//if you want a different context,just modify the value of glContextAttrs
20-
//it will takes effect on all platforms
21-
void AppDelegate::initGLContextAttrs()
22-
{
23-
//set OpenGL context attributions,now can only set six attributions:
24-
//red,green,blue,alpha,depth,stencil
25-
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
26-
27-
GLView::setGLContextAttrs(glContextAttrs);
28-
}
29-
30-
// If you want to use packages manager to install more packages,
31-
// don't modify or remove this function
32-
static int register_all_packages()
33-
{
34-
return 0; //flag for packages manager
35-
}
36-
3714
bool AppDelegate::applicationDidFinishLaunching() {
3815
// initialize director
3916
auto director = Director::getInstance();
4017
auto glview = director->getOpenGLView();
4118
if(!glview) {
42-
/*
43-
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
44-
glview = GLViewImpl::createWithRect("BrickGame", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
45-
#else
46-
glview = GLViewImpl::create("BrickGame");
47-
#endif
48-
*/
49-
glview = GLViewImpl::create("BrickGame");
19+
glview = GLView::create("My Game");
20+
glview->setFrameSize(480, 800);
5021
director->setOpenGLView(glview);
5122
}
5223

53-
glview->setFrameSize(480, 800);
24+
glview->setDesignResolutionSize(640, 1138, ResolutionPolicy::FIXED_WIDTH);
5425

5526
// turn on display FPS
56-
director->setDisplayStats(true);
27+
director->setDisplayStats(false);
5728

5829
// set FPS. the default value is 1.0/60 if you don't call this
5930
director->setAnimationInterval(1.0 / 60);
6031

61-
// Set the design resolution
62-
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::FIXED_WIDTH);
63-
/*Size frameSize = glview->getFrameSize();
64-
// if the frame's height is larger than the height of medium size.
65-
if (frameSize.height > mediumResolutionSize.height)
66-
{
67-
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
68-
}
69-
// if the frame's height is larger than the height of small size.
70-
else if (frameSize.height > smallResolutionSize.height)
71-
{
72-
director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
73-
}
74-
// if the frame's height is smaller than the height of medium size.
75-
else
76-
{
77-
director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
78-
}
79-
80-
register_all_packages();*/
81-
8232
// create a scene. it's an autorelease object
83-
auto scene = CLoadScene::CreateScene();
33+
auto scene = CLoadScene::CreateScene();
8434

8535
// run
8636
director->runWithScene(scene);

Classes/AppDelegate.h

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class AppDelegate : private cocos2d::Application
1414
AppDelegate();
1515
virtual ~AppDelegate();
1616

17-
virtual void initGLContextAttrs();
18-
1917
/**
2018
@brief Implement Director and Scene init code here.
2119
@return true Initialize success, app continue.

Classes/BGGlobal.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ int Random(int iStart, int iEnd, int iStep)
3939
bSameTime = false;
4040
}
4141

42+
int iStartIdx = (iStart < iEnd ? iStart : iEnd);
43+
int iEndIdx = (iEnd > iStart ? iEnd : iStart);
44+
4245
vector<int> vecNum;
43-
for (int i = iStart < iEnd ? iStart : iEnd; i < (iEnd > iStart ? iEnd : iStart); i += iStep)
46+
for (int i = iStartIdx; i < iEndIdx; i += iStep)
4447
{
4548
if (mapInvalidList[i] == 1)
4649
{
@@ -51,7 +54,7 @@ int Random(int iStart, int iEnd, int iStep)
5154
}
5255

5356
random_shuffle(vecNum.begin(), vecNum.end());
54-
57+
5558
//返回结果,如果是相同时间,则返回不同位置的值
5659
int iIndex = 0;
5760
if (bSameTime)

Classes/TankGame.cpp

+96-38
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,17 @@ void CTankGame::Play(float dt)
8282
//状态切换, 如果BOSS阶段没有开启,此时所有坦克已经死亡,则切换到暂停状态
8383
if (!m_bBossFlag && m_enGameState == GAMESTATE_RUNNING && CheckAllTankDead())
8484
{
85-
//切换到暂停状态
85+
//切换到暂停状态
8686
m_enGameState = GAMESTATE_PAUSE;
8787

8888
//重置时间
8989
m_fWaitRefreshTime = 0;
90+
91+
//清除所有子弹
92+
for (int i = 0; i < BULLET_MAXNUM; ++i)
93+
{
94+
m_arrBullet[i].m_bValid = false;
95+
}
9096
}
9197

9298
if (GAMESTATE_OVER == m_enGameState)
@@ -198,8 +204,10 @@ void CTankGame::Play(float dt)
198204
m_stBoss.m_bDead = false;
199205

200206
//随机发射子弹时间间隔
201-
m_stBoss.m_fFireMaxTime = Random(BOSS_FIRE_MIN_INTERVAL - 20 * m_iSpeed, BOSS_FIRE_MAX_INTERVAL - 50 * m_iSpeed);
207+
m_stBoss.m_fFireMaxTime = Random(BOSS_FIRE_MIN_INTERVAL / 10 - m_iSpeed, BOSS_FIRE_MAX_INTERVAL / 10 - 3 * m_iSpeed) * 10;
202208
m_stBoss.m_fFireWaitTime = 0;
209+
m_stBoss.m_iMaxStep = 15 + m_iSpeed; //击中最大次数
210+
m_stBoss.m_iCurStep = 0;
203211

204212
//方向只有左右
205213
int iDirection = Random(DIR_MIN, DIR_MAX);
@@ -235,7 +243,7 @@ bool CTankGame::GetBrickState(int iRowIndex, int iColIndex)
235243
stTargetPos.m_iColIdx = iColIndex;
236244

237245
//自己
238-
if (DrawTank(m_stSelfTank.m_stPos, m_stSelfTank.m_iDirection, stTargetPos))
246+
if (DrawTank(m_stSelfTank.m_stPos, m_bBossFlag ? DIR_UP : m_stSelfTank.m_iDirection, stTargetPos))
239247
{
240248
return true;
241249
}
@@ -462,7 +470,7 @@ bool CTankGame::CreateTank(float dt)
462470
stData.m_iCurStep = 0;
463471
stData.m_iMaxStep = Random(0, TANK_MOVE_MAXSTEP);
464472
stData.m_fFireWaitTime = 0;
465-
stData.m_fFireMaxTime = Random(50, BULLET_CREATE_MAXTIME - 450 * m_iSpeed);
473+
stData.m_fFireMaxTime = Random(1, (BULLET_CREATE_MAXTIME - 350 * m_iSpeed) / 100) * 100;
466474

467475
//坦克创建数量更新
468476
++m_iTankCreateCount;
@@ -521,7 +529,8 @@ bool CTankGame::TankMove(float dt)
521529
{
522530
//时间更新
523531
m_fTankMoveTime += dt;
524-
if (m_fTankMoveTime < TANK_MOVE_INTERVAL - 70 * m_iSpeed)
532+
float fMaxTime = TANK_MOVE_INTERVAL - 50 * m_iSpeed + (m_bBossFlag ? 200 : 0);
533+
if (m_fTankMoveTime < fMaxTime)
525534
{
526535
return false;
527536
}
@@ -825,41 +834,73 @@ bool CTankGame::SelfTankMove( float dt )
825834
//重置
826835
m_fSelfMoveTime = 0;
827836

828-
for (int i = DIR_MIN; i < DIR_MAX; ++i)
837+
if (m_bBossFlag)
829838
{
830-
if (!m_arrBtnState[i])
839+
if (m_arrBtnState[DIR_LEFT])
831840
{
832-
continue;
841+
m_stSelfTank.m_iDirection = DIR_LEFT;
833842
}
834-
835-
POSITION stNextPos;
836-
837-
if (m_stSelfTank.m_iDirection != i)
843+
else if (m_arrBtnState[DIR_RIGHT])
838844
{
839-
m_stSelfTank.m_iDirection = i;
840-
841-
stNextPos = m_stSelfTank.m_stPos;
845+
m_stSelfTank.m_iDirection = DIR_RIGHT;
842846
}
843847
else
844848
{
845-
//方向与当前方向一致,检查下一个位置是否有效
846-
if (!GetNextPos(-1, stNextPos) || !CheckPos(-1, stNextPos))
847-
{
848-
return false;
849-
}
850-
851-
//更新位置
852-
m_stSelfTank.m_stPos = stNextPos;
849+
return false;
850+
}
853851

854-
//最后一行/列不显示
855-
m_pGameScene->UpdateBrick(stNextPos.m_iRowIdx + POS_CHANGE_LIST[i * 4], stNextPos.m_iColIdx + POS_CHANGE_LIST[i * 4 + 1], false, false);
856-
m_pGameScene->UpdateBrick(stNextPos.m_iRowIdx + POS_CHANGE_LIST[i * 4 + 2], stNextPos.m_iColIdx + POS_CHANGE_LIST[i * 4 + 3], false, false);
852+
//检查下一个位置是否有效
853+
POSITION stNextPos;
854+
if (!GetNextPos(-1, stNextPos))
855+
{
856+
return false;
857857
}
858858

859+
//更新
860+
m_stSelfTank.m_stPos = stNextPos;
859861
//画我方坦克
860862
m_pGameScene->UpdateBricks(stNextPos.m_iRowIdx - 1, stNextPos.m_iColIdx - 1, stNextPos.m_iRowIdx + 2, stNextPos.m_iColIdx + 2);
863+
861864
return true;
862865
}
866+
else
867+
{
868+
for (int i = DIR_MIN; i < DIR_MAX; ++i)
869+
{
870+
if (!m_arrBtnState[i])
871+
{
872+
continue;
873+
}
874+
875+
POSITION stNextPos;
876+
877+
if (m_stSelfTank.m_iDirection != i)
878+
{
879+
m_stSelfTank.m_iDirection = i;
880+
881+
stNextPos = m_stSelfTank.m_stPos;
882+
}
883+
else
884+
{
885+
//方向与当前方向一致,检查下一个位置是否有效
886+
if (!GetNextPos(-1, stNextPos) || !CheckPos(-1, stNextPos))
887+
{
888+
return false;
889+
}
890+
891+
//更新位置
892+
m_stSelfTank.m_stPos = stNextPos;
893+
894+
//最后一行/列不显示
895+
m_pGameScene->UpdateBrick(stNextPos.m_iRowIdx + POS_CHANGE_LIST[i * 4], stNextPos.m_iColIdx + POS_CHANGE_LIST[i * 4 + 1], false, false);
896+
m_pGameScene->UpdateBrick(stNextPos.m_iRowIdx + POS_CHANGE_LIST[i * 4 + 2], stNextPos.m_iColIdx + POS_CHANGE_LIST[i * 4 + 3], false, false);
897+
}
898+
899+
//画我方坦克
900+
m_pGameScene->UpdateBricks(stNextPos.m_iRowIdx - 1, stNextPos.m_iColIdx - 1, stNextPos.m_iRowIdx + 2, stNextPos.m_iColIdx + 2);
901+
return true;
902+
}
903+
}
863904

864905
return false;
865906
}
@@ -898,7 +939,7 @@ bool CTankGame::TankFire(float dt)
898939
m_stBoss.m_fFireWaitTime = 0;
899940

900941
//随机时间
901-
m_stBoss.m_fFireMaxTime = Random(BOSS_FIRE_MIN_INTERVAL - 20 * m_iSpeed, BOSS_FIRE_MAX_INTERVAL - 50 * m_iSpeed);
942+
m_stBoss.m_fFireMaxTime = Random(BOSS_FIRE_MIN_INTERVAL / 10 - m_iSpeed, BOSS_FIRE_MAX_INTERVAL / 10 - 3 * m_iSpeed) * 10;
902943
m_stBoss.m_fFireWaitTime = 0;
903944

904945
//创建子弹
@@ -924,7 +965,7 @@ bool CTankGame::TankFire(float dt)
924965
}
925966

926967
//随机时间
927-
refData.m_fFireMaxTime = Random(50, BULLET_CREATE_MAXTIME - 450 * m_iSpeed);
968+
refData.m_fFireMaxTime = Random(1, (BULLET_CREATE_MAXTIME - 350 * m_iSpeed) / 100) * 100;
928969
refData.m_fFireWaitTime = 0;
929970

930971
//创建子弹
@@ -1017,6 +1058,11 @@ int CTankGame::GetBulletFireTankIndex(const POSITION& stBulletPos, int iCamp)
10171058
{
10181059
if (iCamp == CAMP_A)
10191060
{
1061+
if (m_bBossFlag && stBulletPos == m_stBoss.m_stPos)
1062+
{
1063+
return 1;
1064+
}
1065+
10201066
for (int i = 0; i < TANK_MAXNUM; ++i)
10211067
{
10221068
if (m_arrTank[i].m_bDead)
@@ -1103,19 +1149,31 @@ void CTankGame::BulletShoot()
11031149
{
11041150
if (refData.m_iCamp == CAMP_A)
11051151
{
1106-
TANK_DATA& refTankData = m_arrTank[iTankIdx];
1152+
if (m_bBossFlag)
1153+
{
1154+
if (++m_stBoss.m_iCurStep >= m_stBoss.m_iMaxStep)
1155+
{
1156+
m_enGameState = GAMESTATE_PASS;
1157+
}
1158+
1159+
log("m_iCurStep=%d m_iMaxStep=%d", m_stBoss.m_iCurStep, m_stBoss.m_iMaxStep);
1160+
}
1161+
else
1162+
{
1163+
TANK_DATA& refTankData = m_arrTank[iTankIdx];
11071164

1108-
//敌方坦克死亡
1109-
refTankData.m_bDead = true;
1165+
//敌方坦克死亡
1166+
refTankData.m_bDead = true;
11101167

1111-
//重画对应区域状态
1112-
POSITION& stDeadTankPos = refTankData.m_stPos;
1113-
m_pGameScene->UpdateBricks(stDeadTankPos.m_iRowIdx - 1, stDeadTankPos.m_iColIdx - 1,
1114-
stDeadTankPos.m_iRowIdx + 2, stDeadTankPos.m_iColIdx + 2);
1168+
//重画对应区域状态
1169+
POSITION& stDeadTankPos = refTankData.m_stPos;
1170+
m_pGameScene->UpdateBricks(stDeadTankPos.m_iRowIdx - 1, stDeadTankPos.m_iColIdx - 1,
1171+
stDeadTankPos.m_iRowIdx + 2, stDeadTankPos.m_iColIdx + 2);
11151172

1116-
//分数增加
1117-
m_iScore += TANK_KILL_ADD_SCORE;
1118-
m_pGameScene->UpdateScore(m_iScore);
1173+
//分数增加
1174+
m_iScore += TANK_KILL_ADD_SCORE;
1175+
m_pGameScene->UpdateScore(m_iScore);
1176+
}
11191177
}
11201178
else if (refData.m_iCamp == CAMP_B)
11211179
{

Classes/TankGame.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ class CTankGame : public CSceneBase
175175

176176
BULLET_MOVE_INTERVAL = 40, //子弹移动时间间隔
177177

178-
BULLET_CREATE_MAXTIME = 5500, //最大发射子弹时间
178+
BULLET_CREATE_MAXTIME = 4500, //最大发射子弹时间
179179

180180
TANK_CREATE_TIME = TANK_MOVE_INTERVAL, //坦克创建时间间隔
181181

182182
TANK_MOVE_MAXSTEP = 10, //坦克移动最大步数
183183

184184
TANK_SELF_MOVE_INTERVAL = 55, //我方坦克每次移动等待时间
185185

186-
TANK_SELF_FIRE_TIME = 200, //每次发射子弹后间隔
186+
TANK_SELF_FIRE_TIME = 300, //每次发射子弹后间隔
187187

188188
BOOM_SHOWCOUNT = 16, //闪烁显示爆炸效果次数
189189

@@ -195,11 +195,11 @@ class CTankGame : public CSceneBase
195195

196196
TANK_KILL_ADD_SCORE = 10, //杀掉一个坦克增加的分数
197197

198-
TANK_CREATE_MAXCOUNT = 4, //每一个等级坦克创建最大数量
198+
TANK_CREATE_MAXCOUNT = 30, //每一个等级坦克创建最大数量
199199

200-
BOSS_FIRE_MIN_INTERVAL = 500, //boss发射子弹最小时间间隔
200+
BOSS_FIRE_MIN_INTERVAL = 600, //boss发射子弹最小时间间隔
201201

202-
BOSS_FIRE_MAX_INTERVAL = 2000, //boss发射子弹最大时间间隔
202+
BOSS_FIRE_MAX_INTERVAL = 1300, //boss发射子弹最大时间间隔
203203
};
204204

205205
//阵营

Release/BrickGame.apk

1.19 MB
Binary file not shown.

Resources/Sounds/star.png

-2.79 KB
Binary file not shown.

Resources/res/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)