Esempio n. 1
0
//met à jour la position du hero
void CSatan::update(float elapsedTime)
{
	boost::shared_ptr<IEntity> deadHero(m_deadHero.lock());
	if(m_isDead || !deadHero)
		return;

	if(m_isTracking)
	{
		sf::Vector2f coord = getCoord();
		float move = -elapsedTime*m_speed;
		if(coord.y + move <= deadHero->getCoord().y-50)
		{
			deadHero->getModel()->setActive(false);
			m_isTracking = false;
			move = deadHero->getCoord().y - coord.y;
			m_satanModel->setAnim("Hurt");
			m_satanModel->setActiveHero(true);
		}

		setCoord(sf::Vector2f(coord.x, coord.y + move));
		m_satanModel->SetPosition(getCoord());
	}
	else
	{
		float x = getCoord().x;
		float move = elapsedTime*m_speed;
		sf::FloatRect screenRect = CGameEngine::instance()->getScreenRect();

		if(x+move >= screenRect.Right - getDim().x - 50)
		{
			move = screenRect.Right - getDim().x - 50 - x;
			m_speed *= -1.f;
		}
		else if(x+move <= screenRect.Left + 50)
		{
			move = screenRect.Left + 50 - x;
			m_speed *= -1.f;
		}

		float y = CGameEngine::instance()->getScreenRect().Bottom - getDim().y - 50;
		float verMove = y -getCoord().y;

		std::vector<IEntity::SCollisionInfo> collisionResultVec = testVerticalCollision(verMove);
		foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec)
		{
			onTouch(collisionInfo.otherEntity);
		}

		collisionResultVec.clear();
		collisionResultVec = testHorizontalCollision(move);
		foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec)
		{
			onTouch(collisionInfo.otherEntity);
		}
void TouchManager::onTouchMoved(const Touch* touch, const Event* event) {
  if (onTouch == nullptr) {
    return;
  }

  auto location = touch->getLocation();
  onTouch(location);
}
Esempio n. 3
0
void Button::handleTouchRelease(QVector2D pos)
{
    if(m_isHolding)
    {
        this->setTexture(m_textureNormal);
        m_isHolding = false;
        if(onTouch)onTouch();
    }
}
bool TouchManager::onTouchBegan(const Touch* touch, const Event* event) {
  if (onTouch == nullptr) {
    return true;
  }

  auto location = touch->getLocation();
  onTouch(location);
  return true;
}
Esempio n. 5
0
//Avance la boule de feu
void CFireBall::update(float timeElapsed)
{
	sf::Vector2f coord = getCoord();
	float move = m_speed * timeElapsed;

	std::vector<IEntity::SCollisionInfo> collisionResultVec = testHorizontalCollision(move);
	foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec)
	{
		onTouch(collisionInfo.otherEntity);
	}
Esempio n. 6
0
void CDebris::update(float timeElapsed)
{
	m_speed.y = SPEED;
	sf::Vector2f coord = getCoord();
	sf::Vector2f move = m_speed;
	move *= timeElapsed;

	std::vector<IEntity::SCollisionInfo> collisionResultVec = testVerticalCollision(move.y);
	foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec)
	{
		onTouch(collisionInfo.otherEntity);
	}
Esempio n. 7
0
void TButton::Touch()
{  dbgprintln("TButton Touch");
  if (!active) return;
  uint16_t idleColor = Color;
  Color = Color&0xA514;  // clear 343 less bits of the 565 color
  if (CheckButton)
  {
      State = !State; // toggle
  }
  Draw();
  Color = idleColor;
  if (onTouch != NULL) onTouch();
}
Esempio n. 8
0
void GameScene::onEnter() {
    Layer::onEnter();
    
    getScheduler()->scheduleUpdate(this, -2, false);
    getScheduler()->scheduleUpdate(&mPostUpdater, 100, false);
    
    auto contactListener = EventListenerPhysicsContact::create();
    contactListener->onContactPreSolve = CC_CALLBACK_2(GameScene::onContactPreSolve, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
    
    auto listener1 = EventListenerTouchAllAtOnce::create();
    listener1->onTouchesBegan = [&](const std::vector<Touch*>& touches, Event* event){
        for(auto& t : touches) {
            onTouch(t->getLocation());
        }
    };
    listener1->onTouchesMoved = [&](const std::vector<Touch*>& touches, Event*){
        for(auto& t : touches) {
            onTouch(t->getLocation());
        }
    };
    listener1->onTouchesEnded = [&](const std::vector<Touch*>& touches, Event*){
        for(auto& t : touches) {
            onEndTouch(t->getLocation());
        }
    };
    listener1->onTouchesCancelled = [&](const std::vector<Touch*>& touches, Event*){
        for(auto& t : touches) {
            onEndTouch(t->getLocation());
        }
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
    
    runAction(Sequence::create(DelayTime::create(0.4), CallFunc::create([this]{
        mGame->enableGame(true, true);
    }),  NULL));
    
}
Esempio n. 9
0
bool UICenterBag::onTouch(int touchType,CCTouch* touch)
{
	CCPoint touchPoint = touch->getLocation();
	switch(touchType)
	{
		case TOUCH_DOWN:
		{
			if (nowTouch) return false;
			if (onTouch(touchType,touchPoint))
			{
				nowTouch = touch;
				return true;
			}
			return false;
		}break;
	}
	if (nowTouch != touch) return false;
	if (touchType == TOUCH_END)
	{
		nowTouch = NULL;
	}
	return onTouch(touchType,touchPoint);
}
Esempio n. 10
0
void MotionRecorder::track(std::vector<std::pair<double_t, double_t>> points)
{
	for (auto& m : m_motions)
	{
		if (points.empty())
			break;

		std::vector<int> distances;

		auto& base = m.points.back();
		std::transform(begin(points), end(points), std::back_inserter(distances), 
			[&base](const std::pair<double_t, double_t>& p)
			{
				auto diffx = p.first - base.first;
				auto diffy = p.second - base.second;
				//todo double_t statt int??
				return diffx * diffx + diffy * diffy;
			});

		auto min = std::min_element(begin(distances), end(distances));

		if (*min < 100)
		{
			auto minPoint = begin(points) + (min - begin(distances));

			m.currentTimestamp = m_timestamp;
			m.points.push_back(*minPoint);

			points.erase(minPoint);
		}
		else
		{
			onRelease(m);
		}
	}

	m_motions.resize(std::remove_if(begin(m_motions), end(m_motions), [this](const Motion& m){
		return this->m_timestamp != m.currentTimestamp;
	}) - begin(m_motions));

	std::transform(begin(points), end(points), std::back_inserter(m_motions), [this](const std::pair<double_t, double_t>& p){
		Motion m{ m_id++, m_timestamp, { p } };
		onTouch(m);
		return m;
	});

	++m_timestamp;
}
Esempio n. 11
0
/*
 * 	abcdefghijklmnopqrstuvwxyz
 *      e  hi klmno q  t u
 *      |  || ||||| |  | |
 *      |  || ||||| |  | +get screen (full res)
 *      |  || ||||| |  + touch(down,x,y)
 *      |  || ||||| +quit client
 *      |  || ||||+ftp_err
 *      |  || |||+ftp_data
 *      |  || ||+ftp_upload_req
 *      |  || |+ftp_download_req
 *      |  || +ftp_filelist_req
 *      |  |+get screen info
 *      |  +get screen (half req)
 *      +stop service
 */
static int ProcessClientMessage(svcInfoPtr psvc, FBCCMD* pmsg)
{
	//FBCCMD msg;
    //char msg;
    int n = 0;
    int nSize;

    //if( (n = ReadExact(psvc, (char*)&msg, FBCCMD_HEADER)) <= 0 ) {
    //    Err("ProcessClientMessage : read(%d)\n", n);
    //    return false;
    //}
    pmsg->size = ntohl(pmsg->size);
    pmsg->size -= FBCCMD_HEADER;
    //Log("msg received(%c: size - %d)\n", pmsg->cmd, pmsg->size);
    if( pmsg->size > 0) {
    	pmsg->data = (char*)malloc(pmsg->size);
        if( (n = ReadExact(psvc, (char*)pmsg->data, pmsg->size)) <= 0 ) {
            Err("ProcessClientMessage : read(%d)\n", n);
            return false;
        }
    }
    //Log("after alloc %02x %02x %02x %02x\n", msg.data[0],msg.data[1],msg.data[2],msg.data[3]);


    unsigned int data;
#ifdef PERFORMANCE_REPORT
	struct timeval tS, tE;

	gettimeofday(&tS,NULL);
	psvc->frame_client += ELAPSED(tLast, tS);
#endif
    switch(pmsg->cmd) {

        case 'i':
        {
        	FBCCMD_SCRINFO res;
        	res.cmd = 'i';
        	res.size = htonl(sizeof(FBCCMD_SCRINFO));

        	res.width = htonl(g_fbinfo.width);
        	res.height = htonl(g_fbinfo.height);
        	res.bpp = htonl(g_fbinfo.bpp);
        	res.touchfd = htonl( (touchfd != -1 ) ? 1 : 0);
        	LOCK(psvc->output_mutex);
            int rtn = WriteExact(psvc, (const char*)&res, sizeof(FBCCMD_SCRINFO));
            UNLOCK(psvc->output_mutex);
            //Log("response i %d to :%d\n", res.size, rtn);
        }
            break;
        case 'u':
        	//Log("signal-u\n");
        	g_halfmode = 0;
        	//TSIGNAL(psvc->updateCond);
        	read_rgb_framebuffer_to_jpeg(psvc);
#ifdef PERFORMANCE_REPORT
	gettimeofday(&tE,NULL);

	psvc->frame_total += ELAPSED(tS, tE);
	tS = tE;
#endif
            break;
        case 'h':
        	g_halfmode = 1;
        	//Log("signal-h\n");
        	//TSIGNAL(psvc->updateCond);
            //g_halfmode = 0;
            read_rgb_framebuffer_to_jpeg(psvc);
#ifdef PERFORMANCE_REPORT
	gettimeofday(&tE,NULL);

	psvc->frame_total += ELAPSED(tS, tE);
	tS = tE;
#endif
            break;
        case 'e':
            return false;
            break;
        case 'q':
        	ExitClient(psvc);
        	ShutdownSockets(psvc);
        	break;
        // ftp
        case 'k':	// ftp filestlist req
        	onFilelistReq(psvc, pmsg);
        	break;
        case 'l':	// ftp filedownload req
        	onFileDownloadReq(psvc, pmsg);
        	break;
        case 'm':	// ftp fileupload req
        	onFileUploadReq(psvc, pmsg);
        	break;
        case 'n':	// ftp fileupload data
            //Log("case n\n");

        	onFileMsg(psvc, pmsg);
        	break;
        case 'o':	// ftp fileerr
        	onFileErr(psvc, pmsg);
        	break;
        case 't':
        	onTouch(psvc, pmsg);
        	break;
    }

    if( pmsg->size > 0) {
    	free(pmsg->data);
    }

    //if(( psvc->frame_sent++ % 5) == 0) {
    //	g_fbinfo.orientation = get_dev_rotation();
    //	//int isScreenOn = get_screen_on();
    //	//Log("isScreenOn(%d)\n",isScreenOn);
    //}

#ifdef PERFORMANCE_REPORT

            if( (psvc->frame_sent % 10) == 0)
            {
            	double frame_total;
            	double frame_capture;
            	double frame_compress;
            	double frame_colorspace;
            	double frame_tx;
            	double frame_client;
            	double fps, fps_svr;



            	fps = (double)10 * 1000000 / (psvc->frame_total + psvc->frame_client);
            	fps_svr = (double)10 * 1000000 / psvc->frame_total;
            	frame_total = psvc->frame_total / 10000;
            	frame_capture = psvc->frame_capture / 10000;
            	frame_compress = psvc->frame_compress / 10000;
            	frame_colorspace = psvc->frame_colorspace / 10000;
            	frame_tx = psvc->frame_tx / 10000;
            	frame_client = psvc->frame_client / 10000;

                if( psvc->frame_sent > 10 )
                {
                	Log("FPS(%5.2f),SVR(%4.1f) TOT(%3.0f),CAP(%3.0f),ZIP(%3.0f),CNV(%2.0f),TX(%2.0f),CLI(%2.0f)\n",
                			//psvc->frame_sent-1,
                			fps, fps_svr,
                			frame_total, frame_capture, frame_compress, frame_colorspace, frame_tx,frame_client);
                }
            	psvc->frame_total		=	0;
            	psvc->frame_capture		=	0;
            	psvc->frame_compress	=	0;
            	psvc->frame_colorspace	=	0;
            	psvc->frame_tx			=	0;
            	psvc->frame_client		= 	0;

            }
            gettimeofday(&tLast,NULL);
#endif /* PERFORMANCE_REPORT */
           // Log("end loop");
    return true;

}
Esempio n. 12
0
void GLTouchScreen::analyze(float x, float y) {
	//x = roundf(x * width / context->width);
	//y = roundf(y * height / context->height);
	
	if (clientRatio > viewRatio) { // Экран уже чем треубется
		x = roundf(x * clientWidth / viewWidth);
		y = roundf((((y / viewHeight) - 0.5f) * clientRatio / viewRatio + 0.5f) * clientHeight);
	} else {
		x = roundf((((x / viewWidth) - 0.5f) * viewRatio / clientRatio + 0.5f) * clientWidth);
		y = roundf(y * clientHeight / viewHeight);
	}

	recordTrack(x, y, true);
	
	if (touchTimeout != 0) {
		touchTimeout = 0;
	}
	if (touchCancel) {
		touchCancel = false;
		return;
	}
	
	int32_t listlength = touchList.count();
	Vec3* list = touchList.items();
	if (listlength > 0) {
		CString type;
		
		GLfloat x1 = list[0].x;
		GLfloat y1 = list[0].y;
		GLfloat x2 = list[listlength - 1].x;
		GLfloat y2 = list[listlength - 1].y;
		
		if (listlength == 1) {
			int32_t count = clickList.count();
			if (count > 0) {
				GLTouchObject** items = clickList.items();
				for (int i = count - 1; i >= 0; i--) {
					GLfloat ww = items[i]->w;
					GLfloat hh = items[i]->h;
					GLfloat xx = items[i]->x;
					GLfloat yy = items[i]->y;
					if ((x1 >= xx) && (x1 < (xx + ww)) &&
						(y1 >= yy) && (y1 < (yy + hh))
					) {
						type = L"click ";
						type += items[i]->name;
						if (items[i]->onevent(type, NULL, NULL, NULL, items[i]->userData)) {
							break;
						}
					}
				}
			}
			if (type.m_length == 0)
				type = L"none";
		} else {
			// Определение кругового движения по часовой стрелке или против
			GLfloat cx, cy;
			{
				// Вычисляем центр окружности описывающей точки
				GLfloat xmin, xmax, ymin, ymax;
				xmin = xmax = x1;
				ymin = ymax = y1;
				for (int i = 0; i < listlength; i++) {
					GLfloat xx = list[i].x;
					GLfloat yy = list[i].y;
					if (xx < xmin) xmin = xx;
					if (xx > xmax) xmax = xx;
					if (yy < ymin) ymin = yy;
					if (yy > ymax) ymax = yy;
				}
				cx = (xmin + xmax) / 2.0f;
				cy = (ymin + ymax) / 2.0f;
				
				// Вычисляем средний радиус и определяем число смещений по кругу
				GLfloat mr = 0; // Средний радиус
				GLfloat cw = 0; // Число смещений по часовой стрелке
				GLfloat bw = 0; // Число смещений против часовой стрелки
				GLfloat ca = 0; // Угол смещения по часовой стрелке
				GLfloat ba = 0;	// Угол смещения против часовой стрелки
				GLfloat lx = x2 - cx;
				GLfloat ly = y2 - cy;
				GLfloat la = atan2f(ly, lx); // Угол последней точки
				for (int i = 0; i < listlength; i++) {
					// Координаты относительно центра
					GLfloat xx = list[i].x - cx;
					GLfloat yy = list[i].y - cy;
					// Растояние до точки
					GLfloat r = floorf(sqrtf(xx * xx + yy * yy));
					// Направление движения по часовой стрелке или против
					GLfloat s = lx * yy - ly * xx;
					GLfloat na = atan2f(yy, xx);
					GLfloat a = (na - la) * 180.0f / (GLfloat)M_PI;
					while (a < -180.0f) a += 360.0f;
					while (a > 180.0f) a -= 360.0f;
					if (i != 0) {
						if (s > 0) { cw++; ca += a; }
						else if (s < 0) { bw++; ba -= a; }
					}
					// Кешируем вычисления
					list[i].z = r;
					mr += r;
					la = na;
					lx = xx;
					ly = yy;
				}
				mr = floorf(mr / (GLfloat)listlength);
				
				// Вычисляем процентное соотношение смещений и направление
				GLfloat md = 0;
				if ((cw != 0) || (bw != 0)) {
					if (cw > bw) {
						md = floorf((cw - bw) * 100.0f / cw);
					} else {
						md = -floorf((bw - cw) * 100.0f / bw);
					}
				}
				// Угол смещения
				GLfloat a = fabsf(ba - ca);
				
				// Проверяем ровность круга (допустимое искажение радиуса 50% на каждую точку)
				if ((mr > minimalDistance) && (fabsf(md) > 90.0f)) {
					bool circle = true;
					GLfloat drm = 0;
					for (int i = 0; i < listlength; i++) {
						GLfloat dr = floorf(fabsf((list[i].z / mr) - 1.0f) * 100.0f);
						if (dr > drm) drm = dr;
						if (dr > 50.0f) {
							circle = false;
							break;
						}
					}
					if (circle) {
						int ac = (int)roundf(a / 90.0f);
						if (ac > 2) {
							type = L"circle";
						} else {
							type = L"arc";
						}
						if (md > 0) type += L" right";
						else type += L" left";
						if (ac > 5) {
							type += L" ";
							type += (ac * 90);
						}
					}
				}
			}
			
			// Определение свайпов и их направления
			if (type.m_length == 0) {
				// Вычисляем расстояние
				GLfloat dx = x2 - x1;
				GLfloat dy = y2 - y1;
				GLfloat d = floorf(sqrtf(dx * dx + dy * dy));
				
				// Отбрасываем случайные или короткие свайпы
				uint64_t time = currentTimeMillis();
				time -= touchStart;
				if ((d > minimalDistance) && ((listlength < 15) || (d >= swipeDistance))) {
					
					// Проверяем ровность линии (допустимое искажение 25% от длины прямой)
					bool swipe = true;
					GLfloat c = x1 * y2 - x2 * y1;
					for (int i = listlength - 2; i > 0; i--) {
						// Расстояние до точки от отрезка (+ знак стороны)
						GLfloat p = (list[i].y * dx - list[i].x * dy + c) / d;
						GLfloat dp = floorf(fabsf(p) * 100.0f / d);
						if (dp > 25) {
							swipe = false;
							break;
						}
					}
					
					if (swipe) {
						type = L"swipe";
						
						GLfloat ax = fabsf(dx);
						GLfloat ay = fabsf(dy);
						GLfloat ad = 0;
						if (ax > ay) {
							if (d > swipeDistance) type += L" long";
							ad = floorf((ax - ay) * 100.0f / ax);
							if (ad > 50) {
								if (dx > 0) type += L" right";
								else type += L" left";
							} else if (dx > 0) {
								if (dy < 0) type += L" right top";
								else type += L" right bottom";
							} else {
								if (dy < 0) type += L" left top";
								else type += L" left bottom";
							}
						} else {
							if (d > swipeDistance) type += L" long";
							ad = floorf((ay - ax) * 100.0f / ay);
							if (ad > 50) {
								if (dy < 0) type += L" top";
								else type += L" bottom";
							} else if (dy < 0) {
								if (dx > 0) type += L" right top";
								else type += L" left top";
							} else {
								if (dx > 0) type += L" right bottom";
								else type += L" left bottom";
							}
						}
					}
				}
			}
		}
		
		if (type.m_length != 0) {
			onTouch(type);
		}
	}
}
Esempio n. 13
0
void GEVisual::touch(int key_event, int type)
{
  if (onTouch != NULL)
    onTouch(this, key_event, type, opaque);
}