1坦克大战.rar

  • HHope
    了解作者
  • C/C++
    开发工具
  • 57KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2019-10-03 18:06
    上传日期
游戏中设计了武器、敌方、我方等,攻击可掉血等功能
1坦克大战.rar
  • 坦克大战
  • CommonClass_2010.lib
    233.8KB
  • TankPlayer.h
    276B
  • Weapon.cpp
    272B
  • LessonX.h
    2.4KB
  • Bullet.h
    370B
  • Bullet.cpp
    1.6KB
  • Weapon.h
    838B
  • Tank.h
    758B
  • TankEnemy.h
    785B
  • CommonClass.h
    38.6KB
  • Main.cpp
    2KB
  • TankPlayer.cpp
    1.7KB
  • Tank.cpp
    158B
  • LessonX.cpp
    11.3KB
  • TankEnemy.cpp
    3.6KB
内容介绍
#include <stdio.h> #include "commonClass.h" #include "lessonX.h" CGameMain g_GameMain; int g_iMap[11][13] = //0空地,1木头,2海洋,3铁皮,4地板,5草丛 { { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 }, { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 }, { 0, 0, 2, 0, 0, 1, 0, 1, 0, 0, 2, 0, 0 }, { 0, 0, 2, 1, 1, 5, 3, 5, 1, 1, 2, 0, 0 }, { 0, 0, 0, 5, 0, 1, 0, 1, 0, 5, 0, 0, 0 }, { 0, 0, 0, 5, 4, 4, 4, 4, 4, 5, 0, 0, 0 }, { 0, 0, 0, 5, 0, 1, 0, 1, 0, 5, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0 }, { 0, 0, 0, 0, 0, 3, 1, 3, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0 } }; CGameMain::CGameMain() { m_iGameState = 0; m_iBulletNum = 0; m_iPlayerBulletNum = 0; m_iTankEnemyNum = 0; m_iGameCount = 0; m_iScore = 0; m_iMaxScore = 0; m_iEnemy = 20; m_iLife = 3; m_iLevel = 1; m_iMaxTanksNum = 4; m_fGameTime = 0.0f; m_fEnemyCreateTime = 0.0f; m_pSplash = new CSprite("splash"); m_pStart = new CSprite("start"); m_pScore = new CTextSprite("score"); m_pMaxScore = new CTextSprite("maxScore"); m_pEnemy = new CTextSprite("enemyNum"); m_pLife = new CTextSprite("life"); m_pLevel = new CTextSprite("level"); } CGameMain::~CGameMain() { delete m_pSplash; delete m_pStart; } void CGameMain::GameMainLoop( float fDeltaTime ) { switch( GetGameState() ) { case 1: { GameInit(); SetGameState(2); } break; case 2: { if (!m_pTankPlayer->spriteIsDead() && !m_pAim_nor->spriteIsDead() && m_iEnemy > 0) { GameRun( fDeltaTime ); } else { GameEnd(fDeltaTime); SetGameState(0); } } break; case 0: default: break; }; } void CGameMain::GameInit() { m_pSplash->SetSpriteVisible(false); m_pStart->SetSpriteVisible(false); loadMap(); m_pTankPlayer = new TankPlayer("myplayer"); m_pTankPlayer->CloneSprite("player"); m_pTankPlayer->init(); m_pAim_nor = new Weapon("myAim"); m_pAim_nor->CloneSprite("aim_nor"); m_pAim_nor->SetSpriteCollisionReceive(true); m_pAim_nor->SetSpritePosition(0, 20); m_pGameOver = new CSprite("gameOver"); m_pGameOver->CloneSprite("gameover"); m_pGameOver->SetSpritePosition(0, 60); m_pGameOver->SetSpriteVisible(true); m_vWeapon.push_back(m_pTankPlayer); m_vWeapon.push_back(m_pAim_nor); m_iBulletNum = 0; m_iPlayerBulletNum = 0; m_iTankEnemyNum = 0; m_iScore = 0; m_iEnemy = 20; m_iLife = 3; m_iLevel = 0; m_iMaxTanksNum = 4; m_fEnemyCreateTime = 5.0f; m_fGameTime = 0.0f; FILE * fp = fopen("save.txt", "r+"); if (fp) { fread(&m_iMaxScore, sizeof(int), 1, fp); fclose(fp); } m_pMaxScore = new CTextSprite("maxScore"); m_pMaxScore->SetTextValue(m_iMaxScore); m_pLife->SetTextValue(m_iLife); m_pLevel->SetTextValue(m_iLevel); } void CGameMain::GameRun( float fDeltaTime ) { if (m_iMaxTanksNum > 0 && m_iEnemy > 3) { addTankEnemy(fDeltaTime); } for (int i = 0; i < m_vWeapon.size(); i++) { if (!m_vWeapon[i]->spriteIsDead()) { m_vWeapon[i]->move(fDeltaTime); m_vWeapon[i]->enemyFire(fDeltaTime); } else { delWeaponByName(m_vWeapon[i]->GetName()); } } m_fGameTime += m_fGameTime; m_pScore->SetTextValue(m_iScore); m_pMaxScore->SetTextValue(m_iMaxScore); m_pEnemy->SetTextValue(m_iEnemy); m_pLife->SetTextValue(m_iLife); m_pLevel->SetTextValue(m_iLevel); } void CGameMain::GameEnd(float delGameOver) { FILE * fp = fopen("save.txt", "w+"); if (m_iScore>m_iMaxScore) fwrite(&m_iScore, sizeof(int), 1, fp); fclose(fp); m_pEnemy->SetTextValue(0); m_pLife->SetTextValue(0); m_pGameOver->SpriteMoveTo(0, 0, 100, true); deleteAllSprite(); } void CGameMain::OnKeyDown(const int iKey, const bool bAltPress, const bool bShiftPress, const bool bCtrlPress){ if (GetGameState() == 0) { if (iKey != KEY_NULL) { if (GetGameCount() == 0) { m_iGameState = 1; } else { m_pGameOver->SetSpriteVisible(false); m_pSplash->SetSpriteVisible(true); m_pStart->SetSpriteVisible(true); m_iGameCount = 0; } } } if (GetGameState() == 2) { m_pTankPlayer->move(iKey, true); //防止发不了子弹 if (m_iPlayerBulletNum > 1 || m_iPlayerBulletNum < 0) { m_iPlayerBulletNum = 0; } if (m_iPlayerBulletNum == 0 && iKey == KEY_X) { m_pTankPlayer->playerFire(); m_iPlayerBulletNum++; } } } void CGameMain::OnKeyUp(const int iKey) { if (GetGameState() == 2) { m_pTankPlayer->move(iKey, false); } } void CGameMain::OnSpriteColWorldLimit(const char* szName, const int iColSide) { if (strstr(szName, "player") != NULL) { m_pTankPlayer->SetSpriteLinearVelocity(0, 0); } else if (strstr(szName, "enemy") != NULL) { Weapon* enemy = findWeaponByName(szName); enemy->SetSpriteLinearVelocity(0, 0); enemy->move(); } else if (strstr(szName, "bullet") != NULL) { Bullet* bullet = (Bullet*)findWeaponByName(szName); if (bullet->getOwner() == 1) { m_iPlayerBulletNum--; } bullet->setHP(0); } } void CGameMain::addBullet(int dir, float x, float y,int owner) { char* szName = CSystem::MakeSpriteName("bullet", m_iBulletNum); Bullet* pBullet = new Bullet(szName); pBullet->CloneSprite("bullet"); pBullet->SetSpriteWorldLimit(WORLD_LIMIT_KILL, -26, -22, 26, 22); pBullet->SetSpritePosition(x, y); pBullet->SetSpriteCollisionActive(true,true); pBullet->move(dir); m_iBulletNum++; if (owner == 1) { pBullet->setOwner(1); } else { pBullet->setOwner(0); } m_vWeapon.push_back(pBullet); } void CGameMain::addTankEnemy(float dTime) { m_fEnemyCreateTime += dTime; if (m_fEnemyCreateTime > 2) { char* szName = CSystem::MakeSpriteName("enemy", m_iTankEnemyNum); TankEnemy* m_pTankEnemy = new TankEnemy(szName); int enemyType = CSystem::RandomRange(0, 3); switch (enemyType) { case 0: m_pTankEnemy->CloneSprite("putong"); m_pTankEnemy->init(0); break; case 1: m_pTankEnemy->CloneSprite("zhuangjia"); m_pTankEnemy->init(1); break; case 2: m_pTankEnemy->CloneSprite("tuji"); m_pTankEnemy->init(2); break; case 3: m_pTankEnemy->CloneSprite("nice"); m_pTankEnemy->init(3); break; } m_iTankEnemyNum++; m_iMaxTanksNum--; m_vWeapon.push_back(m_pTankEnemy); m_fEnemyCreateTime = 0.0f; } } void CGameMain::loadMap() { char* szName; for (int i = 0; i < 11; i++) { for (int j = 0; j < 13; j++) { float x, y; if (g_iMap[i][j] == 1) { szName = CSystem::MakeSpriteName("muWall", j + i * 13 + i); Weapon* pWall = new Weapon(szName); pWall->CloneSprite("mu"); pWall->SetSpriteCollisionActive(false, true); pWall->SetSpriteCollisionResponse(COL_RESPONSE_CUSTOM); x = float(-24 + 4 * j); y = float(-20 + 4 * i); pWall->SetSpritePosition(x, y); m_vWeapon.push_back(pWall); } if (g_iMap[i][j] == 2) { szName = CSystem::MakeSpriteName("haiWall", j + i * 13 + i); Weapon* pWall = new Weapon(szName); pWall->CloneSprite("hai"); pWall->SetSpriteCollisionActive(false, true); pWall->SetSpriteCollisionResponse(COL_RESPONSE_CUSTOM); x = float(-24 + 4 * j); y = float(-20 + 4 * i); pWall->SetSpritePosition(x, y); m_vWeapon.push_back(pWall); } if (g_iMap[i][j] == 3) { szName = CSystem::MakeSpriteName("tieWall", j + i * 13 + i); Weapon* pWall = new Weapon(szName); pWall->CloneSprite("tie"); pWall->SetSpriteCollisionActive(false, true); pWall->SetSpriteCollisionResponse(COL_RESPONSE_CUSTOM); x = float(-24 + 4 * j); y = float(-20 + 4 * i); pWall->SetSpritePosition(x, y); m_vWeapon.push_back(pWall); } if (g_iMap[i][j] == 4) { szName = CSystem::MakeSpriteName("diban", j + i * 13 + i); Weapon* pWall = new Weapon(szName);
评论
    相关推荐
    • java版坦克大战游戏
      java 版坦克大战java 版坦克大战java 版坦克大战java 版坦克大战java 版坦克大战java 版坦克大战java 版坦克大战java 版坦克大战
    • 坦克大战游戏
      用JAVA编写的小游戏 代码 注解 都很细 很不错哦
    • 坦克大战游戏
      坦克大战游戏,简单的静态Java工程,纯Java代代码
    • 坦克大战游戏java
      自己觉得还不错,感兴趣的可以下载,了解了解,多少有价值
    • 3D坦克大战游戏
      Unity3D开发的3D坦克游戏,可以切换武器,运用了粒子系统使爆炸效果更加酷炫
    • 坦克大战游戏
      游戏运动了java中的线程,swing,画图等多方面知识,适合初学者学习
    • 坦克大战游戏源码
      喜欢游戏开发的就下载吧 代码简洁明了
    • C语言的坦克大战游戏
      一个c语言的坦克大战游戏,总共有四个文件夹分别装了地图、玩家坦克、电脑坦克以及游戏界面的信息。另外,在地图文件夹中还包括了地图编辑器可以使用。
    • 坦克大战游戏源码
      一个通过java编写的单机版坦克对战源码,可直接编译运行
    • C#坦克大战游戏
      C#坦克大战游戏源码