#include "MainMenu.h"
#include "ChessRule.h"
#include <math.h>
USING_NS_CC;
CCScene* CCMainMenu::scene()
{
CCScene* pScene = CCScene::create();
CCMainMenu* pLayer = CCMainMenu::create();
pScene->addChild(pLayer, 3);
return pScene;
}
bool CCMainMenu::init()
{
if (!CCLayer::init())
{
return false;
}
s = CCDirector::sharedDirector()->getWinSize();
m_pBKG = CCSprite::create("background.png");
CCRect r = m_pBKG->getTextureRect();
m_pBKG->setAnchorPoint(CCPointZero);
m_pBKG->setPosition(ccp(0, 0));
m_pBKG->setScaleX(s.width/r.size.width*0.667f);
m_pBKG->setScaleY(s.height/r.size.height);
this->addChild(m_pBKG, -2);
m_pFocus = CCSprite::create("selected.png");
r = m_pFocus->getTextureRect();
m_pFocus->setScaleX(0.667f);
m_pFocus->setScaleY(0.6f);
m_pFocus->setVisible(false);
this->addChild(m_pFocus, 1);
m_fPositionX = s.width - r.size.width*0.667f;
m_fPositionY = s.height - r.size.height*0.6f;
CCMenuItemImage* pItem = CCMenuItemImage::create("new.jpg", "new.jpg", this, menu_selector(CCMainMenu::menuCallBack));
pItem->setPosition(ccp(m_fPositionX - s.width/6, m_fPositionY - s.height/8));
pItem->setAnchorPoint(CCPointZero);
pItem->setScaleX(0.667f);
pItem->setScaleY(0.6f);
CCMenu* pMenu = CCMenu::create(pItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
pItem = CCMenuItemImage::create("regret.jpg", "regret.jpg", this, menu_selector(CCMainMenu::menuRegret));
pItem->setPosition(ccp(m_fPositionX - s.width/6, m_fPositionY - s.height/8*2));
pItem->setAnchorPoint(CCPointZero);
pItem->setScaleX(0.667f);
pItem->setScaleY(0.6f);
pMenu = CCMenu::create(pItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
pItem = CCMenuItemImage::create("start.jpg", "start.jpg", this, menu_selector(CCMainMenu::menuStart));
pItem->setPosition(ccp(m_fPositionX - s.width/6, m_fPositionY - s.height/8*3));
pItem->setAnchorPoint(CCPointZero);
pItem->setScaleX(0.667f);
pItem->setScaleY(0.6f);
pMenu = CCMenu::create(pItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
pItem = CCMenuItemImage::create("difficulty.jpg", "difficulty.jpg", this, menu_selector(CCMainMenu::menuHardChoose));
pItem->setPosition(ccp(m_fPositionX - s.width/6, m_fPositionY - s.height/8*4));
pItem->setAnchorPoint(CCPointZero);
pItem->setScaleX(0.667f);
pItem->setScaleY(0.6f);
pMenu = CCMenu::create(pItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
m_pOpenVolice = CCMenuItemImage::create("openVolice.png", "openVolice.png", this, menu_selector(CCMainMenu::menuSoundChoose));
CCSize r2 = m_pOpenVolice->getContentSize();
m_pOpenVolice->setPosition(ccp(m_fPositionX - s.width/6 + r.size.width/2 - r2.width/6, m_fPositionY - s.height/8*5));
m_pOpenVolice->setAnchorPoint(CCPointZero);
m_pOpenVolice->setScaleX(0.667f);
m_pOpenVolice->setScaleY(0.6f);
pMenu = CCMenu::create(m_pOpenVolice, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1, 100);
m_pCloseVolice = CCMenuItemImage::create("closeVolice.png", "closeVolice.png", this, menu_selector(CCMainMenu::menuSoundChoose));
m_pCloseVolice->setPosition(ccp(m_fPositionX - s.width/6 + r.size.width/2 - r2.width/6, m_fPositionY - s.height/8*5));
m_pCloseVolice->setAnchorPoint(CCPointZero);
m_pCloseVolice->setScaleX(0.667f);
m_pCloseVolice->setScaleY(0.6f);
pMenu = CCMenu::create(m_pCloseVolice, NULL);
pMenu->setPosition(CCPointZero);
m_pCloseVolice->setVisible(false);
this->addChild(pMenu, 1, 101);
// coordinate info
this->initCoordinate();
// show time
this->initTimeShow();
// show chess
this->initListImage();
this->setTouchEnabled(true);
this->schedule(schedule_selector(CCMainMenu::updateTime), 1.0f);
//str = "../process.txt";
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 9; ++j)
{
g_cur_map[i][j] = g_chess_map[i][j];
}
}
//this->print();
m_enGameStatus = GAME_MENU;
m_enCurRole = ROLE_RED;
m_bVolice = true;
m_pCurChess = NULL;
m_bSelect = false;
m_bCollectCorrect = true;
m_pTargetChess = NULL;
m_nContinuous = 3;
m_nCur = 0;
m_enCurChessType = CHESS_NONE;
m_enTarChessType = CHESS_NONE;
m_nWin = -1;
m_vecSprite.reserve(10);
return true;
}
void CCMainMenu::setPos(CCSprite* pSprite, int x, int y)
{
pSprite->setAnchorPoint(CCPointZero);
pSprite->setScaleX(0.667f);
pSprite->setScaleY(0.6f);
pSprite->setPosition(ccp(x, y));
}
void CCMainMenu::setPosDigit(CCSprite* pSprite, int x, int y)
{
pSprite->setAnchorPoint(CCPointZero);
pSprite->setScaleX(0.2f);
pSprite->setScaleY(0.2f);
pSprite->setPosition(ccp(x, y));
}
void CCMainMenu::menuCallBack(CCObject* pSender)
{
m_enGameStatus = GAME_MENU;
m_enCurRole = ROLE_RED;
m_nChessTime = 600;
m_pCurChess = NULL;
m_bSelect = false;
m_bCollectCorrect = true;
m_pTargetChess = NULL;
m_nContinuous = 3;
m_nCur = 0;
m_nWin = -1;
m_pFocus->setVisible(false);
this->initChessPosition();
this->freeAll();
this->setNumberSprite(m_nChessTime);
this->unschedule(schedule_selector(CCMainMenu::updateFocus));
}
void CCMainMenu::menuRegret(CCObject* pSender)
{
this->freeOne();
this->freeOne();
if(m_pCurChess)
{
m_pFocus->setPosition(m_pCurChess->getPosition());
m_pFocus->setVisible(true);
m_bSelect = true;
m_pTargetChess = NULL;
}
}
void CCMainMenu::menuStart(CCObject* pSender)
{
if(m_enGameStatus != GAME_MENU)
{
return;
}
this->schedule(schedule_selector(CCMainMenu::updateFocus), 0.5f);
m_enGameStatus = GAME_RUNNING;
m_nChessTime = 600;
this->setNumberSprite(m_nChessTime);
}
void CCMainMenu::menuHardChoose(CCObject* pSender)
{
}
void CCMainMenu::menuSoundChoose(CCObject* pSender)
{
if(m_bVolice)
{
m_pOpenVolice->setVisible(false);
m_pCloseVolice->setVisible(true);
m_bVolice = false;
}
else
{
m_pOpenVolice->setVisible(true);
m_pCloseVolice->setVisible(false);
m_bVolice = true;
}
}
void CCMainMenu::updateTime(float dt)
{
if (GAME_RUNNING == m_enGameStatus)
{
--m_nChessTime;
if(m_nChessTime < 0)
{
m_nChessTime = 0;
}
else
{
this->setNumberSprite(m_nChessTime);
}
}
}
void CCMainMenu::updateFocus(float dt)
{
// alternate display
static int i = 0;
if(m_bSelect && m_pCurChess)
{
if(i == 0)
{
i = 1;
m_pFocus->setVisible(false);
}
else
{
i = 0;
m_pFocus->setVisible(true);
}
}
}
void CCMainMenu::ccTouchesEnded(CCSet* pTouches, CCEvent* pEvent)
{
if(m_enGameStatus != GAME_RUNNING)
{
return;
}
CCSetIterator it = pTouches->begin();
CCTouch* pTouch = (CCTouch*)(*it);
CCPoint touchPoint = pTouch->getLocationInView();
touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);
this->dealWithChess(touchPoint.x, touchPoint.y);
}
// core
void CCMainMenu::dealWithChess(float x, float y)
{
// judge boundary
if (x < 24 || x > 294 || y < 14 || y > 312)
{
return;
}
CCSprite* pSprite;
pSprite = this->getChessByCoord(x, y);
if(!this->getChessByCoord(x, y, 1))
{
// can not find coordinate
return;
}
int x0 = static_cast<int>(x);
int y0 = static_cast<int>(y);
if (pSprite)
{
if(m_bSelect)
{
m_pTargetChess = pSprite;
}
else
{
if (!m_nCur && m_enCurChessType < CHESS_BORDER)
{
return;
}
else if(m_nCur && m_enCurChessType > CHESS_BORDER)
{
return;
}
m_pFocus->setPosition(pSprite->getPosition());
m_pFocus->setVisible(true);
m_pCurChess = pSprite;
ox = x0;
oy = y0;
m_bSelect = false;
}
}
if (m_bSelect)
{
if(!this->judgeAction(x0, y0))
{
this->clean();
return;
}
if((m_enCurChessType < CHESS_BORDER && m_enTarChessType < CHESS_BORDER && m_enTarChessType > CHESS_NONE) ||
(m_enCurChe
没有合适的资源?快使用搜索试试~ 我知道了~
背包资源(cocoStudio)
共67个文件
png:43个
jpg:8个
h:6个
需积分: 9 34 下载量 41 浏览量
2014-01-20
15:49:49
上传
评论
收藏 1.47MB ZIP 举报
温馨提示
背包资源和代码(cocoStudio),实现背包基本功能.若有需要的网友们,可以下载看下,若有疑问或者建议,请留言,大家相互交流下
资源推荐
资源详情
资源评论
收起资源包目录
.zip (67个子文件)
代码和资源
Resources
zhanting.jpg 21KB
nonandu.jpg 16KB
start.jpg 21KB
d3.png 37KB
ra.png 7KB
bc.png 7KB
yingjiemian.png 38KB
bn.png 7KB
Icon-Small@2x.png 8KB
difficulty.jpg 21KB
rb.png 7KB
d7.png 26KB
d2.png 39KB
d1.png 26KB
background.png 454KB
ba.png 6KB
floor.jpg 29KB
rp.png 7KB
rr.png 7KB
d0.png 38KB
bk.png 7KB
d8.png 42KB
d4.png 32KB
iTunesArtwork 61KB
br.png 7KB
CloseSelected.png 5KB
bp.png 7KB
Icon-Small.png 5KB
d9.png 36KB
d6.png 40KB
bkg1.png 8KB
bkg2.png 8KB
rc.png 7KB
Icon@2x.png 16KB
d5.png 36KB
Icon-72.png 12KB
Info.plist 1KB
rn.png 7KB
regret.jpg 22KB
Default.png 87KB
rk.png 7KB
bb.png 7KB
Icon-Small-50.png 7KB
new.jpg 20KB
shuijiemian.png 38KB
CloseNormal.png 6KB
.DS_Store 15KB
closeVolice.png 9KB
icon.png 5KB
dian.png 8KB
queding.jpg 21KB
selected.png 3KB
HelloWorld.png 136KB
openVolice.png 8KB
Classes
MainMenu.cpp 20KB
AppDelegate.h 960B
HelloWorldScene.h 616B
ChessDefine.h 688B
ChessRule.cpp 5KB
HelloWorldScene.cpp 2KB
AppDelegate.cpp 1KB
MainMenu.h 3KB
WelCome.cpp 1KB
.DS_Store 6KB
ChessRule.h 779B
ChessDefine.cpp 1KB
WelCome.h 304B
共 67 条
- 1
资源评论
热血枫叶
- 粉丝: 388
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功