#include "GameScene.h"
#include <math.h>
#include "Logic/GameLogic.h"
#include "ClientDefine.h"
#include "tool/libuitl.h"
#include "tool/Cjni.h"
#include "MainScene.h"
#include "LanguageConfig.h"
using namespace rapidjson;
using namespace JNI;
bool Box::init(int kind){
if (!Sprite::init()){
return false;
}
string fileName = "img/box" + cocos2d::Value(kind).asString() + ".png";
this->setTexture(fileName);
this->setScale(0.85);
return true;
}
void Box::onEnter(){
Sprite::onEnter();
//stop();
}
void Box::setTargetPos(int target){
targetPos = target;
while (targetPos - pos < GameScene::MIN_SPACE * 2){
targetPos += GameScene::MIN_SPACE;
}
}
void Box::run(function<void()> backFun){
startPos = pos;
process = 0;
speed = 1;
addSpeed = 0;
targetPos = -1;
step = 0;
this->setVisible(true);
this->unschedule(schedule_selector(Box::starHandler));
this->schedule(schedule_selector(Box::runHandler), 0.03);
this->backFun = backFun;
}
void Box::starFast(){
starNum = 0;
this->unschedule(schedule_selector(Box::starHandler));
this->schedule(schedule_selector(Box::starFastHandler), 0.1);
}
void Box::stop(){
step = 4;
starNum = 0;
running = false;
this->unschedule(schedule_selector(Box::runHandler));
this->schedule(schedule_selector(Box::starHandler), 0.5);
}
//旋转
void Box::runHandler(float t)
{
if (step == 0)
{
process += 0.33;
if (process >= 5)
step = 1;
if (pos != startPos + (int)process && !backFun){
CustomTool::playSoundEffect("sounds/s" + cocos2d::Value((9 - (int)process) % 10).asString() + ".mp3");
}
} else if(step == 1){
process += speed;
if(((int)process)%100==0)
{
CustomTool::playSoundEffect("sounds/s8.mp3");
}
if (process > GameScene::ROUND_COUNT && targetPos > -1)
{
startPos = pos;
process = 0;
speed = 1;
runProcess = targetPos - pos;
addSpeed = - speed * speed * 0.5 / runProcess;
step = 2;
}
} else if (step == 2){
float prev_speed = speed;
speed += addSpeed;
process += (speed + prev_speed) * 0.5;
if (process >= runProcess || speed < 0.01)
{
speed = 0;
process = runProcess;
this->unschedule(schedule_selector(Box::runHandler));
runStop();
}
}
int p = (startPos + (int)process) % GameScene::ROUND_COUNT;
if (pos != p && step > 0 && !backFun)
{
CustomTool::playSoundEffect("sounds/s8.mp3");// +cocos2d::Value(((int)process) % 10).asString() + ".mp3");
}
this->setPos(p);
if(backFun)
backFun();
}
void Box::runStop(){
GameScene::gamePtr->getResult();
}
void Box::starHandler(float t){
if (running){
this->setVisible(true);
return;
}
starNum++;
this->setVisible(starNum % 2);
}
void Box::starFastHandler(float t){
starNum++;
this->setVisible(starNum % 2);
if (starNum > 20){
this->setVisible(true);
this->unschedule(schedule_selector(Box::starFastHandler));
GameScene::gamePtr->playResult();
}
}
void Box::setPos(int pos){
if (pos < 0){
pos += GameScene::ROUND_COUNT;
} else if (pos >= GameScene::ROUND_COUNT){
pos %= GameScene::ROUND_COUNT;
}
this->pos = pos;
Vec2 v;
if (pos < 7){
v.x = 68 + pos * 57;
v.y = 662;
} else if (pos < 13){
v.x = 410;
v.y = 662 - (pos - 6) * 57;
} else if(pos < 19){
v.x = 410 - (pos - 12) * 57;
v.y = 318;
} else{
v.x = 68;
v.y = 318 + (pos - 18) * 57;
}
this->setPosition(v);
}
//==================================================
GameScene* GameScene::gamePtr = nullptr;
bool GameScene::SoundOpen = true;
GameScene::GameScene(){
GameScene::gamePtr = this;
getcoinid = 0;
}
GameScene::~GameScene(){
GameScene::gamePtr = nullptr;
}
Scene* GameScene::createScene(){
auto scene = Scene::create();
auto game = GameScene::create();
scene->addChild(game);
return scene;
}
bool GameScene::init()
{
if (!Layer::init())
{
return false;
}
//初始化游戏逻辑
GameLogic::GetInstance()->init();
widget = CustomTool::getCSUI("gameScene", this);
Button* startBtn = (Button*)widget->getChildByName("startBtn");
Button* cancelBtn = (Button*)widget->getChildByName("cancelBtn");
Button* halfBtn = (Button*)widget->getChildByName("halfBtn");
Button* doubleBtn = (Button*)widget->getChildByName("doubleBtn");
Button* smallBtn = (Button*)widget->getChildByName("smallBtn");
Button* bigBtn = (Button*)widget->getChildByName("bigBtn");
CheckBox* soundBox = (CheckBox*)widget->getChildByName("soundBox");
soundBox->addEventListenerCheckBox(this, checkboxselectedeventselector(GameScene::onSelected));
winNumLabel = (TextAtlas*)widget->getChildByName("winNum");
totalNumLabel = (TextAtlas*)widget->getChildByName("totalNum");
totalGold = GameLogic::GetInstance()->user.coin;
totalNumLabel->setStringValue(util::toString(totalGold));
winNumLabel->setStringValue("0");
pointNumLabel = (TextAtlas*)widget->getChildByName("pointNumLabel");
TextAtlas* timeNumLabel = (TextAtlas*)widget->getChildByName("timeNum");
timeNumLabel->setVisible(false);
for (int i = 1; i <= 8; i++)
{
cocos2d::ui::Button* betBtn = (cocos2d::ui::Button*)widget->getChildByName("betBtn" + cocos2d::Value(i).asString());
betBtn->addTouchEventListener(this, toucheventselector(GameScene::onTouch));
TextAtlas* label = (TextAtlas*)widget->getChildByName("betNum" + cocos2d::Value(i).asString());
label->setStringValue("00");
betLabels[i - 1] = label;
}
for (int i = 0; i < GameScene::ROUND_COUNT; i++)
{
boxArr[i] = Box::create(0);
//boxArr[i]->retain();
boxArr[i]->setPos(i);
boxArr[i]->setVisible(false);
widget->addChild(boxArr[i]);
}
lightLeft = nullptr;
lightRight = nullptr;
sprite = nullptr;
startBtn->addTouchEventListener(this, toucheventselector(GameScene::onTouch));
cancelBtn->addTouchEventListener(this, toucheventselector(GameScene::onTouch));
halfBtn->addTouchEventListener(this, toucheventselector(GameScene::onTouch));
doubleBtn->addTouchEventListener(this, toucheventselector(GameScene::onTouch));
smallBtn->addTouchEventListener(this, toucheventselector(GameScene::onTouch));
bigBtn->addTouchEventListener(this, toucheventselector(GameScene::onTouch));
box0 = Box::create();
widget->addChild(box0);
box1 = nullptr;
box2 = nullptr;
box3 = nullptr;
imgMap.insert(map<int, string>::value_type(1, "img/eat"));
imgMap.insert(map<int, string>::value_type(2, "img/xsy"));
imgMap.insert(map<int, string>::value_type(3, "img/xsx"));
imgMap.insert(map<int, string>::value_type(4, "img/xmg"));
imgMap.insert(map<int, string>::value_type(5, "img/dsy"));
imgMap.insert(map<int, string>::value_type(6, "img/dmg"));
imgMap.insert(map<int, string>::value_type(7, "img/khc"));
mm_imgs.insert(map<int, string>::value_type(0, "img/MM/MM_0000.png"));
mm_imgs.insert(map<int, string>::value_type(1, "img/MM/MM_0001.png"));
mm_imgs.insert(map<int, string>::value_type(2, "img/MM/MM_0002.png"));
mm_imgs.insert(map<int, string>::value_type(3, "img/MM/MM_0003.png"));
mm_imgs.insert(map<int, string>::value_type(4, "img/MM/MM_0004.png"));
mm_imgs.insert(map<int, string>::value_type(5, "img/MM/MM_0005.png"));
mm_imgs.insert(map<int, string>::value_type(6, "img/MM/MM_0006.png"));
step = 0;
/*
CustomTool::preloadBackgroundMusic("sounds/bg.mp3");
CustomTool::preloadEffect("sounds/run.mp3");
CustomTool::preloadEffect("sounds/bs.mp3");
CustomTool::preloadEffect("sounds/bswin.mp3");
CustomTool::preloadEffect("sounds/chidiao.mp3");
CustomTool::preloadEffect("sounds/train.mp3");
for (int i = 0; i < 8; i++){
CustomTool::preloadEffect("sounds/s" + cocos2d::Value(i + 1).asString() + ".mp3");
CustomTool::preloadEffect("sounds/w" + cocos2d::Value(i + 1).asString() + ".mp3");
}
CustomTool::preload
没有合适的资源?快使用搜索试试~ 我知道了~
cocos2d-x3.10 c++ 水果机
共155个文件
png:94个
mp3:31个
h:14个
需积分: 49 25 下载量 102 浏览量
2018-11-27
11:12:50
上传
评论 1
收藏 5.16MB RAR 举报
温馨提示
将网上别人的水果机用cocos2d-x 3.10进行了修正,做了一定的改良。仅供大家学习。
资源推荐
资源详情
资源评论
收起资源包目录
cocos2d-x3.10 c++ 水果机 (155个子文件)
GameScene.cpp 30KB
GameLogic.cpp 14KB
md5.cpp 9KB
3des.cpp 7KB
libutil.cpp 6KB
Cjni.cpp 6KB
MainScene.cpp 4KB
AppDelegate.cpp 4KB
CustomTool.cpp 3KB
Mod_Game.cpp 3KB
TimeLoading.cpp 2KB
XMLManager.cpp 1KB
LanguageConfig.cpp 1KB
3des.h 16KB
GameScene.h 4KB
ClientDefine.h 2KB
libuitl.h 1KB
GameLogic.h 1KB
md5.h 1KB
CustomTool.h 1KB
AppDelegate.h 987B
Cjni.h 636B
TimeLoading.h 604B
Mod_Game.h 592B
LanguageConfig.h 567B
MainScene.h 423B
XMLManager.h 295B
gameScene.json 58KB
BACK_GROUND.mp3 234KB
bg.mp3 219KB
w2.mp3 144KB
w6.mp3 144KB
w1.mp3 139KB
w4.mp3 130KB
w3.mp3 125KB
w9.mp3 124KB
w8.mp3 121KB
w7.mp3 116KB
w5.mp3 114KB
train.mp3 75KB
open.mp3 41KB
D_SEVEN.mp3 41KB
D_STAR.mp3 25KB
WATERMELON.mp3 24KB
BAR.mp3 18KB
chidiao.mp3 17KB
bswin.mp3 13KB
bs.mp3 12KB
TURN_START.mp3 10KB
s7.mp3 8KB
s4.mp3 8KB
s1.mp3 7KB
s8.mp3 7KB
s5.mp3 7KB
s6.mp3 7KB
s2.mp3 7KB
s3.mp3 5KB
run.mp3 3KB
coinGet.mp3 2KB
slotmachine.png 384KB
home.png 258KB
MM_0004.png 187KB
MM_0002.png 182KB
MM_0005.png 181KB
MM_0000.png 174KB
xsx1.png 173KB
MM_0003.png 166KB
MM_0001.png 161KB
MM_0006.png 150KB
dsy1.png 145KB
logos.png 138KB
xsy1.png 132KB
dmg1.png 123KB
xsx0.png 103KB
xmg1.png 103KB
logos2.png 95KB
dmg0.png 90KB
khc1.png 74KB
dsy0.png 60KB
xmg0.png 50KB
xsy0.png 43KB
eat.png 29KB
khc0.png 23KB
light0.png 14KB
play2.png 14KB
play.png 13KB
light1.png 11KB
b2.png 10KB
b7.png 10KB
b8.png 9KB
b5.png 9KB
de.png 9KB
b4.png 9KB
b6.png 9KB
b1.png 9KB
b3.png 9KB
b7p.png 9KB
b2p.png 8KB
add.png 8KB
b5p.png 8KB
共 155 条
- 1
- 2
资源评论
superdai
- 粉丝: 5
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功