#include "GameBaseScene.h"
int GameBaseScene::tiledColsCount;
int GameBaseScene::tiledRowsCount;
bool** GameBaseScene::canPassGrid;
Vector<RicherPlayer*> GameBaseScene::players_vector;
Vector<Sprite*> GameBaseScene::pathMarkVector;
Scene* GameBaseScene::createScene()
{
auto scene = Scene::create();
auto layer = GameBaseScene::create();
scene->addChild(layer);
return scene;
}
bool GameBaseScene::init()
{
if ( !Layer::init() )
{
return false;
}
addMap();
initTiledGrid();
setWayPassToGrid();
addRightBanner();
drawTable(2);
addPathMark();
addPlayer();
addGoButton();
addNotificationObserver();
addDice();
addDigiteRoundSprite();
refreshRoundDisplay();
return true;
}
void GameBaseScene::addDigiteRoundSprite()
{
gameRoundCount=0;
auto frameCache = SpriteFrameCache::getInstance();
frameCache->addSpriteFramesWithFile("map/digital_round.plist");
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_0));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_1));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_2));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_3));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_4));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_5));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_6));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_7));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_8));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_9));
}
void GameBaseScene::refreshRoundDisplay()
{
for(auto it = refreshRoundVector.begin();it != refreshRoundVector.end();it++)
{
((Sprite*) *it)->setVisible(false);
}
refreshRoundVector.clear();
int count = gameRoundCount;
Sprite* st;
if(count ==0 )
{
st = Sprite::createWithSpriteFrame(digiteRoundVector.at(0));
addChild(st);
refreshRoundVector.pushBack(st);
}
while(count!=0)
{
st = Sprite::createWithSpriteFrame(digiteRoundVector.at(count%10));
addChild(st);
refreshRoundVector.pushBack(st);
count = count/10;
}
refreshRoundVector.reverse();
for(int i = 0;i< refreshRoundVector.size();i++)
{
Sprite * sp = refreshRoundVector.at(i);
sp->setPosition(ccp((tableStartPosition_x+50)+(i*25),50));
sp->setVisible(true);
}
}
void GameBaseScene::addPathMark()
{
Sprite* mark1 = Sprite::create(PATH_MARK_1);
Sprite* mark2 = Sprite::create(PATH_MARK_2);
Sprite* mark3 = Sprite::create(PATH_MARK_3);
Sprite* mark4 = Sprite::create(PATH_MARK_4);
Sprite* mark5 = Sprite::create(PATH_MARK_5);
Sprite* mark6 = Sprite::create(PATH_MARK_6);
mark1->setAnchorPoint(ccp(0,0));
mark2->setAnchorPoint(ccp(0,0));
mark3->setAnchorPoint(ccp(0,0));
mark4->setAnchorPoint(ccp(0,0));
mark5->setAnchorPoint(ccp(0,0));
mark6->setAnchorPoint(ccp(0,0));
mark1->setVisible(false);
mark2->setVisible(false);
mark3->setVisible(false);
mark4->setVisible(false);
mark5->setVisible(false);
mark6->setVisible(false);
addChild(mark1);
addChild(mark2);
addChild(mark3);
addChild(mark4);
addChild(mark5);
addChild(mark6);
pathMarkVector.pushBack(mark1);
pathMarkVector.pushBack(mark2);
pathMarkVector.pushBack(mark3);
pathMarkVector.pushBack(mark4);
pathMarkVector.pushBack(mark5);
pathMarkVector.pushBack(mark6);
}
void GameBaseScene::drawPathColor(std::vector<int> rowVector,std::vector<int> colVector)
{
int stepsCount = rowVector.size()-1;
for(int i=1;i<rowVector.size();i++)
{
pathMarkVector.at(i-1)->setPosition(ccp(colVector[i]*32,rowVector[i]*32));
pathMarkVector.at(i-1)->setVisible(true);
}
}
void GameBaseScene::addDice()
{
diceFrameCache= SpriteFrameCache::getInstance();
diceFrameCache->addSpriteFramesWithFile("map/dice.plist","map/dice.png");
Vector<SpriteFrame*> diceVector ;
char name[20];
memset(name, 0, 20);
for (int i=1; i<=6; i++)
{
sprintf(name, "dice_%02d.png",i);
diceVector.pushBack(diceFrameCache->getSpriteFrameByName(name));
}
if(!AnimationCache::getInstance()->getAnimation("dice_animation"))
{
AnimationCache::getInstance()->addAnimation(Animation::createWithSpriteFrames(diceVector,0.1),"dice_animation");
}
dice_animate = Animate::create(AnimationCache::getInstance()->getAnimation("dice_animation"));
dice_animate->retain();
diceSprite =Sprite::createWithSpriteFrame(diceFrameCache->getSpriteFrameByName("dice_01.png"));
diceSprite->setPosition(ccp(tableStartPosition_x+2*tableWidth,tableStartPosition_y-tableHeight*4.5));
addChild(diceSprite);
diceSprite->runAction(RepeatForever::create(dice_animate));
}
void GameBaseScene::addNotificationObserver()
{
NotificationCenter::getInstance()->addObserver(
this,
callfuncO_selector(GameBaseScene::receivedMsgForGo),
MSG_GO,
NULL);
}
void GameBaseScene::receivedMsgForGo(Object* data)
{
int retMsgType =((String*)data)->intValue();
Vector<Node*> vecMenuItem = getMenu()->getChildren();
Size winSize = Director::getInstance()->getWinSize();
if(retMsgType ==1)
{
for(auto it=vecMenuItem.begin();it!=vecMenuItem.end();it++)
{
Node* node = dynamic_cast<Node*>(*it);
MoveBy* moveBy = MoveBy::create(0.3,ccp(-(node->getContentSize().width)*2,0));
node->runAction(moveBy);
}
diceSprite->resume();
gameRoundCount++;
refreshRoundDisplay();
}else
{
for(auto it=vecMenuItem.begin();it!=vecMenuItem.end();it++)
{
Node* node = dynamic_cast<Node*>(*it);
MoveBy* moveBy = MoveBy::create(0.3,ccp((node->getContentSize().width)*2,0));
//RotateBy* rotateBy =RotateBy::create(1,360,10);
//Action* action =Spawn::create(moveBy,rotateBy,NULL);
node->runAction(moveBy);
}
char temp[20];
memset(temp, 0, 20);
sprintf(temp, "dice_%02d.png",randNumber);
diceSprite->setSpriteFrame(diceFrameCache->getSpriteFrameByName(temp));
diceSprite->pause();
}
log("received go message is: %d",retMsgType);
}
void GameBaseScene::setWayPassToGrid()
{
TMXLayer* wayLayer = _map->layerNamed("way");
Size _mapSize = wayLayer->getLayerSize();
for (int j = 0; j < _mapSize.width; j++) {
for (int i = 0; i < _mapSize.height; i++) {
Sprite* _sp = wayLayer->tileAt(Point(j, i));
if (_sp)
{
float x = _sp->getPositionX();
float y = _sp->getPositionY();
int col = x/tiledWidth;
int row = y/tiledHeight;
canPassGrid[row][col] = true;
Vec2 p = _sp->getPosition();
wayLayerPass_vector.push_back(p);
log("canPassGrid row= %d ,col =%d ,canpass = %d" ,row,col,canPassGrid[row][col]);
}
}
}
log("setWayPassToGrid finished");
}
void GameBaseScene::addGoButton()
{
Menu* menu = Menu::create();
menu->setPosition(CCPointZero);
setMenu(menu);
MenuItemImage* goMenuItemButton = MenuItemImage::create("map/go_normal.png", "map/go_press.png", this, menu_selector(GameBaseScene::goButtonCallback));
goMenuItemButton->setPosition(ccp(tableStartPosition_x+2*tableWidth,tableStartPosition_y-tableHeight*6));
menu->addChild(goMenuItemButton);
addChild(menu);
}
void GameBaseScene::goButtonCallback(cocos2d::CCObject *pSender)
{
log("go button clicked");
randNumber = rand()%6 + 1;
RouteNavigation::getInstance()->getPath(player1,randNumber,canPassGrid,tiledRowsCount,tiledColsCount);
std::vector<int> colVector = RouteNavigation::getInstance()->getPathCols_vector();
std::vector<int> rowVector = RouteNavigation::getInstance()->getPathRow_vector();
for(int i=0;i<rowVector.size();i++)
{
log(" rowVector row is %d --- colVector col is %d",rowVector[i],colVector[i]);
}
NotificationCenter::getInstance()->postNotification(MSG_GO,String::create("0"));
player1->startGo(rowVector,colV
没有合适的资源?快使用搜索试试~ 我知道了~
Cocos2d-x 3.2 大富翁游戏项目开发-第十二部分 显示合计数器
共61个文件
png:34个
h:11个
cpp:10个
5星 · 超过95%的资源 需积分: 9 71 下载量 11 浏览量
2014-12-28
11:52:04
上传
评论
收藏 2.13MB RAR 举报
温馨提示
Cocos2d-x 3.2 大富翁游戏项目开发-第十二部分 显示合计数器
资源推荐
资源详情
资源评论
收起资源包目录
richer1227_第十二部分.rar (61个子文件)
richer1227_第十二部分
Classes
SplashScene.cpp 3KB
AppDelegate.cpp 1KB
MapChooseScene.h 1KB
RicherPlayer.cpp 5KB
SplashScene.h 697B
MapChooseScene.cpp 4KB
RicherGameController.cpp 3KB
RicherPlayer.h 1KB
SeaScene.h 361B
RouteNavigation.h 718B
SeaScene.cpp 784B
GameBaseScene.cpp 13KB
PopupLayer
PopupLayer.h 1KB
PopupLayer.cpp 5KB
ConstUtil.h 2KB
RicherGameController.h 1KB
MenuScene.h 1KB
AppDelegate.h 947B
MenuScene.cpp 7KB
RouteNavigation.cpp 4KB
GameBaseScene.h 2KB
Resources
popuplayer
button_bg3.png 543B
dialog_bg.png 5KB
button_bg2.png 554B
button_bg1.png 546B
normal_menu.9.png 673B
normal_menu.png 6KB
ke.png 9KB
ji.png 9KB
cheng.png 8KB
press_menu.png 6KB
press_menu.9.png 523B
rainbow.png 37KB
fonts
Marker Felt.ttf 25KB
menuLogo.png 135KB
map
right_banner.png 53KB
mark3.png 5KB
player2.png 7KB
mark1.png 4KB
digital_round.png 15KB
stage_background2.png 579KB
sea_item.png 235KB
player1_anim.plist 8KB
dice.png 5KB
sea.tmx 2KB
mark2.png 5KB
go_press.png 11KB
moon_item.png 130KB
player2_anim.png 40KB
player2_anim.plist 8KB
mark6.png 5KB
player1.png 7KB
digital_round.plist 5KB
mark5.png 5KB
dice.plist 3KB
sea.png 559KB
player1_anim.png 44KB
beach_item.png 195KB
mark4.png 4KB
go_normal.png 10KB
mai.png 9KB
共 61 条
- 1
资源评论
- woaibcb20082015-03-20资源很好 帮我很多忙
- qq7092401322015-06-29很好用,感谢分享!
- k4631348812015-09-11很好用,感谢分享!
lideguo1979
- 粉丝: 148
- 资源: 77
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功