Exemple #1
0
void Level::updateLeaves(float dt) {
    GameModel* gameModel = GameModel::getInstance();
    for (auto iter = this->drowningLeaves->begin(); iter != this->drowningLeaves->end(); iter++) {
        Leaf* drowningLeaf = (Leaf*) *iter;
        if (drowningLeaf->getDrowning()) {
            if (drowningLeaf->getCurrentDrownDuration() != -1) {
                drowningLeaf->setCurrentDrownDuration(drowningLeaf->getCurrentDrownDuration() - dt);
                if (drowningLeaf->getCurrentDrownDuration() < 0) {
                    drowningLeaf->setCurrentDrownDuration(-1);
                    
                    DataEvent* dataEvent = new DataEvent();
                    dataEvent->setEventCode(EVT_LEAF_DROWN);
                    dataEvent->setArgumentReference(drowningLeaf);
                    gameModel->fireEvent(dataEvent);
                    
                    this->leaves->removeObjectForKey(drowningLeaf->getPositionIndex());
                    this->drowningLeaves->eraseObject(drowningLeaf);
                    
                    if (this->leaves->count() == 1) {
                        this->done = true;
                    }
                    break;
                }
            }
            drowningLeaf->play(SPRITE_TYPE_MAIN, FRAME_LEAF_FALL);
        }
    }
}
Exemple #2
0
bool InBandStream::event(QEvent *AEvent)
{
	if (AEvent->type() == DataEvent::registeredType())
	{
		DataEvent *dataEvent = static_cast<DataEvent *>(AEvent);
		sendNextPaket(dataEvent->isFlush());
		return true;
	}
	return QIODevice::event(AEvent);
}
Exemple #3
0
void ChapterScene::onTouchEnded(Touch* touch, Event* event) {
    GameModel* gameModel = GameModel::getInstance();
    this->updatePageAuto();
    
    Point point = this->convertTouchToNodeSpace(touch);
    bool moveTooFar = false;
    float dx = point.x - this->firstPoint.x;
    float dy = point.y - this->firstPoint.y;
    if (abs(dx) > CONF_TOUCH_RANGE || abs(dy) > CONF_TOUCH_RANGE) {
        moveTooFar = true;
    }
    point = point - this->chapterLayer->getPosition();
    
    for (int i = 0; i < this->chapterLayer->getChildren().size(); i++) {
        Face* chapterFace = dynamic_cast<Face*>(this->chapterLayer->getChildren().at(i));
        if (chapterFace != NULL) {
            RectBody* chapterBody = new RectBody(chapterFace->getContentSize().width, chapterFace->getContentSize().height);
            chapterBody->setPosition(chapterFace->getPosition());
            
            if (chapterBody->contains(point)) {
                if (!moveTooFar && chapterFace->getTag() != -1) {
                    if (!gameModel->checkLevelRequireSocial(i + 1)) {
                        this->shareLayer->show(TXT_REQUIRE_SHARE);
                        GameEvent* gameEvent = new GameEvent();
                        gameEvent->setEventCode(EVT_SHOW_SHARE_REQUIRED);
                        this->fireEvent(gameEvent);
                    } else {
                        DataEvent* gameEvent = new DataEvent();
                        gameEvent->setEventCode(EVT_START_PLAY);
                        gameEvent->setArgumentInt(chapterFace->getTag());
                        this->fireEvent(gameEvent);
                        
                        this->_eventDispatcher->removeEventListener(this->touchListener);
                    }
                }
                this->flash(chapterFace);
                break;
            }
        }
    }
}
bool Square::setLoad(bool enabled)
{
	load=enabled;
	if(load){
		return true;
	}
	else if(blank.isEmpty()){
		return false;
	}
	else{
		DataEvent e;
		QHash<QString,QByteArray> h;
		for(BitType t:blank){
			h.insert(QString("T:%1").arg(t),QByteArray());
		}
		e.setData(h);
		Share::sendEvent(e);
		blank.clear();
		return true;
	}
}
Exemple #5
0
void LevelScene::onTouchEnded(Touch* touch, Event* event) {
    if (this->dialogLayer->isVisible()) {
        return;
    }
    
    this->updatePageAuto();
    
    Point point = this->convertTouchToNodeSpace(touch);
    bool moveTooFar = false;
    float dx = point.x - this->firstPoint.x;
    float dy = point.y - this->firstPoint.y;
    if (abs(dx) > CONF_TOUCH_RANGE || abs(dy) > CONF_TOUCH_RANGE) {
        moveTooFar = true;
    }
    point = point - this->levelLayer->getPosition();
    
    for (int i = 0; i < this->levelLayer->getChildren().size(); i++) {
        CSprite* levelFace = dynamic_cast<CSprite*>(this->levelLayer->getChildren().at(i));
        if (levelFace != NULL) {
            RectBody* levelBody = new RectBody(levelFace->getContentSize().width, levelFace->getContentSize().height);
            levelBody->setPosition(levelFace->getPosition());
            
            if (levelBody->contains(point)) {
                if (!moveTooFar && levelFace->getTag() != -1) {
                    DataEvent* gameEvent = new DataEvent();
                    gameEvent->setEventCode(EVT_START_LEVEL);
                    gameEvent->setArgumentInt(levelFace->getTag());
                    this->fireEvent(gameEvent);
                    
                    this->_eventDispatcher->removeEventListener(this->touchListener);
                }
                break;
            }
        }
    }
}
void Handler::DataEventHandle(const DataEvent &event,const QHostAddress &address)
{
	qDebug()<<"Get DataEvent";
	QSqlQuery query;
	QHash<QString,QByteArray> data=event.getData();
	int flag=!data.isEmpty();
	for(QString item:data.keys()){
		if(item.startsWith("T:")){
			query.prepare("SELECT Info,Texture FROM Bit WHERE Type=?");
			query.addBindValue(item.mid(2).toInt());
			query.exec();
			if(query.first()){
				QDataStream s(&data[item],QIODevice::WriteOnly);
				QDataStream r(query.value("Info").toByteArray());
				QString n,d;
				r>>n>>d;
				s<<n<<d<<query.value("Texture").toByteArray();
			}
			else{