#include "Stdafx.h"
#include "AndroidUserItemSink.h"
#include "Config.h"
#include <fstream>
#include <sstream>
#include <time.h>
#include <stdio.h>
#include <memory>
#include <thread>
#include "Tools.h"
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define new new(_NORMAL_BLOCK,__FILE__,__LINE__)
#endif
//////////////////////////////////////////////////////////////////////////
//辅助时间
#define TIME_LESS 1 //最少时间
#define TIME_LESS_CHANGE_BULLET 60 //交换子弹的最少时间
//游戏时间
#define TIME_BUY_BULLET 3 //买子弹时间
#define TIME_FIRE 3 //发射子弹时间
#define TIME_CHANGE_BULLET 120 //交换子弹时间
#define TIME_LOCKTAGET 150
#define TIME_RANDOM_POINT 10 //每10秒随机一个触摸点
#define TIME_SCHEDULE_UPDATE 0.0166667 //0.01667秒是一帧
#define TIME_CEATE_BULLET 5 //每5秒创建一次子弹,子弹数量随机
#define TIME_HALF_SECOND 0.5 //半秒钟
////游戏时间
#define IDI_BUY_BULLET 1001//(IDI_ANDROID_ITEM_SINK+0) //买子弹定时器
#define IDI_FIRE 1002//(IDI_ANDROID_ITEM_SINK+1) //发射子弹定时器
#define IDI_CHANGE_BULLET 1003//(IDI_ANDROID_ITEM_SINK+2) //交换子弹定时器
#define IDI_CHANGE_BULLET_ONCE 1004//(IDI_ANDROID_ITEM_SINK+3) //交换子弹定时器
#define IDI_LOCKTARGET 1000
#define IDI_LOG_SIZE 1005
#define IDI_RANDOM_POINT 100 //随机一个点定时器
#define IDI_COLLISION_JUDGE 101 //碰撞检测定时器
#define IDI_CREATE_BULLET 102 //创建一次子弹定时器
#define IDI_SCHEDULE_CREATE 103 //鱼、子弹每一帧的运动,碰撞
#define IDI_HALF_SECOND 104 //半秒钟
#define MAX_CANNON_COST 1000 //修改版:10分一个炮,10分一次累加,到100分一个炮,100分累加一次,最高难1000分
#define MAX_CANNON_TYPEVALUE 19 //19种分值不同的炮
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180
#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180
#define SUB_IDI_FIRE 10000
//////////////////////////////////////////////////////////////////////////
// !! AI没有完全搞定
//构造函数
//当关闭服务器的时候,存在多个线程,应该先释放子线程里边的资源,再关闭主线程,用静态变量来保存主线程状态和子线程状态,即m_nMainState和m_nSubState,
//如果不用静态变量而用成员变量的话,如果关闭服务器调用destory()只会关闭一个机器人,其余机器人中的子线程还是没有释放,导致崩溃在子线程里边,所以必须要用静态变量。
int CAndroidUserItemSink::m_nMainState = 0;
int CAndroidUserItemSink::m_nSubState = 0;
int CAndroidUserItemSink::pause_count = 0;
int CAndroidUserItemSink::tacticID = 0;
int CAndroidUserItemSink::m_state=0;
CAndroidUserItemSink::CAndroidUserItemSink()
{
//接口变量
m_pIAndroidUserItem=NULL;
srand((UINT)time(NULL));
//m_bType = rand()%3;
m_nFishGold = 0;
m_cbScene = 0;
m_lCellScore = 0;
m_CannonType = 0;
m_fLastFireRote = 0.0f;
for (int i=0; i<GAME_PLAYER; i++)
{
m_RoleObjects[i].wChairID = -1;
//m_RoleObjects[i].dwFishGold = 0;
m_RoleObjects[i].wCannonType = 0;
}
m_nWeaponCost = 10;//默认是10
m_nToChangeRote = 0;
m_nLastRoteFireCount = 0;
m_fNowFireRote = M_PI_2;
m_onceUpScore = 0;
m_nNumberToFire = 0;
int currentChairID = -1;
int currentCannonID = -1;
isUpside = false;
isUpsideEx = false;
x = 0;
y = 0;
fish_num = 0;
pause_n = 300;
fishCount=0;
bulletCount=0;
cannon = new Cannon();
control = false;
GameObject::instance = this;
CTableFrameSink::m_pAndroid = this;
m_bFirstBuy=false;
RepositionState = false;
RepositionSubState = false;
allBullets.clear();
allFishes.clear();
ZeroMemory(fishPlayer, sizeof(FishPlayer));
fishGold = 0;
m_listRemoveFishMessage.clear();
//ZeroMemory(Vec2, sizeof(Vec2));
ZeroMemory(nCannonCount, sizeof(nCannonCount));
// m_listRemoveFishMessage= new std::list<ReceiveMsg*>();
buyFishGold = 0;
IsContinue = true;
}
//析构函数
CAndroidUserItemSink::~CAndroidUserItemSink()
{
LOGD("机器人的析构");
//for (auto msg : m_listRemoveFishMessage)
//{
// delete msg;
// msg = nullptr;
//}
RemoveFiMsg.clear();
allBullets.clear();
allFishes.clear();
//if (cannon)
//{
// delete cannon;
// cannon = NULL;
//}
//delete m_listRemoveFishMessage;
//t1.~thread();
}
//接口查询
void * CAndroidUserItemSink::QueryInterface(REFGUID Guid, DWORD dwQueryVer)
{
QUERYINTERFACE(IAndroidUserItemSink,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IAndroidUserItemSink,Guid,dwQueryVer);
return NULL;
}
//初始接口
bool CAndroidUserItemSink::Initialization(IUnknownEx * pIUnknownEx)
{
//查询接口
// m_pIAndroidUserItem=GET_OBJECTPTR_INTERFACE(pIUnknownEx,IAndroidUserItem);
m_pIAndroidUserItem=QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx,IAndroidUserItem);
if (m_pIAndroidUserItem==NULL) return false;
srand((UINT)time(NULL));
return true;
}
//重置接口,机器人离开的时候会调用这个接口,在这个里边关掉子线程
bool CAndroidUserItemSink::RepositionSink()
{
LOGD("机器人离开调用RespositionSink");
m_nFishGold = 0;
m_fLastFireRote = 0.0f;
RepositionState = true;
//fishPlayer[m_RobotID].lFishGold = 0;
while (1)
{
if (RepositionSubState)
{
break;
}
}
RepositionState = false;
//RemoveFiMsg.clear();
//allBullets.clear();
//allFishes.clear();
LOGD("调用RespositionSink结束");
return true;
}
//时间消息
bool CAndroidUserItemSink::OnEventTimer(UINT nTimerID)
{
switch (nTimerID)
{
case IDI_BUY_BULLET: //买子弹
{
LOGI("CAndroidUserItemSink::OnEventTimer IDI_BUY_BULLET");
BuyBullet();
return true;
}
case IDI_CHANGE_BULLET: //切换子弹
{
ChangeCannon();
return true;
}
case IDI_CHANGE_BULLET_ONCE: //切换子弹(一次)
{
ChangeCannon();
return true;
}
case IDI_FIRE: //发射子弹
{
if (allBullets.size() <= 10)
{
Fire();
//OnEventGameMessage(SUB_IDI_FIRE, 0, 0);
//LOGD("allBullet.size():"<<allBullets.size());
}
else m_pIAndroidUserItem->SetGameTimer(IDI_FIRE, rand() % TIME_FIRE + 2);
return true;
}
case IDI_LOCKTARGET:
{
cout<<"IDI_TEST"<<endl;
LockTarget();
return true;
}
case IDI_RANDOM_POINT:
{
RandomPoint();
m_pIAndroidUserItem->SetGameTimer(IDI_RANDOM_POINT, 4);
return true;
}
case IDI_LOG_SIZE:
{
m_pIAndroidUserItem->SetGameTimer(IDI_LOG_SIZE, 10);
LogSize();
}
}
return true;
}
//游戏消息
bool CAndroidUserItemSink::OnEventGameMessage(WORD wSubCmdID, void * pData, WORD wDataSize)
{
//LOGD("CAndroidUserItemSink::OnEventGameMessage wSubCmdID = " << wSubCmdID)
switch(wSubCmdID)
{
case SUB_S_BUY_BULLET_SUCCESS: //子弹购买成功消息
{
ASSERT(wDataSize == sizeof(CMD_S_Buy_Bullet_Success));
if (wDataSize!=sizeof(CMD_S_Buy_Bullet_Success)) return false;
CMD_S_Buy_Bullet_Success * pBuyBulletSuccess = (CMD_S_Buy_Bullet_Success *)pData;
if (pBuyBulletSuccess->wChairID == m_RobotID)
{
//m_nFishGold += pBuyBulletSuccess->lNowScore;
int cannonID = pBuyBulletSuccess->wChairID;
fishPlayer[cannonID].lFishGold = pBuyBulletSuccess->lCount;
//LOGD("购买子弹成功,FishGold: " << fishPlayer[cannonID].lFishGold);
//fishGold[cannonID] = pBuyBulletSuccess->lCount;
//fishPlayer[cannonID].lFishGold = pBuyBulletSuccess->lNowScore;
/// 切换子弹
if (rand()%100 < 50)
m_pIAndroidUserItem->SetGameTimer(IDI_CHANGE_BULLET, rand()%TIME_CHANGE_BULLET+TIME_LESS_CHANGE_BULLET);
else
ChangeCannon();
m_pIAndroidUserItem->SetGameTimer(IDI_FIRE, rand() % TIME_FIRE + TIME_LESS+5);
// m_pIAndroidUserItem->SetGameTimer(IDI_HALF_SECOND, 1);
// m_pIAndroidUserItem->SetGameTimer(IDI_SCHEDULE_UPDATE,1);
}
return true;
}
case SUB_S_BUY_BULLET_FAILED: //子弹购买失败消息
{
LOGD("子弹购买失败");
m_pIAndroidUserItem->SetGameTimer(IDI_FIRE, rand() % TIME_FIRE + TIME_LESS);
return true;
}
case SUB_S_CHANGE_CANNON: //子弹切换消息
{
ASSERT(wDataSize == sizeof(CMD_S_Change_Cannon));
if (wDataSize != sizeof(CMD_S_Change_Cannon)) return false;
CMD_S_Change_Cannon *pChangeCannon = (CMD_S_Change_Cannon *)pData;
ASSERT(pChangeCannon->cbStyle < MAX_CANNON_STYLE);
if (pChangeCannon->wChairID == m_RobotID)
{
pChangeCannon->cbType = 1;
if (pChangeCannon->nCost<nCannonCount[2]) {
pChangeCannon->cbType = 1;
}
else if (pChangeCannon->nCost<nCannonCount[3]) {
pChangeCannon->cbType = 2;
}
else {
pChangeCannon->cbType = 3;
}
int ID = pChangeCannon->wChairID;
//if (isUpsideEx) {
// ID = getCannonID(ID);
//}
fishPlayer[ID].wCannonType = pChangeCannon->cbStyle;
fishPlayer[ID].wCost = pChangeCannon->nCost;
fishGold = pChangeCannon->nCost;
//LOGD("ChairID:"<< ID <<" 改变炮筒:" << fishGold);
int gunNum = cannon->cannon_gunNum;
if (pChangeCannon->cbType > 0 && pChangeCannon->cbType <= 3) {
gunNum = pChangeCannon->cbType;
}
if (fishPlayer[ID].wCannonType == 0 && cannon->isSuper) {
cannon->isSuper = false;
cannon->cannon_gunNum = gunNum;
}
else {
if (gunNum != cannon->cannon_gunNum) {
cannon->setGunNum(gunNum);
}
}
//m_CannonType = pChangeCannon->cbStyle;
m_pIAndroidUserItem->SetGameTimer(IDI_FIRE, rand()%3+1);//每隔5秒创建一次子弹
return true;
}
}
case SUB_S_FIRE_LOCK_SUCCESS: //这条消息没有调用到,没有打印调试信息
{
//ASSERT(wDataSize==sizeof(CMD_S_Fire_Success_Lock));
//if (wDataSize!=sizeof(CMD_S_Fire_Success_Lock)) return false;
CMD_S_Fire_Success_Lock *pLockTarget = (CMD_S_Fire_Success_Lock *)pData;
return true;
}
case SUB_S_FIRE_SUCCESS: //子弹发射成功
{
ASSERT(wDataSize==sizeof(CMD_S_Fire_Success));
if (wDataSize!=sizeof(CMD_S_Fire_Success)) return false;
CMD_S_Fire_Success *pFireSuccess = (CMD_S_Fire_Success *)pData;
int ID = pFireSuccess->wChairID;
if (ID ==m_RobotID) //是机器人
{
//if (isUpsideEx) {
// ID = getCannonID(ID);
//}
//LOGD("子弹发射成功,m_nFishGold: " << fishPlayer[ID].lFishGold << " fishPlayer[ID].wCost: " << fishPlayer[ID].wCost);
//fishPlayer[ID].lFishGold -= fishPlayer[ID].wCost;
fishPlayer[ID].lFishGold -= fishGold;
//LOGD("子弹发射成功机器人m_nFishGold: " << fishPlayer[ID].lFishGold);
if (cannon->needFire_num<20) {
cannon->needFire_num++;
}
else {
return true;
}
}
return true;
}
case SUB_S_SEND_GET_ENERGY_GUN:
{
CMD_S_Get_Energy_Gun * S_Get_Energy_Gun = (CMD_S_Get_Energy_Gun *)pData;
if (S_Get_Energy_Gun->wChairID == m_RobotID)
{
int ID = S_Get_Energy_Gun->wChairID;
//if (isUpsideEx) {
// ID = getCannonID(ID);
// }
cannon->setSuper(true);
}
return true;
}
//case SUB_S_CAST_NET_SUCCESS:
// {
// CMD_S_Cast_Net_Success_dte * S_Cast_Net_Success_dte = (CMD_S_Cast_Net_Success_dte *)pData;
// int a = wDataSize;
// int b = sizeof(CMD_S_Cast_Net_Success_dte) - (MAX_FISH_IN_CUCESS - S_Cast_Net_Success_dte->cbCount)*sizeof(CMD_C_Fish_Net_Object);
//
// int ID = S_Cast_Net_Success_dte->wChairID;
// if (ID != m_RobotID)
// {
// return true;
// }
// //LOGD("SUB_S_CAST_NET_SUCCESS :a=" << a << " SUB_S_CAST_NET_SUCCESS :b=" << b << " count:" << S_Cast_Net_Success_dte->cbCount);
// //if (isUpsideEx) {
// // ID = getCannonID(ID);
// //}
// fishPlayer[ID].lFishGold = S_Cast_Net_Success_dte->lPlayerScore;
// bool needGoldPlate = false;
//
// for (int i = 0; i<S_Cast_Net_Success_dte->cbCount; i++) {
// mutexDestructFish.lock();
// if (!allFishes.empty())
// {
// FISHES::iterator it= allFishes.begin();
// for (; it!=allFishes.end(); it++)
// {
// if (RepositionState) return true;
// if ((*it).get()/**it)->hasFlag(fish::FLAG_UPDATE) && !(*it)->isState(fish::STATE_EXPLODE)*/) {
// if ((*it).get()->server_ID == S_Cast_Net_Success_dte->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
// (*it).get()->targetChairID = S_Cast_Net_Success_dte->wChairID;
// //(*it)->onHurt(1);
// onHurt((*it),1);
// break;
// }
// }
// }
// }
// mutexDestructFish.unlock();
// }
// return true;
//}
//case SUB_S_HIT_TEAM_SUCCESS:
// {
// const CMD_S_HitTeam_Success_dte* S_HitTeam_Success_dte = (CMD_S_HitTeam_Success_dte*)pData;
// if (wDataSize != sizeof(CMD_S_HitTeam_Success_dte) - (MAX_FISH_IN_TEAM - S_HitTeam_Success_dte->cbCount)*sizeof(CMD_C_Fish_Net_Object))
// {
// // printf("校验失败!\n");
// // return false;
// }
// int a = wDataSize;
// int b = sizeof(CMD_S_HitTeam_Success_dte) - (MAX_FISH_IN_TEAM - S_HitTeam_Success_dte->cbCount)*sizeof(CMD_C_Fish_Net_Object);
// int ID = S_HitTeam_Success_dte->wChairID;
// if (ID != m_RobotID)
// {
// return true;
// }
// //LOGD("SUB_S_HIT_TEAM_SUCCESS :a=" << a << " SUB_S_HIT_TEAM_SUCCESS :b=" << b << " count=" << S_HitTeam_Success_dte->cbCount);
// //if (isUpsideEx) {
// // ID = getCannonID(ID);
// //}
// fishPlayer[ID].lFishGold += S_HitTeam_Success_dte->lPlayerAddScore;
// for (int i = 0; i<S_HitTeam_Success_dte->cbCount; i++) {
// mutexDestructFish.lock();
// if (!allFishes.empty())
// {
// if (RepositionState) return true;
// FISHES::iterator it = allFishes.begin();
// for (; it != allFishes.end(); it++)
// {
// if ((*it).get()/*(*it)->hasFlag(fish::FLAG_UPDATE) && !(*it)->isState(fish::STATE_EXPLODE)*/) {
// if ((*it).get()->server_ID == S_HitTeam_Success_dte->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
// (*it).get()->targetChairID = S_HitTeam_Success_dte->wChairID;
// //(*it)->onHurt(1);
// onHurt((*it),1);
// break;
// }
// }
// }
// }
// mutexDestructFish.unlock();
// }
// return true;
// }
//case SUB_S_TYPE_BOMB_SUCCESS:
// {
// const CMD_S_TypeBomb_Success_dte* S_TypeBomb_Success_dte = (CMD_S_TypeBomb_Success_dte*)pData;
// if (wDataSize != sizeof(CMD_S_TypeBomb_Success_dte) - (MAX_FISH_BY_BOMB - S_TypeBomb_Success_dte->cbCount)*sizeof(CMD_C_Fish_Net_Object))
// {
// // printf("校验失败!\n");
// // return false;
// }
// int a = wDataSize;
// int b = sizeof(CMD_S_TypeBomb_Success_dte) - (MAX_FISH_BY_BOMB - S_TypeBomb_Success_dte->cbCount)*sizeof(CMD_C_Fish_Net_Object);
// int ID = S_TypeBomb_Success_dte->wChairID;
// if (ID != m_RobotID) return true;
// //LOGD("SUB_S_TYPE_BOMB_SUCCESS :a=" << a << " SUB_S_TYPE_BOMB_SUCCESS :b=" << b << " count=" << S_TypeBomb_Success_dte->cbCount);
// //if (isUpsideEx) {
// // ID = getCannonID(ID);
// //}
// fishPlayer[ID].lFishGold += S_TypeBomb_Success_dte->lPlayerAddScore;
// for (int i = 0; i<S_TypeBomb_Success_dte->cbCount; i++)
// {
// mutexDestructFish.lock();
// if (!allFishes.empty())
// {
// if (RepositionState) return true;
// FISHES::iterator it = allFishes.begin();
// for (; it != allFishes.end(); it++)
// {
// if ((*it).get()/*(*it)->hasFlag(fish::FLAG_UPDATE) && !(*it)->isState(fish::STATE_EXPLODE)*/) {
// if ((*it).get()->server_ID == S_TypeBomb_Success_dte->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
// (*it).get()->targetChairID = S_TypeBomb_Success_dte->wChairID;
// //(*it)->onHurt(1)
// onHurt((*it),1);
// break;
// }
// }
// }
// mutexDestructFish.unlock();
// }
// }
// return true;
// }
//case SUB_IDI_FIRE:
//{
// LOGD("SUB_IDI_FIRE");
// std::shared_ptr<ReceiveMsg> pReceiveData = std::shared_ptr<ReceiveMsg>(new /*(std::nothrow)*/ ReceiveMsg());
// pReceiveData->wSubCmdID = wSubCmdID;
// pReceiveData->wDataSize = wDataSize;
// memcpy(pReceiveData->cbDataBuffer, pData, wDataSize);
// bool bRet = getMessage(pReceiveData);
// return true;
//}
case SUB_S_CAST_NET_SUCCESS://撒网成功
case SUB_S_HIT_TEAM_SUCCESS://击中小组
case SUB_S_TYPE_BOMB_SUCCESS://同类炸弹成功
case SUB_S_CHANGE_SCENE://改变场景
{
std::shared_ptr<ReceiveMsg> pReceiveData = std::shared_ptr<ReceiveMsg>(new /*(std::nothrow)*/ ReceiveMsg());
//ReceiveMsg* pReceiveData = new (std::nothrow) ReceiveMsg();
pReceiveData->wSubCmdID = wSubCmdID;
pReceiveData->wDataSize = wDataSize;
memcpy(pReceiveData->cbDataBuffer, pData, wDataSize);
bool bRet = getMessage(pReceiveData);
return true;
}
case SUB_S_SEND_FISH_PATH:
{
CMD_S_Fish_Path * S_Fish_Path = (CMD_S_Fish_Path *)pData;
fishCount=0; //每次收到服务器创建鱼的消息,重置一下fishCount
Tools::srand(S_Fish_Path->cbSeed);
debug_("FISH_PATH:%d,%d,%d,%d,%d", S_Fish_Path->cbType, S_Fish_Path->cbCount, S_Fish_Path->wGroupID, S_Fish_Path->FishNetObject[0].wID, S_Fish_Path->FishNetObject[0].cbType);
int num = S_Fish_Path->cbCount;//鱼的数量
// int runMode = fish::RUN_MODE_LINE + Tools::rand() % 2;
int runMode = Fishes::RUN_MODE_LINE + Tools::rand() % 2;
debug_("S_Fish_Path->cbSeed:%d, Tools::rand()%2: %d", Tools::rand() % 2);
if (S_Fish_Path->cbType == FISH_PATH_LINE) {
for (int i = 0; i < num; i++) {
if (S_Fish_Path->FishNetObject[i].cbType>15) {
// runMode = fish::RUN_MODE_LINE;
runMode = Fishes::RUN_MODE_LINE;
}
int start_x = -300;
int start_y = -300;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
start_y = -start_y + winSize.height;
}
start_x += Tools::rand() % (int)(winSize.width + 600);
}
else {
if (Tools::rand() % 2 == 0) {
start_x = -start_x + winSize.width;
}
start_y += Tools::rand() % (int)(winSize.height + 600);
}
int pass_x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
int pass_y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
Vec2 curvePos[3];
if (/*runMode == fish::RUN_MODE_CURVE*/runMode == Fishes::RUN_MODE_CURVE) {
for (int i = 0; i < 2; i++) {
curvePos[i].x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
curvePos[i].y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
}
curvePos[2].x = -300;
curvePos[2].y = -300;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
curvePos[2].y = -curvePos[2].y + winSize.height;
}
curvePos[2].x += Tools::rand() % (int)(winSize.width + 600);
}
else {
if (Tools::rand() % 2 == 0) {
curvePos[2].x = -curvePos[2].x + winSize.width;
}
curvePos[2].y += Tools::rand() % (int)(winSize.height + 600);
}
}
int angle = Tools::getAngle(pass_x - start_x, pass_y - start_y);
if (isUpside) {
angle += 180;
angle %= 360;
start_x = winSize.width - start_x;
start_y = winSize.height - start_y;
if (/*runMode == fish::RUN_MODE_CURVE*/runMode == Fishes::RUN_MODE_CURVE) {
for (int i = 0; i < 3; i++) {
curvePos[i].x = winSize.width - curvePos[i].x;
curvePos[i].y = winSize.height - curvePos[i].y;
}
}
}
if (S_Fish_Path->FishNetObject[i].cbType <= 20) {
// fish* fish = fish::createFish(start_x, start_y, angle, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
// Fishes* fish = Fishes::createFish(start_x, start_y, angle, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
Fishes* fish = createFish(start_x, start_y, angle, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
if (/*runMode == fish::RUN_MODE_CURVE*/runMode == Fishes::RUN_MODE_CURVE) {
fish->setRunCurve(curvePos);
}
}
}
}
else if (S_Fish_Path->cbType == FISH_PATH_SP_HAS_ID) {
for (int i = 0; i < num; i++) {
int start_x = -300;
int start_y = -300;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
start_y = -start_y + winSize.height;
}
start_x += Tools::rand() % (int)(winSize.width + 600);
}
else {
if (Tools::rand() % 2 == 0) {
start_x = -start_x + winSize.width;
}
start_y += Tools::rand() % (int)(winSize.height + 600);
}
int pass_x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
int pass_y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
int angle = Tools::getAngle(pass_x - start_x, pass_y - start_y);
if (isUpside) {
angle += 180;
angle %= 360;
start_x = winSize.width - start_x;
start_y = winSize.height - start_y;
}
if (S_Fish_Path->FishNetObject[i].cbType == 21 || S_Fish_Path->FishNetObject[i].cbType == 22) {
//fish::createFish(start_x, start_y, angle, fish::TYPE_NIL, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
//Fishes::createFish(start_x, start_y, angle, Fishes::TYPE_NIL, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
createFish(start_x, start_y, angle, Fishes::TYPE_NIL, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
}
else if (S_Fish_Path->FishNetObject[i].cbType == 23) {
// fish::createFish(start_x, start_y, angle, fish::STYLE_PAUSE, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
// Fishes::createFish(start_x, start_y, angle, Fishes::STYLE_PAUSE, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
createFish(start_x, start_y, angle, Fishes::STYLE_PAUSE, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
}
else {
}
}
}
else if (S_Fish_Path->cbType == FISH_PATH_SP_TEAM) {
int start_x = -300;
int start_y = -300;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
start_y = -start_y + winSize.height;
}
start_x += Tools::rand() % (int)(winSize.width + 600);
}
else {
if (Tools::rand() % 2 == 0) {
start_x = -start_x + winSize.width;
}
start_y += Tools::rand() % (int)(winSize.height + 600);
}
int pass_x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
int pass_y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
int angle = Tools::getAngle(pass_x - start_x, pass_y - start_y);
int w = 70;
for (int i = 0; i < num; i++) {
if (S_Fish_Path->FishNetObject[i].cbType >8) {
w = 150;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 7) {
w = 140;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 4) {
w = 130;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 3) {
w = 100;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 2) {
w = 90;
}
int appear_x = start_x + Tools::getAngleX((angle + 180) % 360, w*i);
int appear_y = start_y + Tools::getAngleY((angle + 180) % 360, w*i);
int angle2 = angle;
if (isUpside) {
angle2 += 180;
angle2 %= 360;
appear_x = winSize.width - appear_x;
appear_y = winSize.height - appear_y;
}
// fish::createFish(appear_x, appear_y, angle2, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
// Fishes::createFish(appear_x, appear_y, angle2, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
createFish(appear_x, appear_y, angle2, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
}
}
else if (S_Fish_Path->cbType == FISH_PATH_SP_SPTTEAM) {
if (num > 4) {
int start_x = -300;
int start_y = -300;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
start_y = -start_y + winSize.height;
}
start_x += Tools::rand() % (int)(winSize.width + 600);
}
else {
if (Tools::rand() % 2 == 0) {
start_x = -start_x + winSize.width;
}
start_y += Tools::rand() % (int)(winSize.height + 600);
}
int pass_x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
int pass_y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
int angle = Tools::getAngle(pass_x - start_x, pass_y - start_y);
int w = 70;
for (int i = 0; i < num; i++) {
if (S_Fish_Path->FishNetObject[i].cbType >8) {
w = 150;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 7) {
w = 140;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 4) {
w = 130;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 3) {
w = 100;
}
else if (S_Fish_Path->FishNetObject[i].cbType > 2) {
w = 90;
}
int appear_x = start_x + Tools::getAngleX((angle + 180) % 360, w*i);
int appear_y = start_y + Tools::getAngleY((angle + 180) % 360, w*i);
int angle2 = angle;
if (isUpside) {
angle2 += 180;
angle2 %= 360;
appear_x = winSize.width - appear_x;
appear_y = winSize.height - appear_y;
}
// fish::createFish(appear_x, appear_y, angle2, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
// Fishes::createFish(appear_x, appear_y, angle2, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
createFish(appear_x, appear_y, angle2, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
}
}
else {
int start_x = -500;
int start_y = -500;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
start_y = -start_y + winSize.height;
}
start_x += Tools::rand() % (int)(winSize.width + 1000);
}
else {
if (Tools::rand() % 2 == 0) {
start_x = -start_x + winSize.width;
}
start_y += Tools::rand() % (int)(winSize.height + 1000);
}
int pass_x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
int pass_y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
int angle = Tools::getAngle(pass_x - start_x, pass_y - start_y);
int mark_ID = S_Fish_Path->FishNetObject[0].wID;
if (num == 3) {
for (int i = 0; i < 3; i++) {
int appear_x = start_x + Tools::getAngleX((angle + 180) % 360, 80 * i);
int appear_y = start_y + Tools::getAngleY((angle + 180) % 360, 80 * i);
int angle2 = angle;
if (isUpside) {
angle2 += 180;
angle2 %= 360;
appear_x = winSize.width - appear_x;
appear_y = winSize.height - appear_y;
}
// fish* fish = fish::createFish(appear_x, appear_y, angle2, fish::STYLE_TEAM, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
// fish->mark_ID = mark_ID;
// Fishes* fish = Fishes::createFish(appear_x, appear_y, angle2, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
Fishes* fish = createFish(appear_x, appear_y, angle2, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
fish->mark_ID = mark_ID;
}
}
else {
if (isUpside) {
angle += 180;
angle %= 360;
start_x = winSize.width - start_x;
start_y = winSize.height - start_y;
}
// fish* fish = fish::createFish(start_x, start_y, angle, fish::STYLE_TEAM, S_Fish_Path->FishNetObject[0].cbType, S_Fish_Path->FishNetObject[0].wID);
// fish->mark_ID = mark_ID;
// fish = fish::createFish(start_x - 40, start_y - 75, angle, fish::STYLE_TEAM, S_Fish_Path->FishNetObject[1].cbType, S_Fish_Path->FishNetObject[1].wID);
// fish->mark_ID = mark_ID;
// fish = fish::createFish(start_x + 40, start_y - 75, angle, fish::STYLE_TEAM, S_Fish_Path->FishNetObject[2].cbType, S_Fish_Path->FishNetObject[2].wID);
// fish->mark_ID = mark_ID;
// fish = fish::createFish(start_x, start_y - 150, angle, fish::STYLE_TEAM, S_Fish_Path->FishNetObject[3].cbType, S_Fish_Path->FishNetObject[3].wID);
// fish->mark_ID = mark_ID;
//Fishes* fish = Fishes::createFish(start_x, start_y, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[0].cbType, S_Fish_Path->FishNetObject[0].wID);
Fishes* fish = createFish(start_x, start_y, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[0].cbType, S_Fish_Path->FishNetObject[0].wID);
fish->mark_ID = mark_ID;
//fish = Fishes::createFish(start_x - 40, start_y - 75, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[1].cbType, S_Fish_Path->FishNetObject[1].wID);
fish = createFish(start_x - 40, start_y - 75, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[1].cbType, S_Fish_Path->FishNetObject[1].wID);
fish->mark_ID = mark_ID;
//fish = Fishes::createFish(start_x + 40, start_y - 75, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[2].cbType, S_Fish_Path->FishNetObject[2].wID);
fish = createFish(start_x + 40, start_y - 75, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[2].cbType, S_Fish_Path->FishNetObject[2].wID);
fish->mark_ID = mark_ID;
//fish = Fishes::createFish(start_x, start_y - 150, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[3].cbType, S_Fish_Path->FishNetObject[3].wID);
fish = createFish(start_x, start_y - 150, angle, Fishes::STYLE_TEAM, S_Fish_Path->FishNetObject[3].cbType, S_Fish_Path->FishNetObject[3].wID);
fish->mark_ID = mark_ID;
}
}
}
else if (S_Fish_Path->cbType == FISH_PATH_SP_TYPE_BOMB) {
for (int i = 0; i < num; i++) {
int start_x = -300;
int start_y = -300;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
start_y = -start_y + winSize.height;
}
start_x += Tools::rand() % (int)(winSize.width + 600);
}
else {
if (Tools::rand() % 2 == 0) {
start_x = -start_x + winSize.width;
}
start_y += Tools::rand() % (int)(winSize.height + 600);
}
int pass_x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
int pass_y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
int angle = Tools::getAngle(pass_x - start_x, pass_y - start_y);
if (isUpside) {
angle += 180;
angle %= 360;
start_x = winSize.width - start_x;
start_y = winSize.height - start_y;
}
if (S_Fish_Path->FishNetObject[i].cbType <= 22) {
// fish::createFish(start_x, start_y, angle, fish::STYLE_SAME, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
// Fishes::createFish(start_x, start_y, angle, Fishes::STYLE_SAME, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID
createFish(start_x, start_y, angle, Fishes::STYLE_SAME, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
}
}
}
else if (S_Fish_Path->cbType == FISH_PATH_WATER_PLANT) {
for (int i = 0; i < num; i++) {
int start_x = -300;
int start_y = -300;
if (Tools::rand() % (int)(winSize.width + winSize.height) < winSize.width) {
if (Tools::rand() % 2 == 0) {
start_y = -start_y + winSize.height;
}
start_x += Tools::rand() % (int)(winSize.width + 600);
}
else {
if (Tools::rand() % 2 == 0) {
start_x = -start_x + winSize.width;
}
start_y += Tools::rand() % (int)(winSize.height + 600);
}
int pass_x = winSize.width / 8 + Tools::rand() % (int)(winSize.width * 6 / 8);
int pass_y = winSize.height / 8 + Tools::rand() % (int)(winSize.height * 6 / 8);
int angle = Tools::getAngle(pass_x - start_x, pass_y - start_y);
if (isUpside) {
angle += 180;
angle %= 360;
start_x = winSize.width - start_x;
start_y = winSize.height - start_y;
}
if (S_Fish_Path->FishNetObject[i].cbType <= 22) {
//fish::createFish(start_x, start_y, angle, fish::STYLE_ANY, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
// Fishes::createFish(start_x, start_y, angle, Fishes::STYLE_ANY, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
createFish(start_x, start_y, angle, Fishes::STYLE_ANY, S_Fish_Path->FishNetObject[i].cbType, S_Fish_Path->FishNetObject[i].wID);
}
}
}
setState(STATE_NORMAL);
return true;
}
case SUB_S_SEND_FISH_PATH_GROUP://阵形
{
CMD_S_Fish_Group * S_Fish_Group = (CMD_S_Fish_Group *)pData;
//CCLOG("CMD_S_Fish_Group:%f,%d", S_Fish_Group->fPassTime, S_Fish_Group->cbType);
Tools::srand(S_Fish_Group->cbSeed);
tacticID = S_Fish_Group->cbType - 1;
if (tacticID != 0)
tacticID %= 11;
//tacticID = 3;
//Fish::resetTacticID();
if (tacticID == 0) {
for (int i = 0; i < 100; i++) {
// fish* fish = fish::createFish(Tools::rand() % ((int)winSize.width), winSize.height + 100, 270, 1, i);
// Fishes* fish = Fishes::createFish(Tools::rand() % ((int)winSize.width), winSize.height + 100, 270, 1, i);
Fishes* fish = createFish(Tools::rand() % ((int)winSize.width), winSize.height + 100, 270, 1, i);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 2 + i*0.2f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 10;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(Tools::rand() % ((int)winSize.width), -100, 90, 2, 100 + i);
// fish = Fishes::createFish(Tools::rand() % ((int)winSize.width), -100, 90, 2, 100 + i);
fish = createFish(Tools::rand() % ((int)winSize.width), -100, 90, 2, 100 + i);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 2 + i*0.2f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 10;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
int fish_buffer[80][2];
for (int i = 0; i < 80; i++) {
fish_buffer[i][0] = 200 + i;
fish_buffer[i][1] = 14 + i / 20;
}
int buffer_ID, buffer_type;
int choose_1, choose_2;
for (int i = 0; i < 100; i++) {
choose_1 = Tools::rand() % 80;
choose_2 = Tools::rand() % 80;
while (choose_2 == choose_1) {
choose_2 = Tools::rand() % 80;
}
buffer_ID = fish_buffer[choose_1][0];
buffer_type = fish_buffer[choose_1][1];
fish_buffer[choose_1][0] = fish_buffer[choose_2][0];
fish_buffer[choose_1][1] = fish_buffer[choose_2][1];
fish_buffer[choose_2][0] = buffer_ID;
fish_buffer[choose_2][1] = buffer_type;
}
for (int i = 0; i < 27; i++) {
for (int k = 0; k < 3; k++) {
if (!(i == 26 && k == 2)) {
// fish* fish = fish::createFish(winSize.width + 350, winSize.height / 2, 160 + k * 20 + Tools::rand() % 11 - 5, fish_buffer[i * 3 + k][1], fish_buffer[i * 3 + k][0]);
// Fishes* fish = Fishes::createFish(winSize.width + 350, winSize.height / 2, 160 + k * 20 + Tools::rand() % 11 - 5, fish_buffer[i * 3 + k][1], fish_buffer[i * 3 + k][0]);
Fishes* fish = createFish(winSize.width + 350, winSize.height / 2, 160 + k * 20 + Tools::rand() % 11 - 5, fish_buffer[i * 3 + k][1], fish_buffer[i * 3 + k][0]);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = i*0.75f + Tools::rand() % 10 / 10.0f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
}
}
else if (tacticID == 1) {
int w = winSize.width;
int h = winSize.height;
int half_w = winSize.width / 2;
int half_h = winSize.height / 2;
float angle[4];
angle[0] = Tools::getAngle(winSize.width / 2, winSize.height / 2);
angle[1] = fmod(angle[0] + 180, 360);
angle[2] = 180 - angle[0];
angle[3] = fmod(angle[2] + 180, 360);
float distance = sqrt(half_w*half_w + half_h*half_h)*1.5f;
float x[8], y[8];
x[0] = w + Tools::getAngleX(angle[1], distance);
y[0] = half_h + Tools::getAngleY(angle[1], distance);
x[1] = half_w + Tools::getAngleX(angle[1], distance);
y[1] = h + Tools::getAngleY(angle[1], distance);
x[2] = half_w + Tools::getAngleX(angle[0], distance);
y[2] = 0 + Tools::getAngleY(angle[0], distance);
x[3] = 0 + Tools::getAngleX(angle[0], distance);
y[3] = half_h + Tools::getAngleY(angle[0], distance);
x[4] = 0 + Tools::getAngleX(angle[3], distance);
y[4] = half_h + Tools::getAngleY(angle[3], distance);
x[5] = half_w + Tools::getAngleX(angle[3], distance);
y[5] = h + Tools::getAngleY(angle[3], distance);
x[6] = half_w + Tools::getAngleX(angle[2], distance);
y[6] = 0 + Tools::getAngleY(angle[2], distance);
x[7] = w + Tools::getAngleX(angle[2], distance);
y[7] = half_h + Tools::getAngleY(angle[2], distance);
int type[4] = { 20, 18, 19, 17 };
int ID_offset[4] = { 30, 10, 20, 0 };
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 2; k++) {
// fish* fish = fish::createFish(x[j * 2 + k], y[j * 2 + k], angle[j], type[j], ID_offset[j] + i * 2 + k);
// Fishes* fish = Fishes::createFish(x[j * 2 + k], y[j * 2 + k], angle[j], type[j], ID_offset[j] + i * 2 + k);
Fishes* fish = createFish(x[j * 2 + k], y[j * 2 + k], angle[j], type[j], ID_offset[j] + i * 2 + k);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = i*5.0f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 15;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(120, angle[j]);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
}
}
else if (tacticID == 2) {
float buffer_time = 20;
for (int i = 0; i < 120; i++)
{
buffer_time = 20;
//fish* fish = fish::createFish(Tools::rand() % ((int)winSize.width), winSize.height + 100, 270, 1, i);
//Fishes* fish = Fishes::createFish(Tools::rand() % ((int)winSize.width), winSize.height + 100, 270, 1, i);
Fishes* fish = createFish(Tools::rand() % ((int)winSize.width), winSize.height + 100, 270, 1, i);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = Tools::rand() % 100 / 10.0f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 1 + Tools::rand() % 20 / 10.0f;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_WAIT;
fish->fishAction[2].time = buffer_time;
fish->fishAction[3].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[3].time = 2 + Tools::rand() % 40 / 10.0f;
fish->fishAction[4].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
buffer_time = 20;
// fish = fish::createFish(Tools::rand() % ((int)winSize.width), -100, 90, 2, 120 + i);
// fish = Fishes::createFish(Tools::rand() % ((int)winSize.width), -100, 90, 2, 120 + i);
fish = createFish(Tools::rand() % ((int)winSize.width), -100, 90, 2, 120 + i);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = Tools::rand() % 100 / 10.0f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 1 + Tools::rand() % 20 / 10.0f;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_WAIT;
fish->fishAction[2].time = buffer_time;
fish->fishAction[3].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[3].time = 2 + Tools::rand() % 40 / 10.0f;
fish->fishAction[4].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
for (int i = 0; i < 3; i++) {
// fish* fish = fish::createFish(-150, winSize.height * 7 / 20, 0, 17, 240 + i * 2);
// Fishes* fish = Fishes::createFish(-150, winSize.height * 7 / 20, 0, 17, 240 + i * 2);
Fishes* fish = createFish(-150, winSize.height * 7 / 20, 0, 17, 240 + i * 2);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(-162, winSize.height * 7 / 20, 0, 18, 250 + i * 2);
// fish = Fishes::createFish(-162, winSize.height * 7 / 20, 0, 18, 250 + i * 2);
fish = createFish(-162, winSize.height * 7 / 20, 0, 18, 250 + i * 2);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 2.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(-285, winSize.height * 7 / 20, 0, 19, 260 + i * 2);
// fish = Fishes::createFish(-285, winSize.height * 7 / 20, 0, 19, 260 + i * 2);
fish = createFish(-285, winSize.height * 7 / 20, 0, 19, 260 + i * 2);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 4.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(-350, winSize.height * 7 / 20, 0, 20, 270 + i * 2);
// fish = Fishes::createFish(-350, winSize.height * 7 / 20, 0, 20, 270 + i * 2);
fish = createFish(-350, winSize.height * 7 / 20, 0, 20, 270 + i * 2);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 5.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
///////////////////////////////////////////////////
// fish = fish::createFish(winSize.width + 150, winSize.height * 13 / 20, 180, 17, 240 + i * 2 + 1);
// fish = Fishes::createFish(winSize.width + 150, winSize.height * 13 / 20, 180, 17, 240 + i * 2 + 1);
fish = createFish(winSize.width + 150, winSize.height * 13 / 20, 180, 17, 240 + i * 2 + 1);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(winSize.width + 162, winSize.height * 13 / 20, 180, 18, 250 + i * 2 + 1);
// fish = Fishes::createFish(winSize.width + 162, winSize.height * 13 / 20, 180, 18, 250 + i * 2 + 1);
fish = createFish(winSize.width + 162, winSize.height * 13 / 20, 180, 18, 250 + i * 2 + 1);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 2.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(winSize.width + 285, winSize.height * 13 / 20, 180, 19, 260 + i * 2 + 1);
// fish = Fishes::createFish(winSize.width + 285, winSize.height * 13 / 20, 180, 19, 260 + i * 2 + 1);
fish = createFish(winSize.width + 285, winSize.height * 13 / 20, 180, 19, 260 + i * 2 + 1);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 4.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(winSize.width + 350, winSize.height * 13 / 20, 180, 20, 270 + i * 2 + 1);
// fish = Fishes::createFish(winSize.width + 350, winSize.height * 13 / 20, 180, 20, 270 + i * 2 + 1);
fish = createFish(winSize.width + 350, winSize.height * 13 / 20, 180, 20, 270 + i * 2 + 1);
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 5.5f + i*8.5f;
buffer_time -= fish->fishAction[0].time;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
buffer_time -= fish->fishAction[1].time;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
else if (tacticID == 3) {
int buffer_ID = 900;
int n = Tools::rand() % 4;
for (int i = 0; i < 4; i++) {
int m = 2;
if (n == i) {
m = 1;
}
for (int j = 0; j < m; j++) {
// fish* fish = fish::createFish(winSize.width / 2, winSize.height / 2, 30 + Tools::rand() % 6 * 60 + Tools::rand() % 31 - 15, 4, buffer_ID++);
// Fishes* fish = Fishes::createFish(winSize.width / 2, winSize.height / 2, 30 + Tools::rand() % 6 * 60 + Tools::rand() % 31 - 15, 4, buffer_ID++);
Fishes* fish = createFish(winSize.width / 2, winSize.height / 2, 30 + Tools::rand() % 6 * 60 + Tools::rand() % 31 - 15, 4, buffer_ID++);
fish->fishAction[0].actionID = Fishes::ACTION_HIDE;
fish->fishAction[0].time = 0.2f*i;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 7;
fish->fishAction[4].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish->setVisible(false);
// fish->shadow->setVisible(false);
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 30; j++) {
for (int k = 0; k < 6; k++) {
// fish* fish = fish::createFish(winSize.width / 2, winSize.height / 2, 30 + k * 60 + Tools::rand() % 31 - 15, 1 + i, i * 300 + j * 6 + k);
// Fishes* fish = Fishes::createFish(winSize.width / 2, winSize.height / 2, 30 + k * 60 + Tools::rand() % 31 - 15, 1 + i, i * 300 + j * 6 + k);
Fishes* fish = createFish(winSize.width / 2, winSize.height / 2, 30 + k * 60 + Tools::rand() % 31 - 15, 1 + i, i * 300 + j * 6 + k);
fish->fishAction[0].actionID = Fishes::ACTION_HIDE;
fish->fishAction[0].time = j*0.1f + i * 4 + 2.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 7;
fish->fishAction[4].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
//fish->setVisible(false);
//fish->shadow->setVisible(false);
}
}
}
}
else if (tacticID == 4) {
int x1 = winSize.width / 4;
int x2 = winSize.width * 3 / 4;
int x = 0;
int y = winSize.height / 2;
int n = 32;
float angle = 0;
float r = x1*0.95f;
float moveAngle = 0;
float r2 = r;
int type = 0;
int buffer_ID[7] = { 0, 40, 80, 110, 130, 160, 190 };
int index[7] = { 0, 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < 8; i++) {
if (i % 2 == 0) {
x = x1;
}
else {
x = x2;
}
if (i == 3) {
type = 5;
}
else if (i == 4) {
type = 4;
}
else if (i < 6) {
type = i + 1;
}
else {
type = i;
}
if (i % 2 == 0) {
n -= 5;
}
angle = 360.0f / n;
r2 = r*(1 - 0.125f*(i / 2));
for (int j = 0; j < n; j++) {
// fish* fish = fish::createFish(x + Tools::getAngleX(j*angle, r2), y + Tools::getAngleY(j*angle, r2), moveAngle = fmod(j*angle + 90, 360), type, buffer_ID[type - 1] + (index[type - 1]++));
// Fishes* fish = Fishes::createFish(x + Tools::getAngleX(j*angle, r2), y + Tools::getAngleY(j*angle, r2), moveAngle = fmod(j*angle + 90, 360), type, buffer_ID[type - 1] + (index[type - 1]++));
Fishes* fish = createFish(x + Tools::getAngleX(j*angle, r2), y + Tools::getAngleY(j*angle, r2), moveAngle = fmod(j*angle + 90, 360), type, buffer_ID[type - 1] + (index[type - 1]++));
fish->fishAction[0].actionID = Fishes::ACTION_RUN_ROUND;
fish->fishAction[0].time = 15 + i*0.8f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 10;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
}
fish->buffer_x = x;
fish->buffer_y = y;
fish->buffer_angle = j*angle;
fish->buffer_r = r2;
fish->angle_v = 40;
}
}
// fish* fish = fish::createFish(x1, y, 90, 20, 203);
// Fishes* fish = Fishes::createFish(x1, y, 90, 20, 203);
Fishes* fish = createFish(x1, y, 90, 20, 203);
fish->fishAction[0].actionID = Fishes::ACTION_ROTATE;
fish->fishAction[0].time = 15 + 7.2f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 12;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
fish->angle_v = 40;
// fish = Fishes::createFish(x2, y, 270, 19, 202);
fish = createFish(x2, y, 270, 19, 202);
fish->fishAction[0].actionID = Fishes::ACTION_ROTATE;
fish->fishAction[0].time = 15 + 7.2f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 10;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
fish->angle_v = 40;
}
else if (tacticID == 5) {
bool isLeft = Tools::rand() % 2;
float C = 1.41421f;
int n = 80;
float angle = 0;
float moveAngle = isLeft ? 0 : 180;
float r = (winSize.height - 50) / 2;
float r2 = r;
float w = r*C / 4;
int center_x = isLeft ? -winSize.height / 2 : winSize.width + winSize.height / 2;
int center_y = winSize.height / 2;
int center_x2 = center_x;
int center_y2 = center_y;
int buffer_ID[6] = { 0, 120, 150, 180, 210, 240 };
int index[6] = { 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < 6; i++) {
if (i == 0) {
n = 80;
angle = 360.0f / n;
}
else {
n = 16;
angle = 360.0f / n;
if (i == 5) {
center_x2 = center_x;
center_y2 = center_y;
r2 = r / 2 * 0.6f;
}
else {
center_x2 = center_x + ((i - 1) / 2 == 0 ? w : -w);
center_y2 = center_y + (i / 2 % 2 == 0 ? -w : w);
r2 = r / 2 * 0.6f;
}
}
for (int j = 0; j < n; j++) {
// fish* fish = fish::createFish(center_x2 + Tools::getAngleX(j*angle, r2), center_y2 + Tools::getAngleY(j*angle, r2), moveAngle, i + 1, buffer_ID[i] + (index[i]++));
// Fishes* fish = Fishes::createFish(center_x2 + Tools::getAngleX(j*angle, r2), center_y2 + Tools::getAngleY(j*angle, r2), moveAngle, i + 1, buffer_ID[i] + (index[i]++));
Fishes* fish = createFish(center_x2 + Tools::getAngleX(j*angle, r2), center_y2 + Tools::getAngleY(j*angle, r2), moveAngle, i + 1, buffer_ID[i] + (index[i]++));
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 20;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
}
else if (tacticID == 6) {
int buffer_ID[3] = { 0, 140, 226 };
int index[3] = { 0, 0, 0 };
float C = 1.41421f;
for (int k = 0; k < 2; k++) {
bool isLeft = k == 0;
int n = 70;
float angle = 0;
float moveAngle = isLeft ? 0 : 180;
float r = (winSize.height - 50) / 2;
float r2 = r;
int center_x = isLeft ? -winSize.height / 2 : winSize.width + winSize.height / 2;
int center_y = winSize.height / 2;
int type = 1;
for (int i = 0; i < 3; i++) {
n = 70 - i * 27;
angle = 360.0f / n;
if (i == 2) {
type = 6;
}
else {
type = i + 1;
}
r2 = r*(1 - 0.25f*i);
for (int j = 0; j < n; j++) {
// fish* fish = fish::createFish(center_x + Tools::getAngleX(j*angle, r2), center_y + Tools::getAngleY(j*angle, r2), moveAngle, type, buffer_ID[i] + (index[i]++));
// Fishes* fish = Fishes::createFish(center_x + Tools::getAngleX(j*angle, r2), center_y + Tools::getAngleY(j*angle, r2), moveAngle, type, buffer_ID[i] + (index[i]++));
Fishes* fish = createFish(center_x + Tools::getAngleX(j*angle, r2), center_y + Tools::getAngleY(j*angle, r2), moveAngle, type, buffer_ID[i] + (index[i]++));
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 25;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
// fish* fish = fish::createFish(center_x, center_y, moveAngle, 20, 258 + k);
// Fishes* fish = Fishes::createFish(center_x, center_y, moveAngle, 20, 258 + k);
Fishes* fish =createFish(center_x, center_y, moveAngle, 20, 258 + k);
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 20;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
else if (tacticID == 7) {
int buffer_ID[3] = { 0, 100, 160 };
int index[3] = { 0, 0, 0 };
bool isLeft = Tools::rand() % 2;
float C = 1.41421f;
int n = 50;
float angle = 0;
float moveAngle = isLeft ? 0 : 180;
float r = (winSize.height - 100) / 2;
float r2 = r;
int center_x = isLeft ? -winSize.height : winSize.width + winSize.height;
int center_y = winSize.height / 2;
int center_x2 = center_x;
int center_y2 = center_y;
int type = 1;
int ii = 0;
for (int i = 0; i < 5; i++) {
if (i < 4) {
n = 50 - 20 * (i % 2);
r2 = r*(1 - 0.25f*(i % 2));
if (i < 2) {
center_x2 = center_x + r*0.8f;
}
else {
center_x2 = center_x - r*0.8f;
}
type = i % 2 + 1;
ii = i % 2;
}
else {
n = 40;
r2 = r;
center_x2 = center_x;
center_y2 = center_y;
type = 6;
ii = 2;
}
angle = 360.0f / n;
for (int j = 0; j < n; j++) {
// fish* fish = fish::createFish(center_x2 + Tools::getAngleX(j*angle, r2), center_y2 + Tools::getAngleY(j*angle, r2), moveAngle, type, buffer_ID[ii] + (index[ii]++));
// Fishes* fish = Fishes::createFish(center_x2 + Tools::getAngleX(j*angle, r2), center_y2 + Tools::getAngleY(j*angle, r2), moveAngle, type, buffer_ID[ii] + (index[ii]++));
Fishes* fish = createFish(center_x2 + Tools::getAngleX(j*angle, r2), center_y2 + Tools::getAngleY(j*angle, r2), moveAngle, type, buffer_ID[ii] + (index[ii]++));
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 28;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
int w = r / 2;
int h = r / 4;
for (int i = 0; i < 4; i++) {
// fish* fish = fish::createFish(center_x + (((isLeft && i < 2) || (!isLeft && i >= 2)) ? w : -w), center_y + ((i + 1) / 2 % 2 == 0 ? h : -h), moveAngle, 20, 200 + i);
// Fishes* fish = Fishes::createFish(center_x + (((isLeft && i < 2) || (!isLeft && i >= 2)) ? w : -w), center_y + ((i + 1) / 2 % 2 == 0 ? h : -h), moveAngle, 20, 200 + i);
Fishes* fish =createFish(center_x + (((isLeft && i < 2) || (!isLeft && i >= 2)) ? w : -w), center_y + ((i + 1) / 2 % 2 == 0 ? h : -h), moveAngle, 20, 200 + i);
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 28;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
else if (tacticID == 8) {
bool isLeft = Tools::rand() % 2;
int n = 66;
float angle = 0;
float moveAngle = isLeft ? 0 : 180;
float r = winSize.height / 2 + 140;
int center_x = isLeft ? -winSize.height : winSize.width + winSize.height;
int center_y = winSize.height / 2;
int offset_x = 0;
int type = 1;
angle = 360.0f / n;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
// fish* fish = fish::createFish(center_x + Tools::getAngleX(j*angle, r) - 60 + i * 60, center_y + Tools::getAngleY(j*angle, r), moveAngle, type, i * 66 + j);
// Fishes* fish = Fishes::createFish(center_x + Tools::getAngleX(j*angle, r) - 60 + i * 60, center_y + Tools::getAngleY(j*angle, r), moveAngle, type, i * 66 + j);
Fishes* fish = createFish(center_x + Tools::getAngleX(j*angle, r) - 60 + i * 60, center_y + Tools::getAngleY(j*angle, r), moveAngle, type, i * 66 + j);
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 28;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
int ID_buffer = 198;
for (int i = 0; i < 9; i++) {
offset_x = 0;
for (int j = 0; j < 7; j++) {
if (i == 0 || i == 8) {
if (j < 2 || j>4) {
continue;
}
}
else if (i == 1 || i == 7) {
if (j == 0 || j == 6) {
continue;
}
}
else if (i == 3 || i == 5) {
if (j == 3) {
continue;
}
}
else if (i == 4) {
if (j < 2) {
offset_x = -40;
}
else if (j>4) {
offset_x = 40;
}
else {
continue;
}
}
// fish* fish = fish::createFish(center_x - 330 + j * 110 + offset_x, center_y - 320 + i * 80, moveAngle, 6, ID_buffer++);
// Fishes* fish = Fishes::createFish(center_x - 330 + j * 110 + offset_x, center_y - 320 + i * 80, moveAngle, 6, ID_buffer++);
Fishes* fish = createFish(center_x - 330 + j * 110 + offset_x, center_y - 320 + i * 80, moveAngle, 6, ID_buffer++);
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 25;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
// fish* fish = fish::createFish(center_x, center_y + 70, moveAngle, 19, 244);
// Fishes* fish = Fishes::createFish(center_x, center_y + 70, moveAngle, 19, 244);
Fishes* fish = createFish(center_x, center_y + 70, moveAngle, 19, 244);
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 28;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(center_x, center_y - 70, moveAngle, 19, 245);
// fish = Fishes::createFish(center_x, center_y - 70, moveAngle, 19, 245);
fish = createFish(center_x, center_y - 70, moveAngle, 19, 245);
fish->fishAction[0].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[0].time = 28;
fish->fishAction[1].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, moveAngle);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
else if (tacticID == 9) {
int buffer_ID[7] = { 0, 60, 107, 112, 114, 117, 121 };
int index[7] = { 0, 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < 47; i++) {
int MYx;
int MYy;
if (i <= 3) {
MYx = winSize.width + 300 + i * 50;
MYy = 500;
}
else if (i > 3 && i < 7) {
MYx = winSize.width + 450 + (i - 3) * 17;
MYy = 500 + (i - 3) * 30;
}
else if (i >= 7 && i < 15) {
MYx = winSize.width + 501 + (i - 6) * 50;
MYy = 590;
}
else if (i >= 15 && i <= 18) {
MYx = winSize.width + 930 + (i - 14) * 17;
MYy = 590 - (i - 15) * 30;
}
else if (i > 19 && i < 23) {
MYx = winSize.width + 1015 + (i - 19) * 50;
MYy = 500;
}
else if (i >= 23 && i <= 26) {
MYx = winSize.width + 1190;
MYy = 275 + (i - 23) * 60;
}
else if (i > 26 && i <= 42) {
MYx = winSize.width + 300 + (i - 27) * 57;
MYy = 230;
}
else {
MYx = winSize.width + 300;
MYy = 275 + (i - 43) * 60;
}
// fish* fish = fish::createFish(MYx, MYy, 180, 2, buffer_ID[1] + (index[1]++));
// Fishes* fish = Fishes::createFish(MYx, MYy, 180, 2, buffer_ID[1] + (index[1]++));
Fishes* fish = createFish(MYx, MYy, 180, 2, buffer_ID[1] + (index[1]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 180);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
for (int i = 0; i < 5; i++) {
// fish* fish = fish::createFish(winSize.width + 1080, 530 + i * 38, 180, 3, buffer_ID[2] + (index[2]++));
// Fishes* fish = Fishes::createFish(winSize.width + 1080, 530 + i * 38, 180, 3, buffer_ID[2] + (index[2]++));
Fishes* fish = createFish(winSize.width + 1080, 530 + i * 38, 180, 3, buffer_ID[2] + (index[2]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 180);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
for (int i = 0; i < 3; i++) {
// fish* fish = fish::createFish(winSize.width + 580 + i * 140, 540, 180, 8, buffer_ID[4] + (index[4]++));
// Fishes* fish = Fishes::createFish(winSize.width + 580 + i * 140, 540, 180, 8, buffer_ID[4] + (index[4]++));
Fishes* fish = createFish(winSize.width + 580 + i * 140, 540, 180, 8, buffer_ID[4] + (index[4]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 180);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 2; j++) {
// fish* fish = fish::createFish(winSize.width + 500 + j * 480 + Tools::rand() % 50 - 25, 170 + Tools::rand() % 60 - 30, 180, 1, buffer_ID[0] + (index[0]++));
// Fishes* fish = Fishes::createFish(winSize.width + 500 + j * 480 + Tools::rand() % 50 - 25, 170 + Tools::rand() % 60 - 30, 180, 1, buffer_ID[0] + (index[0]++));
Fishes* fish = createFish(winSize.width + 500 + j * 480 + Tools::rand() % 50 - 25, 170 + Tools::rand() % 60 - 30, 180, 1, buffer_ID[0] + (index[0]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 180);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
for (int i = 0; i < 2; i++) {
// fish* fish = fish::createFish(winSize.width + 175, 275 + i * 180, 180, 6, buffer_ID[3] + (index[3]++));
// Fishes* fish = Fishes::createFish(winSize.width + 175, 275 + i * 180, 180, 6, buffer_ID[3] + (index[3]++));
Fishes* fish = createFish(winSize.width + 175, 275 + i * 180, 180, 6, buffer_ID[3] + (index[3]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 180);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(winSize.width + 450 + i * 650, winSize.height / 2, 180, 20, buffer_ID[6] + (index[6]++));
// fish = Fishes::createFish(winSize.width + 450 + i * 650, winSize.height / 2, 180, 20, buffer_ID[6] + (index[6]++));
fish = createFish(winSize.width + 450 + i * 650, winSize.height / 2, 180, 20, buffer_ID[6] + (index[6]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 180);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
//fish = fish::createFish(winSize.width + 1200 + i * 100, winSize.height / 2 - 100, 180, 19, buffer_ID[5] + (index[5]++));
//fish = Fishes::createFish(winSize.width + 1200 + i * 100, winSize.height / 2 - 100, 180, 19, buffer_ID[5] + (index[5]++));
fish = createFish(winSize.width + 1200 + i * 100, winSize.height / 2 - 100, 180, 19, buffer_ID[5] + (index[5]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 180);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
else if (tacticID == 10) {
int buffer_ID[7] = { 0, 60, 107, 112, 114, 117, 121 };
int index[7] = { 0, 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < 47; i++) {
int MYx;
int MYy;
if (i <= 3) {
MYx = -350 - i * 50;
MYy = 500;
}
else if (i > 3 && i < 7) {
MYx = -500 - (i - 3) * 17;
MYy = 500 + (i - 3) * 30;
}
else if (i >= 7 && i < 15) {
MYx = -551 - (i - 6) * 50;
MYy = 590;
}
else if (i >= 15 && i <= 18) {
MYx = -980 - (i - 14) * 17;
MYy = 590 - (i - 15) * 30;
}
else if (i > 19 && i < 23) {
MYx = -1050 - (i - 19) * 50;
MYy = 500;
}
else if (i >= 23 && i <= 26) {
MYx = -1230;
MYy = 275 + (i - 23) * 60;
}
else if (i > 26 && i <= 42) {
MYx = -300 - (i - 26) * 57;
MYy = 230;
}
else {
MYx = -350;
MYy = 275 + (i - 43) * 60;
}
// fish* fish = fish::createFish(MYx, MYy, 0, 2, buffer_ID[1] + (index[1]++));
// Fishes* fish = Fishes::createFish(MYx, MYy, 0, 2, buffer_ID[1] + (index[1]++));
Fishes* fish = createFish(MYx, MYy, 0, 2, buffer_ID[1] + (index[1]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 0);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
for (int i = 0; i < 5; i++) {
// fish* fish = fish::createFish(-1130, 530 + i * 38, 0, 3, buffer_ID[2] + (index[2]++));
// Fishes* fish = Fishes::createFish(-1130, 530 + i * 38, 0, 3, buffer_ID[2] + (index[2]++));
Fishes* fish = createFish(-1130, 530 + i * 38, 0, 3, buffer_ID[2] + (index[2]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 0);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
for (int i = 0; i < 3; i++) {
// fish* fish = fish::createFish(-640 - i * 140, 540, 0, 8, buffer_ID[4] + (index[4]++));
// Fishes* fish = Fishes::createFish(-640 - i * 140, 540, 0, 8, buffer_ID[4] + (index[4]++));
Fishes* fish = createFish(-640 - i * 140, 540, 0, 8, buffer_ID[4] + (index[4]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 0);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 2; j++) {
// fish* fish = fish::createFish(-550 - j * 480 - (Tools::rand() % 50 - 25), 170 + Tools::rand() % 60 - 30, 0, 1, buffer_ID[0] + (index[0]++));
// Fishes* fish = Fishes::createFish(-550 - j * 480 - (Tools::rand() % 50 - 25), 170 + Tools::rand() % 60 - 30, 0, 1, buffer_ID[0] + (index[0]++));
Fishes* fish = createFish(-550 - j * 480 - (Tools::rand() % 50 - 25), 170 + Tools::rand() % 60 - 30, 0, 1, buffer_ID[0] + (index[0]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 0);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
for (int i = 0; i < 2; i++) {
// fish* fish = fish::createFish(-500 - i * 650, winSize.height / 2, 0, 20, buffer_ID[6] + (index[6]++));
// Fishes* fish = Fishes::createFish(-500 - i * 650, winSize.height / 2, 0, 20, buffer_ID[6] + (index[6]++));
Fishes* fish = createFish(-500 - i * 650, winSize.height / 2, 0, 20, buffer_ID[6] + (index[6]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 0);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(-1250 - i * 100, winSize.height / 2 - 100, 0, 19, buffer_ID[5] + (index[5]++));
// fish = Fishes::createFish(-1250 - i * 100, winSize.height / 2 - 100, 0, 19, buffer_ID[5] + (index[5]++));
fish = createFish(-1250 - i * 100, winSize.height / 2 - 100, 0, 19, buffer_ID[5] + (index[5]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 30;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 0);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
// fish = fish::createFish(-260, 275 + i * 180, 0, 19, buffer_ID[5] + (index[5]++));
// fish = Fishes::createFish(-260, 275 + i * 180, 0, 19, buffer_ID[5] + (index[5]++));
fish = createFish(-260, 275 + i * 180, 0, 19, buffer_ID[5] + (index[5]++));
fish->fishAction[0].actionID = Fishes::ACTION_WAIT;
fish->fishAction[0].time = 0.5f;
fish->fishAction[1].actionID = Fishes::ACTION_RUN_LINE;
fish->fishAction[1].time = 20;
fish->fishAction[2].actionID = Fishes::ACTION_CLEAR;
fish->setSpeed(100, 0);
if (isUpside) {
fish->angle += 180;
fish->angle = fmod(fish->angle, 360);
fish->x = winSize.width - fish->x;
fish->y = winSize.height - fish->y;
fish->setAngle(fish->angle);
fish->setV_xy();
}
fish->buffer_x = fish->x;
fish->buffer_y = fish->y;
fish->buffer_angle = fish->angle;
}
}
for (int i = 0; i < S_Fish_Group->wCount; i++) {
bool s = false;
//debug_("SUB_S_SEND_FISH_PATH_GROUP:", S_Fish_Group->FishNetIDs[i].wID);
//fish* currentFish = fish::headDrawFish;
//while (currentFish != NULL) {
// GameObject* tem = currentFish->nextDrawGameObject;
// if (currentFish->hasFlag(fish::FLAG_UPDATE) && !currentFish->isState(fish::STATE_EXPLODE)) {
// if (currentFish->server_ID == S_Fish_Group->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
// currentFish->onClear();
// s = true;
// break;
// }
// }
// currentFish = (Fish*)tem;
//}
//用stl
//mutexDestructFish.lock();
//if (!allFishes.empty())
//{
// std::list<shared_ptr<Fishes>>::iterator it = allFishes.begin();
// for ( ; it!=allFishes.end();it++)
// {
// if (RepositionSubState) return true;
// if ((*it).get()->server_ID == S_Fish_Group->FishNetIDs[i].wID)
// {
// (*it).get()->setSign(true);
// // (*it)->onClear();
// // it = allFishes.erase(it);
// // s = true;
// // break;
// }
// //else
// //{
// // it++;
// //}
// }
//}
//mutexDestructFish.unlock();
//if (!s) {
// debug_("error:", S_Fish_Group->FishNetIDs[i].wID);
//}
//else {
// debug_("done");
//}
}
setState(STATE_TACTIC);
Fishes::tactic_duration = S_Fish_Group->fPassTime;
return true;
}
case SUB_S_END:
{
LOGD("游戏结束");
return true;
}
case SUB_S_SEND_HIGHT_SCORE://全局分数通知
{
LOGD("全局分数通知");
return true;
}
case SUB_S_SEND_CLEAR_PLAYER://清空玩家
{
LOGD("清空玩家");
return true;
}
case SUB_S_SEND_King_FISH_SUCCESS://打中八爪鱼
debug_("SUB_S_SEND_King_FISH_SUCCESS");
{
CMD_S_Hit_King_Success * S_Hit_King_Success = (CMD_S_Hit_King_Success *)pData;
}
return true;
case SUB_S_SEND_TIME://时间
debug_("SUB_S_SEND_TIME");
{
CMD_S_Time * S_Time = (CMD_S_Time *)pData;
}
return true;
case SUB_S_KICK_PLAYER:
debug_("SUB_S_KICK_PLAYER");
{
}
return true;
case SUB_S_GAME_SCENE:
debug_("SUB_S_GAME_SCENE");
{
//CMD_S_StatusFree * S_StatusFree = (CMD_S_StatusFree *)pData;
//for(int i=0;i<GAME_PLAYER;i++) {
// debug_("Role_Net_Object:wChairID=%d,lFishGold=%d,wCost=%d", S_StatusFree->RoleObjects[i].wChairID, S_StatusFree->RoleObjects[i].lFishGold, S_StatusFree->RoleObjects[i].wCost);
// if(S_StatusFree->RoleObjects[i].wChairID<GAME_PLAYER) {
// int cannonID = getCannonID(S_StatusFree->RoleObjects[i].wChairID);
// if(cannonID>=GAME_PLAYER)
// continue;
// fishPlayer[cannonID].lFishGold = S_StatusFree->RoleObjects[i].lFishGold;
// fishPlayer[cannonID].wCost = S_StatusFree->RoleObjects[i].wCost;
// if(hasInitCannon) {
// cannon[cannonID]->setMoney(fishPlayer[cannonID].lFishGold);
// cannon[cannonID]->times_frameLab->setString(StringUtils::format("%d", fishPlayer[cannonID].wCost));
// }
// }
//}
return true;
}
return true;
case SUB_S_SPEED_FREQUENCY:
debug_("SUB_S_SPEED_FREQUENCY");
{
CMD_S_SpeedFrequency * S_SpeedFrequency = (CMD_S_SpeedFrequency *)pData;
}
return true;
case SUB_S_PAUSE:
{
CMD_C_PAUSE *pause = (CMD_C_PAUSE*)pData;
if (pause->wChairID != m_RobotID) pause_count = 0;
LOGD("有人打到暂停了,pause_count: "<<pause_count);
}
case SUB_S_ACCOUNT: //没用到
{
CMD_S_Account * S_Account = (CMD_S_Account *)pData;
if (S_Account->wChairID == m_RobotID)
{
int ID = S_Account->wChairID;
//if (isUpsideEx) {
// ID = getCannonID(ID);
//}
LOGD("lPlayerScore: " << S_Account->lPlayerScore << " lCellScore: " << S_Account->lCellScore);
m_nFishGold = S_Account->lPlayerScore;
}
}
return true;
case SUB_S_AI_ENTER:
{
CMD_S_AI_Enter * aiEnter = (CMD_S_AI_Enter*)pData;
if (aiEnter->wChairID == m_RobotID)
{
IServerUserItem * pIServerUserItem = m_pIAndroidUserItem->GetMeUserItem();
int userid = pIServerUserItem->GetUserID();
SCORE score = aiEnter->lScore;
//LOGD("有机器人进入,userID: " << userid << "分数:"<<score);
//fishPlayer[m_RobotID].lFishGold = score;
}
}
return true;
default:
LOGD("wSubCmdID: " << wSubCmdID);
return true;
}
return true;
}
//游戏消息
bool CAndroidUserItemSink::OnEventFrameMessage(WORD wSubCmdID, void * pData, WORD wDataSize)
{
return true;
}
//场景消息
bool CAndroidUserItemSink::OnEventSceneMessage(BYTE cbGameStatus, bool bLookonOther, void * pData, WORD wDataSize)
{
//LOGD("CAndroidUserItemSink::OnEventSceneMessage cbGameStatus = " << cbGameStatus)
srand(time(0));
switch (cbGameStatus)
{
case GAME_STATUS_FREE: //空闲状态
case GAME_STATUS_PLAY: //游戏状态
{
ASSERT(wDataSize == sizeof(CMD_S_StatusFree));
if (wDataSize!=sizeof(CMD_S_StatusFree)) return false;
CMD_S_StatusFree * pStatusFree = (CMD_S_StatusFree *)pData;
//LONGLONG score = m_pIAndroidUserItem->GetMeUserItem()->GetUserInfo()->lScore;
//int userid = m_pIAndroidUserItem->GetMeUserItem()->GetUserID();
//int gameid = m_pIAndroidUserItem->GetMeUserItem()->GetGameID();
//LOGD("UserID: "<<userid<<" GameID: "<<gameid<<" 服务器发过来的分数: " << score);
m_cbScene = pStatusFree->cbScene;
m_lCellScore = pStatusFree->lCellScore;
//m_maxWeaponCost = pStatusFree->wMaxFire;
m_onceUpScore = pStatusFree->dwOnceUpScore;
CopyMemory(m_RoleObjects, pStatusFree->RoleObjects, GAME_PLAYER*sizeof(Role_Net_Object));
IServerUserItem * pIServerUserItem = m_pIAndroidUserItem->GetMeUserItem();
pause_count = pause_n;
RepositionSubState = false;
m_RobotID = pIServerUserItem->GetChairID();//opposite对面的
int type = m_RobotID / (GAME_PLAYER / 2) == 0 ? TYPE_NORMAL : TYPE_OPPOSITE;
int gap = 210;
int w = winSize.width - gap;
setCannonPosition(type,gap,w);//设置炮台的坐标
//LOGD( "炮台坐标x: " << m_positionX << "炮台坐标y: " << m_positionY);
//LOGD("allbullets.size: " << allBullets.size());
if (currentChairID < 0) {
currentChairID = pIServerUserItem->GetChairID();
currentCannonID = currentChairID % (GAME_PLAYER / 2);
if (currentChairID >= GAME_PLAYER / 2)
{
isUpside = true; //在屏幕的上方
isUpsideEx = true;
}
else
{
isUpside = false;
isUpsideEx = false;
}
}
//做一个特殊处理,之后用isUpside做条件判断的都用isUpsideEx作条件,创建鱼中的判断还用isUpside做条件,这里存在一个坐标的问题,如果在创建鱼当中
//炮台坐标在屏幕的上方,并且isUpside为true,存在一个这样的问题,客户端鱼的x坐标,机器人对应鱼的坐标是屏幕的长度-x,客户端y的坐标,机器人对应的
//坐标是屏幕的高度-y
if (isUpside)
{
isUpside = false;
}
for (int i = 0; i<4; i++)
{
nCannonCount[i] = pStatusFree->nCannonCount[i];
}
for (int i = 0; i<GAME_PLAYER; i++) {
if (pStatusFree->RoleObjects[i].wChairID<GAME_PLAYER) {
//int cannonID = getCannonID(pStatusFree->RoleObjects[i].wChairID);
if (i >= GAME_PLAYER)
continue;
fishPlayer[i].lFishGold = pStatusFree->RoleObjects[i].lFishGold;
fishPlayer[i].wCost = pStatusFree->RoleObjects[i].wCost;
int gunNum = 1;
if (fishPlayer[i].wCost<nCannonCount[2]) {
gunNum = 1;
}
else if (fishPlayer[i].wCost<nCannonCount[3]) {
gunNum = 2;
}
else {
gunNum = 3;
}
if (cannon)
cannon->setGunNum(gunNum);
}
}
buyFishGold = pIServerUserItem->GetUserScore();
if (pIServerUserItem == NULL) return true;
//玩家设置
//LOGD("------------------------------------------------");
//LONGLONG score =pIServerUserItem->GetUserInfo()->lScore;
//int userid = pIServerUserItem->GetUserID();
//LOGD("UserID: " << userid <<"分数:" << score);
//LOGD("------------------------------------------------");
if (pIServerUserItem->GetUserStatus() == US_SIT || pIServerUserItem->GetUserStatus() == US_PLAYING)
{
LOGD("CAndroidUserItemSink::OnEventSceneMessage 3")
UINT nElapse = rand() % TIME_BUY_BULLET + TIME_LESS * 3;
m_pIAndroidUserItem->SetGameTimer(IDI_BUY_BULLET,nElapse);
}
//定时打印一下鱼和子弹的size大小
m_pIAndroidUserItem->SetGameTimer(IDI_LOG_SIZE, 5);
t1=std::thread(&CAndroidUserItemSink::threadUpdate, this);
t1.detach();
return true;
}
// case GAME_STATUS_PLAY: //游戏状态
// {
// return true;
// }
}
ASSERT(0);
return false;
}
//用户进入
void CAndroidUserItemSink::OnEventUserEnter(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
LOGD("机器人进入了");
////char text[500] = { 0 };
////sprintf(text, "有机器人进入:%d\n", pIAndroidUserItem->GetChairID());
////OutputDebugString(text);
////LOGD("CAndroidUserItemSink::OnEventUserEnter bLookonUser = " << bLookonUser)
//// if (bLookonUser == false) {
//// //debug_("UserID= %d, NickName= %s, ChairID= %d", pIClientUserItem->GetUserID(), pIClientUserItem->GetNickName(), pIClientUserItem->GetChairID());
//// if (currentChairID < 0) {
//// currentChairID = pIAndroidUserItem->GetChairID();
//// currentCannonID = currentChairID % (GAME_PLAYER / 2);
//// if (currentChairID >= GAME_PLAYER / 2)
//// isUpside = true;
//// else
//// isUpside = false;
//// }
//// }
//Fish::initFishs(600);//用户进来创建600条鱼的链
}
//用户离开
void CAndroidUserItemSink::OnEventUserLeave(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
LOGD("CAndroidUserItemSink::OnEventUserLeave bLookonUser = " << bLookonUser)
LOGD("机器人离开了");
}
//用户积分
void CAndroidUserItemSink::OnEventUserScore(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
LOGD("CAndroidUserItemSink::OnEventUserScore bLookonUser = " << bLookonUser)
}
//用户状态
void CAndroidUserItemSink::OnEventUserStatus(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
LOGD("CAndroidUserItemSink::OnEventUserStatus bLookonUser = " << bLookonUser)
}
//用户段位
void CAndroidUserItemSink::OnEventUserSegment(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
LOGD("CAndroidUserItemSink::OnEventUserSegment bLookonUser = " << bLookonUser)
}
/// 购买子弹
void CAndroidUserItemSink::BuyBullet()
{
CMD_C_Buy_Bullet buyBullet;
//LONGLONG bulletArray[10] = {100000,150000,200000,250000,300000,350000,400000,450000,500000,600000};
buyBullet.lCount = m_pIAndroidUserItem->GetMeUserItem()->GetUserScore();//从数据库中读取的范围在那两个字段之间的;
//LOGD("不是第一次买子弹,买子弹数量:" << buyBullet.lCount << " UserID: " << m_pIAndroidUserItem->GetUserID());
if (m_bFirstBuy)
{
buyBullet.lCount = buyFishGold;
}
//发送数据
m_pIAndroidUserItem->SendSocketData(SUB_C_BUY_BULLET,&buyBullet,sizeof(buyBullet));
m_bFirstBuy = true;
}
void CAndroidUserItemSink::LockTarget()
{
//cout<<"ClearBullet()"<<endl;
LOGI("CAndroidUserItemSink::LockTarget")
CMD_C_Fire_Lock lockTarget;
CMD_C_Fish_Net_Object fishtpye;
fishtpye.cbType = 0;
fishtpye.wID = 0;
lockTarget.target = fishtpye;
m_pIAndroidUserItem->SendSocketData(SUB_C_FIRE_LOCK, &lockTarget, sizeof(CMD_C_Fire_Lock));
}
/// 切换子弹
void CAndroidUserItemSink::ChangeCannon()
{
//LOGI("CAndroidUserItemSink::ChangeCannon")
//if ( m_nWeaponCost < 100 )
//{
// m_nWeaponCost += 10;
// if (m_nWeaponCost>20 && m_nWeaponCost<=50)
// {
// m_nWeaponCost = 50;
// }
// if (m_nWeaponCost > 50 && m_nWeaponCost <80)
// {
// m_nWeaponCost = 80;
// }
// if (m_nWeaponCost>=80)
// {
// m_nWeaponCost = 100;
// }
//}
//else if ( m_nWeaponCost >= 100 && m_nWeaponCost < 1000 )
//{
// m_nWeaponCost += 100;
// if (m_nWeaponCost>300 && m_nWeaponCost<500)
// {
// m_nWeaponCost = 500;
// }
// if (m_nWeaponCost > 500 && m_nWeaponCost < 800)
// {
// m_nWeaponCost = 800;
// }
// if (m_nWeaponCost > 800)
// {
// m_nWeaponCost = 1000;
// }
//}
//else if ( m_nWeaponCost >= 1000 )
//{
// //m_nWeaponCost += 1000;
// m_nWeaponCost =10;
//}
//if (fishPlayer[m_RobotID].lFishGold>1000000)//如果机器人的钱大于1000000,默认为1000的炮
//{
// m_nWeaponCost = 1000;
//}
//else if (fishPlayer[m_RobotID].lFishGold>50000)//如果机器人的钱大于500000小于5000000
//{
// if (m_nWeaponCost < 100)
// {
// m_nWeaponCost = 300;
// }
// else if (m_nWeaponCost >= 100 && m_nWeaponCost < 1000)
// {
// m_nWeaponCost += 100;
// if (m_nWeaponCost>300 && m_nWeaponCost<500)
// {
// m_nWeaponCost = 500;
// }
// if (m_nWeaponCost > 500 && m_nWeaponCost < 800)
// {
// m_nWeaponCost = 800;
// }
// if (m_nWeaponCost > 800)
// {
// m_nWeaponCost = 1000;
// }
// }
// else if (m_nWeaponCost >= 1000)
// {
// m_nWeaponCost = 300;
// }
//}
//else //如果机器人的分小于500000
//{
if (m_nWeaponCost < 100)
{
m_nWeaponCost += 10;
if (m_nWeaponCost>20 && m_nWeaponCost <= 50)
{
m_nWeaponCost = 50;
}
if (m_nWeaponCost > 50 && m_nWeaponCost <80)
{
m_nWeaponCost = 80;
}
if (m_nWeaponCost >= 80)
{
m_nWeaponCost = 100;
}
}
else if (m_nWeaponCost >= 100 && m_nWeaponCost < 1000)
{
m_nWeaponCost += 100;
if (m_nWeaponCost>300 && m_nWeaponCost<500)
{
m_nWeaponCost = 500;
}
if (m_nWeaponCost > 500 && m_nWeaponCost < 800)
{
m_nWeaponCost = 800;
}
if (m_nWeaponCost > 800)
{
m_nWeaponCost = 1000;
}
}
else if (m_nWeaponCost >= 1000)
{
//m_nWeaponCost += 1000;
m_nWeaponCost = 10;
}
//}
//切换子弹
CMD_C_Change_Cannon changeCannon;
getCanAttri(m_RobotID);//获取一下炮台的属性
if (m_isSuper) changeCannon.cbStyle = 1;
else changeCannon.cbStyle = 0;
changeCannon.wCost = m_nWeaponCost;
//发送数据
m_pIAndroidUserItem->SendSocketData(SUB_C_CHANGE_CANNON,&changeCannon,sizeof(changeCannon));
m_pIAndroidUserItem->SetGameTimer(IDI_CHANGE_BULLET, 70);
}
/// 发射子弹
void CAndroidUserItemSink::Fire()
{
//LOGD("Fire里边,机器人lFishGold:" << fishPlayer[m_RobotID].lFishGold << "当前炮台分:" << fishPlayer[m_RobotID].wCost);
//LOGI("Fire里边,机器人lFishGold:" << fishPlayer[m_RobotID].lFishGold << "当前炮台分:" << fishGold);
//LI("Fire里边机器人lFishGold" << fishPlayer[m_RobotID].lFishGold << "当前炮台分" << m_nWeaponCost);
if (fishPlayer[m_RobotID].lFishGold > fishGold)
{
m_nLastRoteFireCount++;
CMD_C_Fire fire;
WORD wChairID = m_pIAndroidUserItem->GetChairID();
////if (wChairID == 0 || wChairID == 1)
//// Fire.fRote += 180;
//m_fLastFireRote = m_fNowFireRote;
if (m_nLastRoteFireCount >= m_nToChangeRote)
{
m_nLastRoteFireCount = 0;
//m_nToChangeRote =RandFun(2, 20);
//m_fNowFireRote = (float)RandFun(0, (int)(M_PI * 100000)) / 100000.f;
//m_fNowFireRote-=M_PI_2;
m_nToChangeRote = RandFun(2, 40);
if (m_positionY>0)//炮台在屏幕的上边
{
//x = rand() % 1000;
x = rand()%800;
y = 0;
angle = getAngel(x - m_positionX, y - m_positionY);
}
else
{
//x = rand() % 1000 + 140;
//y = 360;
x = rand() % 1000;
y = 500;
angle = Tools::getAngle(x - m_positionX, y - m_positionY);
if (angle > 180) {
if (angle < 270) {
angle = 180;
}
else {
angle = 0;
}
}
}
}
fire.fRote = angle;
if (m_nNumberToFire == 0)
{
bulletCount = 0;
//m_nNumberToFire = RandFun(1, 10);
m_nNumberToFire = 8;
m_pIAndroidUserItem->SetGameTimer(IDI_FIRE, rand()%TIME_FIRE+TIME_LESS);
}
else
{
//if (m_nFishGold > 1500&&allBullets.size()<10)
{
//if (!(pause_count <pause_n))
//{
//LOGD("子弹角度: " << angle);
if (fishPlayer[m_RobotID].lFishGold > 0)
{
m_pIAndroidUserItem->SendSocketData(SUB_C_FIRE, &fire, sizeof(CMD_C_Fire));
CreateBullets(1);
fishPlayer[m_RobotID].lFishGold -= fishGold;
}
}
m_pIAndroidUserItem->SetGameTimer(IDI_FIRE,1.5);
}
m_nNumberToFire--;
}
else if (fishPlayer[m_RobotID].lFishGold != 0 && (rand() % 10)>3)
{
ChangeCannon();
}
else
{
/// 购买子弹
BuyBullet();
//LOGD("钱不够的时候,购买子弹");
}
}
//向服务器发送消息
void CAndroidUserItemSink::sendMessage(WORD wSubCmdID, void* pData, WORD wDataSize) {
//debug_("sendMessage");
if (m_pIAndroidUserItem)
{
m_pIAndroidUserItem->SendSocketData(wSubCmdID, pData, wDataSize);
}
else
{
char text[500] = { 0 };
sprintf(text, "机器人的ChairID:%d,m_onceUpScore:%d\n", m_pIAndroidUserItem->GetChairID(), m_onceUpScore);
OutputDebugString(text);
}
}
//随机一个点,像客户端触摸一样
void CAndroidUserItemSink::RandomPoint()//随机一个方向
{
/*x = rand() % 1280;
y = rand() % 720;
if (m_positionY>0)
{
angle = getAngel(x - m_positionX, y - m_positionY);
}
else
{
angle = Tools::getAngle(x - m_positionX, y - m_positionY);
if (angle > 180) {
if (angle < 270) {
angle = 180;
}
else {
angle = 0;
}
}
}*/
}
//创建子弹
void CAndroidUserItemSink::CreateBullets(int num)//每次向服务器发送Fire创建一个子弹
{
int count = 0;
if (allBullets.size()>50) return;
while (count<num)
{
getCanAttri(m_RobotID);
if (m_RobotID >1) {//cannonID=chairID 在屏幕的上方
float a = Tools::getAngleX(180-angle, 70);
float b = Tools::getAngleY(180-angle, 70);
float c = Tools::getAngleX(angle, 70);
float d = Tools::getAngleY(angle, 70);
float e = angle;
float f = 180 - angle;
//LOGD("m_positionX: " << m_positionX << " m_positionY: " << m_positionY <<" angle: " << angle << " Tools::getAngleX(180-angle, 70) : " << a << " Tools::getAngleY(180-angle, 70): "<<b);
//LOGD("angle: "<< e << " 180-angle "<<f);
//LOGD("Tools::getAngleX(180-angle, 70) : "<< a << "Tools::getAngleY(180-angle, 70): " << b);
//LOGD("Tools::getAngleX(angle, 70) : " << c << "Tools::getAngleY(angle, 70): " << d);
//LOGD("---------------------------------------");
//shared_ptr<Bullet> bullet = createBullet(m_positionX +Tools::getAngleX(angle, 70), m_positionY- Tools::getAngleY(angle, 70), 180 - angle, 900, 0, (m_isSuper ? m_GunNum - 1 : 3 + (m_GunNum - 1)*GAME_PLAYER + m_RobotID));
Bullet* bullet = createBullet(m_positionX - Tools::getAngleX(angle, 70), 665 - Tools::getAngleY(angle, 70), 180 - angle, 850, 0, (m_isSuper ? m_GunNum - 1 : 3 + (m_GunNum - 1)*GAME_PLAYER + m_RobotID));
}
else {//在屏幕的下方
//float a = Tools::getAngleX(angle, 70);
//float b = Tools::getAngleY(angle, 70);
//LOGD("m_positionX: " << m_positionX << " angle: " << angle << " m_positionY: " << m_positionY << " Tools::getAngleX(angle, 70) :" << a << " Tools::getAngleY(angle, 70) :" << b);
Bullet* bullet = createBullet(m_positionX + Tools::getAngleX(angle, 70), 55 + Tools::getAngleY(angle, 70), angle, 850, 1, (m_isSuper ? m_GunNum - 1 : 3 + (m_GunNum - 1)*GAME_PLAYER + m_RobotID));
}
count++;
}
}
//鱼每一帧要移动
void CAndroidUserItemSink::UpdateFish()
{
if (allFishes.size()>0)
{
FISHES::iterator iter = allFishes.begin();
for (; iter != allFishes.end();)
{
auto a = (*iter).get()->x;
auto b = (*iter).get()->y;
//if (!Tools::isGameObjectCollision((*it).get(), (*it).get()->x - 1400, (*it).get()->x + winSize.width + 1400, (*it).get()->y + winSize.height + 1400, (*it).get()->y - 1400))
if (((*iter).get()->x<-300) || ((*iter).get()->x>1880) || ((*iter).get()->y<-300) || ((*iter).get()->y>1520))//鱼游出固定范围删除掉
{
iter = allFishes.erase(iter);
}
else
{
(*iter).get()->update();
//LOGD("UpdateFish,fish_ID: " << (*it).get()->fish_ID << " x: " << (*it).get()->x << " y: " << (*it).get()->y << " angle: " << (*it).get()->angle << " size: " << allFishes.size());
iter++;
}
}
}
return;
}
//子弹每一帧要移动
void CAndroidUserItemSink::UpdateBullet()
{
if (!allBullets.empty())
{
std::list<std::shared_ptr<Bullet>>::iterator it1 = allBullets.begin();
for (; it1 != allBullets.end();)
{
//step1: 首先更新子弹的位置:
(*it1).get()->update();
//LOGD("MoveBullet bullet_ID:" << (*it1).get()->bullet_ID << " x:" << (*it1).get()->x << " y:" << (*it1).get()->y);
//step2: 判断子弹和鱼的碰撞
//if (allFishes.empty()) return;
FISHES::iterator it2 = allFishes.begin();
FISHES::iterator it3 = allFishes.begin();
bool isExplode = false; //标记是否击中鱼
bool isCollision = false;
for (; it3 != allFishes.end(); it3++)
{
if ((*it1).get()->isFishCollisionBullet((*it3).get())) //鱼碰子弹
{
isExplode = true;
(*it1).get()->setSign(true);
//LOGD("MoveBullet bullet_ID:" << (*it1).get()->bullet_ID << " x:" << (*it1).get()->x << " y:" << (*it1).get()->y);
//LOGD("MoveFish fish_ID:" << (*it3).get()->fish_ID << " x:" << (*it3).get()->x << " y:" << (*it3).get()->y);
//LOGD("bullet_ID: " << (*it1).get()->bullet_ID << "和" << "fish_ID: " << (*it3).get()->fish_ID<<"碰撞了");
break;
}
}
if (isExplode)
{
fish_num = 0;
for (; it2 != allFishes.end(); it2++) //遍历鱼跟子弹碰撞
{
if ((*it1).get()->isFishCollisionNet((*it2).get())) //判断碰撞结果
{
isCollision = true;
target = (*it2).get();
if (fish_num < MAX_FISH_IN_NET) {
fish_buffer[fish_num][0] = (*it2).get()->server_ID;
fish_buffer[fish_num][1] = (*it2).get()->fish_type;
fish_buffer[fish_num][2] = (*it2).get()->fish_style;
fish_buffer[fish_num][3] = (*it2).get()->mark_ID;
fish_num++;
}
//(*it2)->onHurt(0);
onHurt((*it2), 0);
if (fish_num >= MAX_FISH_IN_NET) {
break;
}
}
}
if (fish_num > 0) //碰撞之后给服务器发消息
{
(*it1).get()->target_offset_w = (*it1).get()->x - target->x;
(*it1).get()->target_offset_h = (*it1).get()->y - target->y;
//(*it1).get()->onHurt(1);
if ((*it1).get()->from_ID == 1 || (*it1).get()->from_ID == 0)
{
int cmd_level = Fish_CMD_Priority::NORMAL_LEVEL;
fish_num = 1;
for (int i = 0; i<fish_num; i++) {
int current_cmd_level = Fish_CMD_Priority::NORMAL_LEVEL;
if (fish_buffer[i][1] == 22) {
current_cmd_level = Fish_CMD_Priority::SCREEN_BOMB_LEVEL;
}
else if (fish_buffer[i][1] == 21) {
current_cmd_level = Fish_CMD_Priority::BOAT_LEVEL;
}
else if (fish_buffer[i][1] == 24) {
current_cmd_level = Fish_CMD_Priority::RANGE_BOMB_LEVEL;
}
else if (fish_buffer[i][2] == Fishes::STYLE_SAME) {
current_cmd_level = Fish_CMD_Priority::TYPE_BOMB_LEVEL;
}
else if (fish_buffer[i][2] == Fishes::STYLE_TEAM) {
current_cmd_level = Fish_CMD_Priority::TEAM_LEVEL;
}
if (current_cmd_level<cmd_level) {
cmd_level = current_cmd_level;
}
}
switch (cmd_level)
{
case Fish_CMD_Priority::SCREEN_BOMB_LEVEL:
debug_("SCREEN_BOMB_LEVEL");
{
CMD_C_Hit_Screen_Bomb C_Hit_Screen_Bom;
C_Hit_Screen_Bom.wRatio = 100;
for (int i = 0; i < fish_num; i++) {
if (fish_buffer[i][1] == 22) {
C_Hit_Screen_Bom.hitFish.wID = fish_buffer[i][0];
C_Hit_Screen_Bom.hitFish.cbType = fish_buffer[i][1];
break;
}
}
m_pIAndroidUserItem->SendSocketData(SUB_C_SCREEN_BOBM, &C_Hit_Screen_Bom, sizeof(CMD_C_Hit_Screen_Bomb));
}
break;
case Fish_CMD_Priority::BOAT_LEVEL:
debug_("BOAT_LEVEL");
{
CMD_C_HitBoat C_HitBoat;
C_HitBoat.cbCount = 1;
C_HitBoat.wRatio = 0;
for (int i = 0; i < fish_num; i++) {
if (fish_buffer[i][1] == 21) {
C_HitBoat.hitFish.wID = fish_buffer[i][0];
C_HitBoat.hitFish.cbType = fish_buffer[i][1];
break;
}
}
m_pIAndroidUserItem->SendSocketData(SUB_C_HIT_BOAT, &C_HitBoat, sizeof(CMD_C_HitBoat));
}
break;
case Fish_CMD_Priority::RANGE_BOMB_LEVEL:
debug_("RANGE_BOMB_LEVEL!!!!!!!!");
{
}
break;
case Fish_CMD_Priority::TYPE_BOMB_LEVEL:
debug_("TYPE_BOMB_LEVEL");
{
CMD_C_TypeBomb_dte C_TpyeBomb_dte;
for (int i = 0; i < fish_num; i++) {
if (fish_buffer[i][2] == Fishes::STYLE_SAME) {
C_TpyeBomb_dte.hitFish.wID = fish_buffer[i][0];
C_TpyeBomb_dte.hitFish.cbType = fish_buffer[i][1];
break;
}
}
C_TpyeBomb_dte.cbCount = 0;
//用stl重写
if (!allFishes.empty())
{
FISHES::iterator it = allFishes.begin();
for (; it != allFishes.end(); it++)
{
if ((*it)->fish_type == C_TpyeBomb_dte.hitFish.cbType) {
C_TpyeBomb_dte.FishNetIDs[C_TpyeBomb_dte.cbCount].wID = (WORD)(*it)->server_ID;
C_TpyeBomb_dte.FishNetIDs[C_TpyeBomb_dte.cbCount].cbType = (BYTE)(*it)->fish_type;
C_TpyeBomb_dte.cbCount++;
if (C_TpyeBomb_dte.cbCount >= MAX_FISH_BY_BOMB) {
break;
}
}
}
}
m_pIAndroidUserItem->SendSocketData(SUB_C_TPYE_BOBM, &C_TpyeBomb_dte, sizeof(CMD_C_TypeBomb_dte) - (MAX_FISH_BY_BOMB - C_TpyeBomb_dte.cbCount)*sizeof(CMD_C_Fish_Net_Object));
}
break;
case Fish_CMD_Priority::TEAM_LEVEL:
debug_("TEAM_LEVEL");
{
CMD_C_HitTeam_dte C_HitTeam_dte;
int mark_ID = 0;
for (int i = 0; i < fish_num; i++) {
if (fish_buffer[i][2] == Fishes::STYLE_TEAM) {
C_HitTeam_dte.hitFish.wID = fish_buffer[i][0];
C_HitTeam_dte.hitFish.cbType = fish_buffer[i][1];
mark_ID = fish_buffer[i][3];
break;
}
}
C_HitTeam_dte.cbCount = 0;
//用STL实现
if (!allFishes.empty())
{
FISHES::iterator it = allFishes.begin();
for (; it != allFishes.end(); it++)
{
if ((*it)->mark_ID == mark_ID) {
C_HitTeam_dte.FishNetIDs[C_HitTeam_dte.cbCount].wID = (WORD)(*it)->server_ID;
C_HitTeam_dte.FishNetIDs[C_HitTeam_dte.cbCount].cbType = (BYTE)(*it)->fish_type;
C_HitTeam_dte.cbCount++;
if (C_HitTeam_dte.cbCount >= MAX_FISH_IN_TEAM) {
break;
}
}
}
}
m_pIAndroidUserItem->SendSocketData(SUB_C_HIT_TEAM, &C_HitTeam_dte, sizeof(CMD_C_HitTeam_dte) - (MAX_FISH_IN_TEAM - C_HitTeam_dte.cbCount)*sizeof(CMD_C_Fish_Net_Object));
}
break;
case Fish_CMD_Priority::NORMAL_LEVEL:
debug_("NORMAL_LEVEL");
{
C_Cast_Net_dte.cbCount = fish_num;
for (int i = 0; i<fish_num; i++) {
C_Cast_Net_dte.FishNetIDs[i].wID = (WORD)fish_buffer[i][0];
C_Cast_Net_dte.FishNetIDs[i].cbType = (BYTE)fish_buffer[i][1];
}
m_pIAndroidUserItem->SendSocketData(SUB_C_CAST_NET, &C_Cast_Net_dte, sizeof(CMD_C_Cast_Net_dte) - (MAX_FISH_IN_NET - C_Cast_Net_dte.cbCount)*sizeof(CMD_C_Fish_Net_Object));
}
break;
default:
break;
}
}
}
}
if (isExplode)
{
//step3:击中鱼移除出子弹iteras
it1 = allBullets.erase(it1);
//LOGD("移除子弹");
}
else
{
it1++; //迭代器++
}
}
}
return;
}
//随机
int CAndroidUserItemSink::RandFun(int min, int max)
{
if (max < min)
{
int tmp = max;
max = min;
min = tmp;
}
CRandom random;
return min + random.Random(max - min);
}
//状态
bool CAndroidUserItemSink::isState(int state)
{
return (m_state == state);
}
void CAndroidUserItemSink::setState(int state)
{
m_state = state;
if (state == STATE_TACTIC) {
Fishes::tactic_duration = 0;
}
}
//另起一个线程,用于判断鱼和子弹之间的碰撞和鱼和子弹每一帧的位移
void CAndroidUserItemSink::threadUpdate()
{
while (true)
{
if (m_nMainState == 1)//说明主线程收到退出消息
{
m_nSubState = 1;//子线程先退出
LOGD("子线程退出了");
m_pIAndroidUserItem->KillGameTimer(IDI_FIRE);//SetGameTimer(IDI_FIRE);
t1.~thread();
break;
}
else
{
if (RepositionState)//机器人中途离开
{
RepositionSubState = true;
LOGD("机器人中途离开,子线程退出了");
m_pIAndroidUserItem->KillGameTimer(IDI_FIRE);
return;
}
GameObject::setFrameDuration(TIME_SCHEDULE_UPDATE); //设置鱼和子弹移动的间隔时间 0.01666667
if (isState(STATE_TACTIC)) { //按顺序的
Fishes::updateDurationTime();
}
getNewBulletList(allBullets); //得到现在最新的子弹
getAllFishes(allFishes); //得到现在所生成的鱼
if (pause_count < pause_n)
{
pause_count++; //打到暂停了
}
else
{
UpdateFish(); //更新鱼的位置,同时移除跑出屏幕外边的鱼
}
UpdateBullet(); //更新子弹的位置,并检测和鱼的碰撞,并且移除碰到鱼的子弹,子弹打中鱼给服务器发消息
//RemoveBullet();
checkQueue(); //处理队列
RemoveFish(); //从所有鱼中删除打死的鱼
Sleep(TIME_SCHEDULE_UPDATE * 1000); //每隔0.016667s休眠一次线程
}
}
}
//获取角度
float CAndroidUserItemSink::getAngel(float x, float y)
{
//这种情况下是炮台在屏幕的上方
if (x > 0)
{
if (y > 0)
{
//第一象限
//return CC_RADIANS_TO_DEGREES(atan(x / y));
//LOGD("第一象限");
return CC_RADIANS_TO_DEGREES(atan(x / y));
}
else
{
//第四象限
//LOGD("第四象限");
return CC_RADIANS_TO_DEGREES(atan(x / y)) + 180;
//return CC_RADIANS_TO_DEGREES(atan(x / y)) + 360;
}
}
else if (x<0)
{
if (y > 0)
{
//第二象限
//LOGD("第二象限");
return CC_RADIANS_TO_DEGREES(atan(x / y)) + 180;
}
else
{
//第三象限
//LOGD("第三象限");
return CC_RADIANS_TO_DEGREES(atan(x / y));
//return CC_RADIANS_TO_DEGREES(atan(x / y))+180;
}
}
else
{
//x=0
return y>0 ? 90 : 270;
}
}
void CAndroidUserItemSink::Collision(BULLET g1, FISH g2)//每个子弹和任何一个鱼先判断一遍
{
return;
}
//获取炮台的位置,来判断该炮台在屏幕底下还是在屏幕上边
int CAndroidUserItemSink::getCannonID(int chairID) {
int ID = chairID;
if (isUpsideEx) {
if (ID >= GAME_PLAYER / 2)
ID -= GAME_PLAYER / 2;
else
ID += GAME_PLAYER / 2;
}
return ID;
}
//获取从服务器返回的该删除的鱼放进waitRemoveFishEx链表中
void CAndroidUserItemSink::onHurt(shared_ptr<Fishes> fi, int hurt)
{
if (hurt == 1) {
int targetCannonID = fi.get()->targetChairID;
/*if (instance->isUpside) {
targetCannonID = instance->getCannonID(targetCannonID);
}*/
int ex_ratio = 1;
if (fi.get()->fish_style == STYLE_NIL) {
if (fi.get()->fish_type > 15) {
//fi.get()->setSign(true);
}
if (fi.get()->fish_type < 16) {
//fi.get()->setSign(true);
}
if (fi.get()->fish_type > 20) {
fi.get()->setSign(true);
if (fi.get()->fish_type == 22) {
}
}
else {
fi.get()->setSign(true);
}
}
else if (fi.get()->fish_style ==STYLE_PAUSE) {
//当机器人和客户端打到暂停的鱼了,然后界面暂停了,这时候机器人不能再每一帧更新鱼的位置,所以机器人和客户端打到暂停的鱼时,
//需要向服务器发送消息,让服务器通知其他机器人,当机器人收到消息之后再做操作。
pause_count = 0;
//waitRemoveFishEx.push_back(fi);
//CMD_C_PAUSE Pause;
//Pause.wChairID = m_RobotID;
//m_pIAndroidUserItem->SendSocketData(SUB_C_PAUSE, &Pause, sizeof(CMD_C_PAUSE));
}
else if (fi.get()->fish_style ==STYLE_TEAM) {
fi.get()->setSign(true);
}
else if (fi.get()->fish_style == STYLE_SAME) {
fi.get()->setSign(true);
}
else if (fi.get()->fish_style == STYLE_ANY) {
if (fi.get()->fish_type > 20) {
fi.get()->setSign(true);
}
else {
fi.get()->setSign(true);
}
}
}
else {
fi.get()->hurt_count = 12;
}
}
//复制一份删除鱼的链表
void CAndroidUserItemSink::copyRemovefish(FISHES & f)
{
mutexWaitRemoveFish.lock();
f.splice(f.end(), waitRemoveFishEx, waitRemoveFishEx.begin(), waitRemoveFishEx.end());//保存一下从服务器发过来的要删除的鱼,加上锁
mutexWaitRemoveFish.unlock();
}
//删除鱼
void CAndroidUserItemSink::RemoveFish()
{
//if (!copyWaitRemoveFishEx.empty())
//{
// std::list<shared_ptr<Fishes>>::iterator it1 = copyWaitRemoveFishEx.begin();
// for (; it1 != copyWaitRemoveFishEx.end(); it1++)
// {
// (*it1).get()->setSign(true);//标记一下该鱼要删除了
// }
//}
//mutexDestructFish.lock();
int DeleteFishCount = 0;
std::list<shared_ptr<Fishes>>::iterator it = allFishes.begin();
for (; it != allFishes.end();)
{
if ((*it).get()->sign)
{
DeleteFishCount++;
it=allFishes.erase(it);//删除标记的鱼
}
else
{
it++;
}
}
//mutexDestructFish.unlock();
//LOGD("要删除鱼的数量:" << DeleteFishCount);
return;
}
//删除子弹
void CAndroidUserItemSink::RemoveBullet()
{
if (!allBullets.empty())
{
std::list<std::shared_ptr<Bullet>>::iterator iter1 = allBullets.begin();
for (; iter1 != allBullets.end();)
{
if (iter1->get()->deleteSign)
{
LOGD("删除子弹");
iter1 = allBullets.erase(iter1);
}
else
{
iter1++;
}
}
}
}
//是否暂停,暂停不更新鱼的位置
bool CAndroidUserItemSink::isOnPause()
{
return pause_count<pause_n;
}
//创建鱼的一些操作
Fishes * CAndroidUserItemSink::createFish(float x, float y, float angle, int Fishes_style, int Fishes_type, int server_ID)
{
//LOGD("创建鱼");
std::shared_ptr<Fishes> fish = std::shared_ptr<Fishes>(new Fishes(fishCount++));
mutexCreateFishes.lock();
fish->setFish(x, y, angle, Fishes_style, Fishes_type, server_ID);
createShareFishes.push_back(fish);
if (!isOnPause())
{
if (!createShareFishes.empty())
{
std::list<shared_ptr<Fishes>>::iterator it = createShareFishes.begin();
for (; it != createShareFishes.end(); it++)
{
if ((*it).get())
{
(*it).get()->update();//创建鱼的同时赋予初始位置
}
}
}
}
mutexCreateFishes.unlock();
//LOGD("创建鱼成功");
return fish.get();
}
//创建鱼
Fishes * CAndroidUserItemSink::createFish(float x, float y, float angle, int Fishes_type, int server_ID)
{
return createFish(x, y, angle, STYLE_NIL, Fishes_type, server_ID);
}
//获取最新的鱼的列表
void CAndroidUserItemSink::getAllFishes(std::list<shared_ptr<Fishes>> &fi)
{
mutexCreateFishes.lock();
//LOGD("allFish.size(): " << allFishes.size() << " createShareFishes.size():" << createShareFishes.size());
if (fi.empty())
{
fi.splice(fi.begin(), createShareFishes, createShareFishes.begin(), createShareFishes.end());//得到现在创建的所有鱼
}
else
{
fi.splice(fi.end(), createShareFishes, createShareFishes.begin(), createShareFishes.end());
}
mutexCreateFishes.unlock();
}
//创建子弹的一些操作
Bullet* CAndroidUserItemSink::createBullet(float x, float y, float angle, float speed, float vx_ex, float vy_ex, int from_type, int bullet_type)
{
std::shared_ptr<Bullet> bullet = std::shared_ptr<Bullet>(new Bullet(bulletCount++));
mutexCreateBullet.lock();
bullet->setBullet(x, y, angle, speed, vx_ex, vy_ex, from_type, bullet_type);
createShareBullets.push_back(bullet);//刚创建的子弹放到链表createShareBullets中
if (createShareBullets.size()>0)
{
std::list<std::shared_ptr<Bullet>>::iterator it = createShareBullets.begin();
for (; it != createShareBullets.end(); it++)
{
if ((*it).get())
{
//LOGD("CreateBullet bullet_ID:" << (*it).get()->bullet_ID << " x:" << (*it).get()->x << /*" vx: " << (*it).get()->vx << " vy: " << (*it).get()->vy<<*/ " y:" << (*it).get()->y<<" angle: "<<(*it).get()->angle);
(*it).get()->update();
//LOGD("CreateBullet bullet_ID:" << (*it).get()->bullet_ID << " x:" << (*it).get()->x << /*" vx: " << (*it).get()->vx << " vy: " << (*it).get()->vy<<*/ " y:" << (*it).get()->y<<" angle: "<<(*it).get()->angle);
}
}
}
mutexCreateBullet.unlock();
return bullet.get();
}
//创建子弹
Bullet* CAndroidUserItemSink::createBullet(float x, float y, float angle, float speed, int from_type, int bullet_type)
{
return createBullet(x, y, angle, speed, 0, 0, from_type, bullet_type);
}
//获取最新的子弹的列表
void CAndroidUserItemSink::getNewBulletList(list<shared_ptr<Bullet>> & newBullet)
{
mutexCreateBullet.lock();
if (newBullet.size() == 0)
{
newBullet.splice(newBullet.begin(), createShareBullets, createShareBullets.begin(), createShareBullets.end());//复制创建的鱼的链表到最新的子弹链表中,然后清空创建鱼的链表
}
else
{
newBullet.splice(newBullet.end(), createShareBullets, createShareBullets.begin(), createShareBullets.end());
}
mutexCreateBullet.unlock();
}
//鱼的更新位置,没用到
void CAndroidUserItemSink::fishUpdate(Fishes *f)
{
//if (isState(STATE_RUN))
//{
//instance->isState(CAndroidUserItemSink::STATE_TACTIC);
if (isState(CAndroidUserItemSink::STATE_TACTIC)) {
fishUpdateTactic(f);
//LOGD("UpdateTacticMoveFish: fish_ID: " << fish_ID << " x: " << x << " y: " << y << " angle: " << angle);
}
else
{
if (!(pause_count<pause_n))//界面暂停
{
if (f->runMode == RUN_MODE_LINE) {
f->moveT();
//LOGD("MoveTMoveFish: fish_ID: " << fish_ID << " x: " << x << " y: " << y << " angle: " << angle);
}
else {
/*if (Tools::isLineExceedValue(f->x, f->y, curvePos[curveIndex].x, curvePos[curveIndex].y, f->speed)) {
float x_distance =f->x - curvePos[curveIndex].x;
float y_distance =f->y - curvePos[curveIndex].y;
float step = sqrt(x_distance*x_distance + y_distance*y_distance) / f->speed;
float ter_angle = Tools::getAngle(curvePos[curveIndex].x - f->x, curvePos[curveIndex].y -f->y);
float offset_angle = ter_angle - f->angle;
if (offset_angle > 180) {
offset_angle = -(360 - offset_angle);
}
else if (offset_angle < -180) {
offset_angle = 360 + offset_angle;
}
f->angle_v = offset_angle / step * 2;
}
else {
f->angle_v = 0;
curveIndex++;
if (curveIndex > 2) {
f->setRunMode(RUN_MODE_LINE);
}
}
f->moveAngleT();*/
}
}
else { /*LOGD("!!!!!更新时暂停了*/ }
}
if (f->fish_style == STYLE_TEAM || f->fish_style == STYLE_SAME) {
f->angle += 2;
}
if (!Tools::isGameObjectCollision(f, f->x - 1400, f->x + winSize.width + 1400, f->y + winSize.height + 1400, f->y - 1400)) {
}
else {
if (f->hurt_count > 0) {
if (f->hurt_count > 1) {
}
else {
}
f->hurt_count--;
}
}
//}
//else if (isState(STATE_EXPLODE))
//{
//if (getAnima()->isOver()){
// onClear();
//}
//else if (target != NULL){
// //x = target->x+target_offset_w;
// //y = target->y+target_offset_h;
//}
//}
//count++;
}
//更新鱼的位置,没用到
void CAndroidUserItemSink::fishUpdateTactic(Fishes *f)
{
f->tactic_duration_buffer = f->tactic_duration;
f->phase = 0;
f->x = f->buffer_x;
f->y = f->buffer_y;
f->angle = f->buffer_angle;
while (f->phase < 6) {
if (f->fishAction[f->phase].actionID == ACTION_HIDE) {
if (f->tactic_duration_buffer >= f->fishAction[f->phase].time) {
//setVisible(true);
//shadow->setVisible(true);
f->tactic_duration_buffer -=f-> fishAction[f->phase].time;
}
else {
break;
}
}
else if (f->fishAction[f->phase].actionID == ACTION_RUN_LINE) {
if (f->tactic_duration_buffer >= f->fishAction[f->phase].time) {
f->moveT(f->fishAction[f->phase].time);
f->tactic_duration_buffer -= f->fishAction[f->phase].time;
}
else {
f->moveT(f->tactic_duration_buffer);
break;
}
}
else if (f->fishAction[f->phase].actionID == ACTION_RUN_ROUND) {
if (f->tactic_duration_buffer >= f->fishAction[f->phase].time) {
f->angle += f->angle_v*f->fishAction[f->phase].time;
f->angle = fmod(f->angle + 360, 360);
f->tactic_duration_buffer -= f->fishAction[f->phase].time;
f->x += Tools::getAngleX(f->angle, f->buffer_r);
f->y += Tools::getAngleY(f->angle, f->buffer_r);
f->angle = fmod(f->angle + 90, 360);
//if (instance->isUpside) {
if (isUpside)
{
f->angle += 180;
f->angle = fmod(f->angle, 360);
f->x = winSize.width - f->x;
f->y = winSize.height- f->y;
}
f->setSpeed(2 * f->buffer_r*3.14159f*f->angle_v / 360 * 1.3f, f->angle, true);
//setSpeed(200, angle, true);
}
else {
f->angle += f->angle_v*f->tactic_duration_buffer;
f->angle = fmod(f->angle + 360, 360);
f->x += Tools::getAngleX(f->angle, f->buffer_r);
f->y += Tools::getAngleY(f->angle, f->buffer_r);
f->angle = fmod(f->angle + 90, 360);
//if (instance->isUpside) {
if (isUpside)
{
f->angle += 180;
f->angle = fmod(f->angle, 360);
f->x = winSize.width - f->x;
f->y = winSize.height -f->y;
}
break;
}
}
else if (f->fishAction[f->phase].actionID == ACTION_ROTATE) {
if (f->tactic_duration_buffer >= f->fishAction[f->phase].time) {
f->angle += f->angle_v*f->fishAction[f->phase].time;
f->angle = fmod(f->angle + 360, 360);
f->tactic_duration_buffer -= f->fishAction[f->phase].time;
f->setSpeed(180, f->angle, true);
}
else {
f->angle += f->angle_v*f->tactic_duration_buffer;
f->angle = fmod(f->angle + 360, 360);
break;
}
}
else if (f->fishAction[f->phase].actionID == ACTION_WAIT) {
if (f->tactic_duration_buffer >= f->fishAction[f->phase].time) {
f->tactic_duration_buffer -= f->fishAction[f->phase].time;
if (tacticID == 2) {
if (f->phase == 0) {
int vy = (winSize.height / 5 + 100) / f->fishAction[f->phase + 1].time;
//if (instance->isUpside) {
if (isUpside)
{
f->vy = -vy;
}
if (f->fish_type == 1) {
f->setV_xy(0, -vy);
}
else if (f->fish_type == 2) {
f->setV_xy(0, vy);
}
}
else {
int vy = (winSize.height * 4 / 5 + 100) / f->fishAction[f->phase + 1].time;
//if (instance->isUpside) {
if (isUpside)
{
f->vy = -vy;
}
if (f->fish_type == 1) {
f->setV_xy(0, -vy);
}
else if (f->fish_type == 2) {
f->setV_xy(0, vy);
}
}
}
}
else {
break;
}
}
else if (f->fishAction[f->phase].actionID == ACTION_CLEAR) {
//onClear();
break;
}
else {
//onClear();
break;
}
f->phase++;
}
}
//获取炮台的坐标
void CAndroidUserItemSink::setCannonPosition(int type, int gap, int w)
{
if (type == TYPE_NORMAL) {
m_positionX = gap / 2 + w / GAME_PLAYER + (m_RobotID*(w / (GAME_PLAYER / 2)));
m_positionY = 0;
}
else {
m_positionX = gap / 2 + w / GAME_PLAYER + ((GAME_PLAYER - m_RobotID - 1)*(w / (GAME_PLAYER / 2)));
m_positionY = winSize.height;
}
}
//获取机器人所在炮台的属性
void CAndroidUserItemSink::getCanAttri(int chairID)
{
m_isSuper = cannon->isSuper;
m_GunNum = cannon->cannon_gunNum;
}
//设置主线程的状态
void CAndroidUserItemSink::setMainState(int main)
{
m_nMainState = main;
}
//获取子线程的状态,等游戏结束的时候先保证关闭子线程,再退出主线程
int CAndroidUserItemSink::getSubState()
{
return m_nSubState;
}
//处理接收到的打中鱼的消息
bool CAndroidUserItemSink::getMessage(shared_ptr<ReceiveMsg> &msg)
{
std::lock_guard<std::mutex> lk( m_mutexTSMsg);
/*switch (msg->wSubCmdID)
{
case SUB_S_CAST_NET_SUCCESS:
{
CMD_S_Cast_Net_Success_dte * S_Cast_Net_Success_dte = (CMD_S_Cast_Net_Success_dte *)(msg->cbDataBuffer);
// if (S_Cast_Net_Success_dte->wChairID != m_RobotID) return true;
}
break;
case SUB_S_HIT_TEAM_SUCCESS:
{
CMD_S_HitTeam_Success_dte* S_HitTeam_Success_dte = (CMD_S_HitTeam_Success_dte*)(msg->cbDataBuffer);
//if (S_HitTeam_Success_dte->wChairID != m_RobotID) return true;
}
break;
case SUB_S_TYPE_BOMB_SUCCESS:
{
CMD_S_TypeBomb_Success_dte* S_TypeBomb_Success_dte = (CMD_S_TypeBomb_Success_dte*)(msg->cbDataBuffer);
// if (S_TypeBomb_Success_dte->wChairID != m_RobotID) return true;
}
break;
}*/
if (msg->wSubCmdID == SUB_S_CHANGE_SCENE)
{
LOGD("服务器发过来_SUB_S_CHANGE_SCENE_改变场景");
//allBullets.clear();
}
//m_listRemoveFishMessage.push_back(msg);
//LOGD("allBullet.size():" << allBullets.size());
RemoveFiMsg.push_back(msg);
return true;
}
//网成功
bool CAndroidUserItemSink::OnNetSuccess(CMD_S_Cast_Net_Success_dte*pData)
{
CMD_S_Cast_Net_Success_dte * S_Cast_Net_Success_dte = (CMD_S_Cast_Net_Success_dte *)pData;
//int a = wDataSize;
//int b = sizeof(CMD_S_Cast_Net_Success_dte) - (MAX_FISH_IN_CUCESS - S_Cast_Net_Success_dte->cbCount)*sizeof(CMD_C_Fish_Net_Object);
int ID = S_Cast_Net_Success_dte->wChairID;
if (ID != m_RobotID)
{
return true;
}
fishPlayer[ID].lFishGold = S_Cast_Net_Success_dte->lPlayerScore;
//if (currentFish->hasFlag(Fish::FLAG_UPDATE) && !currentFish->isState(Fish::STATE_EXPLODE)) {
// if (currentFish->server_ID == S_Cast_Net_Success_dte->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
// currentFish->targetChairID = S_Cast_Net_Success_dte->wChairID;
// currentFish->getPauseChairID(ID);
// currentFish->onHurt(1);
// if (currentFish->fish_type>15) {
// needGoldPlate = true;
// }
// break;
// }
//}
bool needGoldPlate = false;
for (int i = 0; i<S_Cast_Net_Success_dte->cbCount; i++) {
if (!allFishes.empty())
{
FISHES::iterator it = allFishes.begin();
for (; it != allFishes.end(); it++)
{
if ((*it).get() /*&& (*it).get()->hasFlag(Fishes::FLAG_UPDATE) && !(*it).get()->isState(Fishes::STATE_EXPLODE)*/) {
if ((*it).get()->server_ID == S_Cast_Net_Success_dte->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
(*it).get()->targetChairID = S_Cast_Net_Success_dte->wChairID;
onHurt((*it), 1);
break;
}
}
}
}
}
return true;
}
//炸弹打中
bool CAndroidUserItemSink::OnBoomSuccess(CMD_S_TypeBomb_Success_dte* pData)
{
//LOGD("炸弹成功OnBoomSuccess");
const CMD_S_TypeBomb_Success_dte* S_TypeBomb_Success_dte = (CMD_S_TypeBomb_Success_dte*)pData;
int ID = S_TypeBomb_Success_dte->wChairID;
if (ID != m_RobotID) return true;
fishPlayer[ID].lFishGold += S_TypeBomb_Success_dte->lPlayerAddScore;
for (int i = 0; i<S_TypeBomb_Success_dte->cbCount; i++)
{
if (!allFishes.empty())
{
FISHES::iterator it = allFishes.begin();
for (; it != allFishes.end(); it++)
{
if ((*it).get()/*&&(*it)->hasFlag(Fishes::FLAG_UPDATE) && !(*it)->isState(Fishes::STATE_EXPLODE)*/) {
if ((*it).get()->server_ID == S_TypeBomb_Success_dte->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
(*it).get()->targetChairID = S_TypeBomb_Success_dte->wChairID;
//(*it)->onHurt(1)
onHurt((*it), 1);
break;
}
}
}
}
}
return true;
}
//击中小组
bool CAndroidUserItemSink::OnTeamSuccess(CMD_S_HitTeam_Success_dte* pData)
{
//LOGD("小队成功OnTeamSuccess");
const CMD_S_HitTeam_Success_dte* S_HitTeam_Success_dte = (CMD_S_HitTeam_Success_dte*)pData;
// a = wDataSize;
//int b = sizeof(CMD_S_HitTeam_Success_dte) - (MAX_FISH_IN_TEAM - S_HitTeam_Success_dte->cbCount)*sizeof(CMD_C_Fish_Net_Object);
int ID = S_HitTeam_Success_dte->wChairID;
if (ID != m_RobotID)
{
return true;
}
fishPlayer[ID].lFishGold += S_HitTeam_Success_dte->lPlayerAddScore;
for (int i = 0; i<S_HitTeam_Success_dte->cbCount; i++) {
if (!allFishes.empty())
{
FISHES::iterator it = allFishes.begin();
for (; it != allFishes.end(); it++)
{
if ((*it).get()/*&&(*it)->hasFlag(Fishes::FLAG_UPDATE) && !(*it)->isState(Fishes::STATE_EXPLODE)*/) {
if ((*it).get()->server_ID == S_HitTeam_Success_dte->FishNetIDs[i].wID) {//&& currentFish->fish_type==S_Cast_Net_Success_dte->FishNetIDs[i].cbType
(*it).get()->targetChairID = S_HitTeam_Success_dte->wChairID;
//(*it)->onHurt(1);
onHurt((*it), 1);
break;
}
}
}
}
}
return true;
}
//改变场景
void CAndroidUserItemSink::changeScene(short ID)
{
/*Fish* currentFish = Fish::headDrawFish;
while (currentFish != NULL) {
GameObject* tem = currentFish->nextDrawGameObject;
if (currentFish->hasFlag(Fish::FLAG_UPDATE) && !currentFish->isState(Fish::STATE_EXPLODE)) {
currentFish->setRunMode(Fish::RUN_MODE_LINE);
currentFish->setSpeed(currentFish->speed * 2, currentFish->angle);
}
currentFish = (Fish*)tem;
}*/
//LOGD("改变场景changeScene");
if (!allFishes.empty())
{
std::list<shared_ptr<Fishes>>::iterator it = allFishes.begin();
for (; it != allFishes.end(); it++)
{
if ((*it).get()->hasFlag(Fishes::FLAG_UPDATE) && (*it).get()->isState(Fishes::FLAG_UPDATE))
{
(*it).get()->setRunMode(Fishes::RUN_MODE_LINE);
(*it).get()->setSpeed((*it).get()->speed * 2, (*it).get()->angle);
}
}
}
}
//检测队列
void CAndroidUserItemSink::checkQueue()
{
//检测队列
m_mutexTSMsg.lock();
if (0 == RemoveFiMsg.size())
{
m_mutexTSMsg.unlock();
return;
}
std::list<shared_ptr<ReceiveMsg>> messages;
while (!RemoveFiMsg.empty())
{
//LOGD("m_listRemoveFishMessage不为空");
messages.push_back(RemoveFiMsg.front());
RemoveFiMsg.pop_front();
}
m_mutexTSMsg.unlock();
while (!messages.empty())
{
std::list<shared_ptr<ReceiveMsg>>::iterator it = messages.begin();
switch ((*it).get()->wSubCmdID)
{
case SUB_S_CAST_NET_SUCCESS:
{
CMD_S_Cast_Net_Success_dte * netsuccess = (CMD_S_Cast_Net_Success_dte *)((*it)->cbDataBuffer);
OnNetSuccess(netsuccess);
}
break;
case SUB_S_HIT_TEAM_SUCCESS:
{
CMD_S_HitTeam_Success_dte* S_HitTeam_Success_dte = (CMD_S_HitTeam_Success_dte*)((*it)->cbDataBuffer);
OnTeamSuccess(S_HitTeam_Success_dte);
}
break;
case SUB_S_TYPE_BOMB_SUCCESS:
{
CMD_S_TypeBomb_Success_dte* S_TypeBomb_Success_dte = (CMD_S_TypeBomb_Success_dte*)((*it)->cbDataBuffer);
OnBoomSuccess(S_TypeBomb_Success_dte);
}
break;
case SUB_S_CHANGE_SCENE:
{
CMD_S_Change_Scene * S_Change_Scene = (CMD_S_Change_Scene *)((*it)->cbDataBuffer);
changeScene(S_Change_Scene->cbScene);
}
break;
/*case SUB_IDI_FIRE:
{
Fire();
}
break;*/
default:
break;
}
messages.erase(it);
}
//LOGD("checkQueue中messages.size()="<<messages.size());
//for (auto msg : messages)
//{
// //LOGD("循环messages");
// if (msg == nullptr) continue;
// switch (msg.get()->wSubCmdID)
// {
// case SUB_S_CAST_NET_SUCCESS:
// {
// CMD_S_Cast_Net_Success_dte * netsuccess = (CMD_S_Cast_Net_Success_dte *)(msg->cbDataBuffer);
// OnNetSuccess(netsuccess);
// }
// break;
// case SUB_S_HIT_TEAM_SUCCESS:
// {
// CMD_S_HitTeam_Success_dte* S_HitTeam_Success_dte = (CMD_S_HitTeam_Success_dte*)(msg->cbDataBuffer);
// OnTeamSuccess(S_HitTeam_Success_dte);
// }
// break;
// case SUB_S_TYPE_BOMB_SUCCESS:
// {
// CMD_S_TypeBomb_Success_dte* S_TypeBomb_Success_dte = (CMD_S_TypeBomb_Success_dte*)(msg->cbDataBuffer);
// OnBoomSuccess(S_TypeBomb_Success_dte);
// }
// break;
// case SUB_S_CHANGE_SCENE:
// {
// CMD_S_Change_Scene * S_Change_Scene = (CMD_S_Change_Scene *)(msg->cbDataBuffer);
// changeScene(S_Change_Scene->cbScene);
// }
// break;
// default:
// break;
// }
// //delete msg;
// // msg = nullptr;
//}
}
//打印鱼和子弹size大小
void CAndroidUserItemSink::LogSize()
{
//LOGD("fishList.size()=" << allFishes.size() << " BulletList.size()=" << allBullets.size() << " RemoveFiMsg.size()=" << RemoveFiMsg.size());
}
void CAndroidUserItemSink::fireBullet()
{
if (cannon->needFire_num > 0)
{
if (cannon->needFire_count <= 0)
{
cannon->needFire_num--;
cannon->needFire_count = 8;
shoot();
}
}
if (cannon->needFire_count>0)
{
cannon->needFire_count--;
}
}
void CAndroidUserItemSink::shoot()
{
if (fishPlayer[m_RobotID].lFishGold > fishGold)
{
CMD_C_Fire fire;
WORD wChairID = m_pIAndroidUserItem->GetChairID();
if (m_positionY>0)//炮台在屏幕的上边
{
//x = rand() % 1000;
x = rand() % 800;
y = 0;
angle = getAngel(x - m_positionX, y - m_positionY);
}
else
{
//x = rand() % 1000 + 140;
//y = 360;
x = rand() % 1000;
y = 500;
angle = Tools::getAngle(x - m_positionX, y - m_positionY);
if (angle > 180) {
if (angle < 270) {
angle = 180;
}
else {
angle = 0;
}
}
}
//}
fire.fRote = angle;
{
{
if (fishPlayer[m_RobotID].lFishGold > 0)
{
m_pIAndroidUserItem->SendSocketData(SUB_C_FIRE, &fire, sizeof(CMD_C_Fire));
CreateBullets(1);
fishPlayer[m_RobotID].lFishGold -= fishGold;
if(cannon->needFire_num<20) {
cannon->needFire_num++;
}
}
}
}
}
else if (fishPlayer[m_RobotID].lFishGold != 0 && (rand() % 10)>3)
{
ChangeCannon();
}
else
{
/// 购买子弹
BuyBullet();
LOGD("钱不够的时候,购买子弹");
}
}
//////////////////////////////////////////////////////////////////////////