Exemplo n.º 1
0
/**
* \fn void setSideMotionPossibility(KaamObject* pObject, SDL_Surface* pSurfaceMap)
* \brief Set the side variable that indicate a faisability of a ground move.
*
* \param[in] pObject, pointer to the object to test.
* \param[in] pSurfaceMap, pointer to the map's surface.
* \returns void
*/
void setSideMotionPossibility(KaamObject* pObject, SDL_Surface* pSurfaceMap)
{
	pObject->rightOk = 1;
	pObject->leftOk = 1;
	pObject->objectSurface->clip_rect.x += XTEST;
	enum DIRECTION directionTest = RIGHT;
	if (collisionSurfaceWithMapLimits(pSurfaceMap, pObject->objectSurface)
		|| collisionSurfaceWithMap(pSurfaceMap, pObject->objectSurface, &directionTest, 1))
	{
		if (directionTest == DOWN)
		{
			pObject->rightOk = 2;
			if (!checkDirection(pSurfaceMap, pObject->objectSurface, 2, -5, UPRIGHT)
				|| !checkDirection(pSurfaceMap, pObject->objectSurface, 0, -5, UP))
				pObject->rightOk = 0;
		}
		else pObject->rightOk = 0;
	}
	pObject->objectSurface->clip_rect.x -= 2 * XTEST;
	directionTest = LEFT;
	if (collisionSurfaceWithMapLimits(pSurfaceMap, pObject->objectSurface)
		|| collisionSurfaceWithMap(pSurfaceMap, pObject->objectSurface, &directionTest, 1))
	{
		if (directionTest == DOWN)
		{
			pObject->leftOk = 2;
			if (!checkDirection(pSurfaceMap, pObject->objectSurface, -2, -5, UPLEFT)
				|| !checkDirection(pSurfaceMap, pObject->objectSurface, 0, -5, UP))
				pObject->leftOk = 0;
		}
		else pObject->leftOk = 0;
	}
	pObject->objectSurface->clip_rect.x += XTEST;
}
Exemplo n.º 2
0
void automove(){
  static int times = 0;
  boolean flag = false;
  
  //如果有障礙物且已經遠離上次的障礙物
  if(checkDirection(currentDir) && (times == 0)){
    uint8_t dir = (currentDir + 1) % 4;  //turn 90 degrees
    while(checkDirection(dir)){
      dir = (dir + 1) % 4;  //turn 90 degrees
      if(dir == currentDir){  //if can't move
        carMove(VEHICLE_X_MID, VEHICLE_Y_MID);
        flag = true;
        break;
      }
    }
    currentDir = dir;
    times = 25;
  }
  
  if(times > 0)
    times--;  
  if(!flag)
    carMove(cmd[currentDir].x, cmd[currentDir].y);
  Serial.println(currentDir);
}
Exemplo n.º 3
0
ValidMove Turn::constructValidMove(BoardSquare current_empty_bs, Board b, State pc)
{
	// store the directions for a valid move somewhere while we determine the capture line directions
	ValidMove vm;
	int dir_name_array_size = 0;
	Direction_Name* p_dir_name_array;
	std::stack<Direction_Name> dir_name_stack;

	for (int i = 0; i < 8; i++)
	{
		// if there is a capture line in that direction...
		if (checkDirection(current_empty_bs, b, pc, CARDINAL_AND_ORDINAL_DIRECTIONS_ARRAY[i].row_offset, CARDINAL_AND_ORDINAL_DIRECTIONS_ARRAY[i].col_offset) == true)
		{
			dir_name_array_size++;
			dir_name_stack.push(CARDINAL_AND_ORDINAL_DIRECTIONS_ARRAY[i].dir_name);
		}
	}

	// create p_dir_name_array
	p_dir_name_array = new Direction_Name[dir_name_array_size];
	for (int i = 0; !dir_name_stack.empty(); i++)
	{
		p_dir_name_array[i] = dir_name_stack.top();
		dir_name_stack.pop();
	}

	vm.row = current_empty_bs.getRow();
	vm.col = current_empty_bs.getCol();
	vm.dir_name_array_size = dir_name_array_size;
	vm.p_dir_name_array = p_dir_name_array;

	return vm;
}
void FourDirectionMoveController::registeKeyBoardEvent(){
	auto listener = EventListenerKeyboard::create();

	listener->onKeyPressed = [&](EventKeyboard::KeyCode code, Event* event){
		switch (code)
		{
		case cocos2d::EventKeyboard::KeyCode::KEY_W:
			press[0] = true;
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_D:
			press[1] = true;
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_S:
			press[2] = true;
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_A:
			press[3] = true;
			break;
		default:
			break;
		}
		checkDirection();
	};

	listener->onKeyReleased = [&](EventKeyboard::KeyCode code, Event* event){
		switch (code)
		{
		case cocos2d::EventKeyboard::KeyCode::KEY_W:
			press[0] = false;
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_D:
			press[1] = false;
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_S:
			press[2] = false;
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_A:
			press[3] = false;
			break;
		default:
			break;
		}
		checkDirection();
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
Exemplo n.º 5
0
int main(void) {
	setbuf(stdout, NULL);
	int T, i, j, N;
	int test_case;
	char tmp;
	scanf("%d", &T);
	for (test_case = 1; test_case <= T; test_case++) {
		// 이 부분에서 알고리즘 프로그램을 작성하십시오. 기본 제공된 코드를 수정 또는 삭제하고 본인이 코드를 사용하셔도 됩니다.

		init();
		scanf("%d", &N);
		for (i = 1; i <= N; i++)
			for (j = 1; j <= N; j++){
				scanf("%c", &tmp);
				while (tmp == '\n' || tmp == '\0')
					scanf("%c", &tmp);
				grid[i][j] = tmp - '0';
			}

		/* pos
			0 -> 오른쪽
			1 -> 위쪽
			2 -> 왼쪽
			3 -> 아래쪽
		*/

		while (grid[x][y] != -1){

			if (grid[x][y] % 3 == 1 || grid[x][y] % 3 == 2){
				if (grid[x][y] == 1){
					count++;
					grid[x][y] = 4;
				}
				else if (grid[x][y] == 2){
					count++;
					grid[x][y] = 5;
				}
				checkDirection();
			}

			switch (pos){
			case 0: y++; break;
			case 1: x--; break;
			case 2: y--; break;
			case 3: x++; break;
			}
		}
		// 이 부분에서 정답을 출력하십시오.
		printf("Case #%d\n", test_case);
		printf("%d\n", count);
	}

	return 0;	// 정상종료 시 반드시 0을 리턴해야 합니다.
}
int main()
{
	long result = 0;

	int data[size][size] =
		{{8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8},
		{49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,04,56,62,0},
		{81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,03,49,13,36,65},
		{52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,36,91},
		{22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80},
		{24,47,32,60,99,03,45,02,44,75,33,53,78,36,84,20,35,17,12,50},
		{32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70},
		{67,26,20,68,02,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21},
		{24,55,58,05,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72},
		{21,36,23,9,75,00,76,44,20,45,35,14,00,61,33,97,34,31,33,95},
		{78,17,53,28,22,75,31,67,15,94,03,80,04,62,16,14,9,53,56,92},
		{16,39,05,42,96,35,31,47,55,58,88,24,00,17,54,24,36,29,85,57},
		{86,56,00,48,35,71,89,07,05,44,44,37,44,60,21,58,51,54,17,58},
		{19,80,81,68,05,94,47,69,28,73,92,13,86,52,17,77,04,89,55,40},
		{04,52,8,83,97,35,99,16,07,97,57,32,16,26,26,79,33,27,98,66},
		{88,36,68,87,57,62,20,72,03,46,33,67,46,55,12,32,63,93,53,69},
		{04,42,16,73,38,25,39,11,24,94,72,18,8,46,29,32,40,62,76,36},
		{20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74,04,36,16},
		{20,73,35,29,78,31,90,01,74,31,49,71,48,86,81,16,23,57,05,54},
		{01,70,54,71,83,51,54,69,16,92,33,48,61,43,52,01,89,19,67,48}};

	for(int i = 0; i < size; i++)
	{
		for(int j = 0; j < size; j++)
		{
			result = max(result, checkDirection(data, i, j, 1, 0));
			result = max(result, checkDirection(data, i, j, 0, 1));
			result = max(result, checkDirection(data, i, j, 1, 1));
			result = max(result, checkDirection(data, i, j, -1, 0));
			result = max(result, checkDirection(data, i, j, -1, 1));
		}
	}

	printf("Result: %ld\n", result);
	return 0;
}
Exemplo n.º 7
0
void MoveSensorSystem::update(entityx::EntityManager &entities,
                              entityx::EventManager &events,
                              entityx::TimeDelta dt) {
    SurfaceC *surface;
    SensorC *sensorC;
    PositionC *positionC;
    MoveC *moveC;
    for (entityx::Entity ground : entities.entities_with_components<SurfaceC>()) {
        surface = ground.component<SurfaceC>().get();

        for (entityx::Entity unit : entities
                .entities_with_components<SensorC, PositionC, GroundedC, MoveC>()) {
            sensorC = unit.component<SensorC>().get();
            positionC = unit.component<PositionC>().get();
            moveC = unit.component<MoveC>().get();

            sensorC->rightS = checkDirection(surface, sensorC, positionC, moveC, 1);
            sensorC->leftS  = checkDirection(surface, sensorC, positionC, moveC, -1);
        }
    }
}
Exemplo n.º 8
0
void GpxBlock::setDirection(Graphic::Direction dir)
{
  qreal angle;
  if(_myDirection != dir && checkDirection(_myDirection))
    angle=rotationAngle(_myDirection, dir);
  else
  	angle = rotationAngle(Graphic::RIGHT,dir);
  _myDirection = dir;
	QGraphicsItem::rotate(angle);
	foreach(GpxConnectionInport* port, _inPorts) {
	    port->setDirection(direction());
		port->updatePosition();
	}
Exemplo n.º 9
0
static short BWLimiterProcess(PacketNode *head, PacketNode *tail)
{
	int dropped = 0;

	DWORD currentTime = timeGetTime();
	PacketNode *pac = tail->prev;
	// pick up all packets and fill in the current time
	while (pac != head) 
	{
		if (checkDirection(pac->addr.Direction, BWLimiterInbound, BWLimiterOutbound)) 
		{
			if ( bufSizeByte >= ((DWORD)BWQueueSizeValue*1024))
			{
				LOG("droped with chance, direction %s",
					BOUND_TEXT(pac->addr.Direction));
				freeNode(popNode(pac));
				++dropped;
			}
			else
			{
				insertAfter(popNode(pac), bufHead)->timestamp = timeGetTime();
				++bufSize;
				bufSizeByte += pac->packetLen;
				pac = tail->prev;
			}
		} 
		else 
		{
			pac = pac->prev;
		}
	}


	while (!isBufEmpty() && canSendPacket(currentTime))
	{
		PacketNode *pac = bufTail->prev;
		bufSizeByte -= pac->packetLen;
		recordSentPacket(currentTime, pac->packetLen);
		insertAfter(popNode(bufTail->prev), head); 
		--bufSize;
	}

	if (bufSize > 0)
	{
		LOG("Queued buffers : %d",
			bufSize);
	}


	return (bufSize>0) || (dropped>0);
}
Exemplo n.º 10
0
void CGSeerHut::setObjToKill()
{
	if (quest->missionType == CQuest::MISSION_KILL_CREATURE)
	{
		quest->stackToKill = getCreatureToKill(false)->getStack(SlotID(0)); //FIXME: stacks tend to disappear (desync?) on server :?
		assert(quest->stackToKill.type);
		quest->stackToKill.count = 0; //no count in info window
		quest->stackDirection = checkDirection();
	}
	else if (quest->missionType == CQuest::MISSION_KILL_HERO)
	{
		quest->heroName = getHeroToKill(false)->name;
		quest->heroPortrait = getHeroToKill(false)->portrait;
	}
}
Exemplo n.º 11
0
void StepperMotor::step(int numberOfSteps) {
	//cout << "Doing "<< numberOfSteps << " steps and going to sleep for " << uSecDelay/delayFactor << "uS\n";
	int sleepDelay = uSecDelay / delayFactor;
	checkDirection(numberOfSteps);
	if ((numberOfSteps < 0)) {
//		this->reverseDirection();
		numberOfSteps = -numberOfSteps;
	}
	for (int i = 0; i < numberOfSteps; i++) {
		if (isAtLimit()) {
			return;
		}
		this->step();
		usleep(sleepDelay);
	}
}
Exemplo n.º 12
0
static short dropProcess(PacketNode *head, PacketNode* tail) {
    int dropped = 0;
    while (head->next != tail) {
        PacketNode *pac = head->next;
        // chance in range of [0, 1000]
        if (checkDirection(pac->addr.Direction, dropInbound, dropOutbound)
            && calcChance(chance)) {
            LOG("dropped with chance %.1f%%, direction %s",
                chance/10.0, BOUND_TEXT(pac->addr.Direction));
            freeNode(popNode(pac));
            ++dropped;
        } else {
            head = head->next;
        }
    }

    return dropped > 0;
}
Exemplo n.º 13
0
static short dupProcess(PacketNode *head, PacketNode *tail) {
    short duped = FALSE;
    PacketNode *pac = head->next;
    while (pac != tail) {
        if (checkDirection(pac->addr.Direction, dupInbound, dupOutbound)
            && calcChance(chance)) {
            short copies = count - 1;
            LOG("duplicating w/ chance %.1f%%, cloned additionally %d packets", chance/100.0, copies);
            while (copies--) {
                PacketNode *copy = createNode(pac->packet, pac->packetLen, &(pac->addr));
                insertBefore(copy, pac); // must insertBefore or next packet is still pac
            }
            duped = TRUE;
        }
        pac = pac->next;
    }
    return duped;
}
Exemplo n.º 14
0
string solve(){
    string board[BOARD_LINE_SIZE];
    for(int i = 0; i < BOARD_LINE_SIZE; ++i){
        cin >> board[i];
    }

    bool has_empty = false;
    for(int i = 0; i < DIR_MAX; ++i){
        string ret = checkDirection(board, (DIRECTION)i, has_empty);
        if(!ret.empty()){
            return ret;
        }
    }

    if(has_empty){
        return "Game has not completed";
    }

    return "Draw";
}
Exemplo n.º 15
0
static short resetProcess(PacketNode *head, PacketNode *tail) {
    short reset = FALSE;
    PacketNode *pac = head->next;
    while (pac != tail) {
        if (checkDirection(pac->addr.Direction, resetInbound, resetOutbound)
            && pac->packetLen > TCP_MIN_SIZE
            && (setNextCount || calcChance(chance)))
        {
            PWINDIVERT_TCPHDR pTcpHdr;
            WinDivertHelperParsePacket(
                pac->packet,
                pac->packetLen,
                NULL,
                NULL,
                NULL,
                NULL,
                &pTcpHdr,
                NULL,
                NULL,
                NULL);

            if (pTcpHdr != NULL) {
                LOG("injecting reset w/ chance %.1f%%", chance/100.0);
                pTcpHdr->Rst = 1;
                WinDivertHelperCalcChecksums(pac->packet, pac->packetLen, 0);

                reset = TRUE;
                if (setNextCount > 0) {
                    InterlockedDecrement16(&setNextCount);
                }
            }
        }
        
        pac = pac->next;
    }
    return reset;
}
Exemplo n.º 16
0
static short tamperProcess(PacketNode *head, PacketNode *tail) {
    short tampered = FALSE;
    PacketNode *pac = head->next;
    while (pac != tail) {
        if (checkDirection(pac->addr.Direction, tamperInbound, tamperOutbound)
            && calcChance(chance)) {
            char *data = NULL;
            UINT dataLen = 0;
            if (WinDivertHelperParsePacket(pac->packet, pac->packetLen, NULL, NULL, NULL,
                NULL, NULL, NULL, (PVOID*)&data, &dataLen) 
                && data != NULL && dataLen != 0) {
                // try to tamper the central part of the packet,
                // since common packets put their checksum at head or tail
                if (dataLen <= 4) {
                    // for short packet just tamper it all
                    tamper_buf(data, dataLen);
                    LOG("tampered w/ chance %.1f, dochecksum: %d, short packet changed all", chance/10.0, doChecksum);
                } else {
                    // for longer ones process 1/4 of the lens start somewhere in the middle
                    UINT len = dataLen;
                    UINT len_d4 = len / 4;
                    tamper_buf(data + len/2 - len_d4/2 + 1, len_d4);
                    LOG("tampered w/ chance %.1f, dochecksum: %d, changing %d bytes out of %u", chance/10.0, doChecksum, len_d4, len);
                }
                // FIXME checksum seems to have some problem
                if (doChecksum) {
                    WinDivertHelperCalcChecksums(pac->packet, pac->packetLen, 0);
                }
                tampered = TRUE;
            }

        }
        pac = pac->next;
    }
    return tampered;
}
Exemplo n.º 17
0
/**
* \fn int jumpDoability(SDL_Surface* pSurfaceMap, SDL_Surface* pSurfaceMotion, enum DIRECTION jumpDirection)
* \brief Determine the faisability of a jump.
*
* \param[in] pSurfaceMap, pointer to the surface of the map.
* \param[in] pSurfaceMotion, pointer to the surface in motion.
* \param[in] jumpDirection, direction of the jump (UP or UPLEFT or UPRIGHT).
* \returns 1 = jump doable, 0 = jump not doable
*/
int jumpDoability(SDL_Surface* pSurfaceMap, SDL_Surface* pSurfaceMotion, enum DIRECTION jumpDirection)
{
	int checkUpLeft = 1, checkUpRight = 1, checkUp = 1, checkRight = 1, checkLeft = 1;
	int doAble = 1;

	checkUp = checkDirection(pSurfaceMap, pSurfaceMotion, 0, -7, UP);
	if (jumpDirection == UPLEFT)
	{
		checkUpLeft = checkDirection(pSurfaceMap, pSurfaceMotion, -3, -7, UPLEFT);
		checkLeft = checkDirection(pSurfaceMap, pSurfaceMotion, -3, 0, LEFT);
	}
	if (jumpDirection == UPRIGHT)
	{
		checkUpRight = checkDirection(pSurfaceMap, pSurfaceMotion, 3, -7, UPRIGHT);
		checkRight = checkDirection(pSurfaceMap, pSurfaceMotion, 3, 0, RIGHT);
	}
	if (jumpDirection == UP)
	{
		checkUpRight = checkDirection(pSurfaceMap, pSurfaceMotion, 2, -7, UPRIGHT);
		checkUpLeft = checkDirection(pSurfaceMap, pSurfaceMotion, -2, -7, UPLEFT);
	}
	doAble = processCheck(checkLeft, checkRight, checkUp, checkUpLeft, checkUpRight, jumpDirection);
	return doAble;
}
Exemplo n.º 18
0
int setMap(MAP * map, PROTAIN * prot, GENE * gene){
  /* タンパク質をマップの中心から描き始める */
  int x = map->len / 2;
  int y = map->len / 2;
  map->sq[x][y].prev = 2;
  int dir1, dir2, dir3;
  int prev, next;
  for(int i = 0; i < gene->len; i++){
    map->sq[x][y].on = 1;
    map->sq[x][y].pep = prot->pep[i];
    if(i == gene->len - 1){
      map->sq[x][y].next = -1;
      break;} 
    prev = map->sq[x][y].prev;
    switch(gene->dna[i]){
    case FRL:
      dir1 = (prev+2)%4;
      dir2 = (prev+3)%4;
      dir3 = (prev+1)%4;
      break;
    case FLR:
      dir1 = (prev+2)%4;
      dir2 = (prev+1)%4;
      dir3 = (prev+3)%4;
      break;
    case RFL:
      dir1 = (prev+3)%4;
      dir2 = (prev+2)%4;
      dir3 = (prev+1)%4;
      break;
    case RLF:
      dir1 = (prev+3)%4;
      dir2 = (prev+1)%4;
      dir3 = (prev+2)%4;
      break;
    case LFR:
      dir1 = (prev+1)%4;
      dir2 = (prev+2)%4;
      dir3 = (prev+3)%4;
      break;
    case LRF:
      dir1 = (prev+1)%4;
      dir2 = (prev+3)%4;
      dir3 = (prev+2)%4;
      break;
    }
    next = dir1;
    if(checkDirection(map, x, y, next)){
      next = dir2;
      if(checkDirection(map, x, y, next)){
        next = dir3;
        if(checkDirection(map, x, y, next)){
          //行き止まり
          gene->val = -1;//致死性遺伝子の印
          return 0;
        }
      }
    }
    map->sq[x][y].next = next;
    switch(next){
    case 0:
      x--;
      break;
    case 1:
      y++;
      break;
    case 2:
      x++;
      break;
    case 3:
      y--;
      break;
    default:
      break;
    }
    map->sq[x][y].prev = (next + 2) % 4;
  }

  x = map->len / 2;
  y = map->len / 2;
  map->sq[x][y].prev = -1;
  return 1;
}
Exemplo n.º 19
0
bool EmissionMap::checkDirection(const ParticleState& state) const {
	return checkDirection(state.getId(), state.getEnergy(), state.getDirection());
}
Exemplo n.º 20
0
 bool Gameboard::check() {
     checkResults_.erase(checkResults_.begin(), checkResults_.end());
     checkDirection(HORIZONTAL);
     checkDirection(VERTICAL);
     return !checkResults_.empty();
 }
Exemplo n.º 21
0
int video_thread(SceSize args, void *argp) {
	// Pixel coordinates: first = first luminant pixel to breach threshhold, last = ..., mid = ...
	Coord first, last, mid;
	int bufsize; int threshold = 200; // Luminance threshold.
	int showvideo = 0; // Show the actual video input? 0: No, 1: Yes

	// Camera buffers.
	PspUsbCamSetupVideoParam videoparam;
	static u8  buffer[MAX_STILL_IMAGE_SIZE] __attribute__((aligned(64)));
	static u8  work[68*1024] __attribute__((aligned(64)));
	static u32 framebuffer[480*272] __attribute__((aligned(64)));

	// Startup cursor position.
	cursor.x = 237, cursor.y = 50; old.x = 237, old.y = 50;

	// Setup the screenmap size and position.
	screenmap.x = 20; screenmap.y = 200;
	screenmap.w = 60; screenmap.h = 60;
	screenmap.gridcolor = 0xFFC09090;
	screenmap.fillcolor = 0xFFF0F0F0;
	screenmap.selcolor = 0xFFC0FFFF;

	// Create a start button.
	Button btnStart;
	btnStart.x = 420; btnStart.y = 250;
	btnStart.w = 50; btnStart.h = 12;
	btnStart.fillcolor = 0xFF00FFFF;
	btnStart.textcolor = 0xFF000000;
	btnStart.bordercolor = 0xFF000000;
	btnStart.shadowcolor = 0xFF888888;
	btnStart.bordersize = 1;
	btnStart.borderbevel = 0;
	btnStart.shadowsize = 0;
	btnStart.shadowdistance = 0;
	strcpy(btnStart.text, "Start");
	strcpy(btnStart.name, "btnStart");

	// Wait for camera to be connected.
	while (!connected) {
		clearScreen(0xFFF0F0F0);
		printTextScreenCenter(132, "Please connect the camera and press any button.", 0xFF009900);
		flipScreen(); sceDisplayWaitVblankStart();
		sceKernelDelayThread(20000);
	}

	// Load the camera modules and start the decoder.
	if (LoadModules() < 0) sceKernelSleepThread();
	if (StartUsb() < 0) sceKernelSleepThread();
	if (sceUsbActivate(PSP_USBCAM_PID) < 0) sceKernelSleepThread();
	if (InitJpegDecoder() < 0) sceKernelSleepThread();
	while (1) {
		if ((sceUsbGetState() & 0xF) == PSP_USB_CONNECTION_ESTABLISHED) break;
		sceKernelDelayThread(50000);
	}

	//Setup video parameters and start video capture.
	memset(&videoparam, 0, sizeof(videoparam));
	videoparam.size = sizeof(videoparam);
	videoparam.resolution = PSP_USBCAM_RESOLUTION_480_272;
	videoparam.framerate = PSP_USBCAM_FRAMERATE_30_FPS;
	videoparam.wb = PSP_USBCAM_WB_INCANDESCENT;
	videoparam.saturation = 125;
	videoparam.brightness = 100;
	videoparam.contrast = 64;
	videoparam.sharpness = 0;
	videoparam.effectmode = PSP_USBCAM_EFFECTMODE_NORMAL;
	videoparam.framesize = MAX_VIDEO_FRAME_SIZE;
	videoparam.evlevel = PSP_USBCAM_EVLEVEL_0_0;	
	if (sceUsbCamSetupVideo(&videoparam, work, sizeof(work)) < 0) sceKernelExitDeleteThread(0);
	sceUsbCamAutoImageReverseSW(1);
	if (sceUsbCamStartVideo() < 0) sceKernelExitDeleteThread(0);

	while (running) {
		int i, j, lum = 0, tracking = 0;
		first.x = 0; first.y = 0; last.x = 0; last.y = 0; mid.x = old.x; mid.y = old.y;
		clearScreen(0xFFFFFFFF);

		// Capture the camera image into the framebuffer.
		bufsize = sceUsbCamReadVideoFrameBlocking(buffer, MAX_VIDEO_FRAME_SIZE);
		if (bufsize > 0) sceJpegDecodeMJpeg(buffer, bufsize, framebuffer, 0);

		// Analyze the camera image.
		for (i = 0; i < 272; i++) {
			for (j = 0; j < 480; j++) {
				if (showvideo) putPixelScreen(framebuffer[i * CAM_LINE_SIZE + j], j, i); // Show video input.
				// Calculate luminance (brightness as perceived by the eye) and compare versus threshhold. 
				lum = (299 * R(framebuffer[i * CAM_LINE_SIZE + j]) + 587 * G(framebuffer[i * CAM_LINE_SIZE + j]) + 114 * B(framebuffer[i * CAM_LINE_SIZE + j])) / 1000;
				if (lum > threshold) {
					tracking = 1; if (aligned) putPixelScreen(0xFF0000FF, j, i);
					if ((first.x == 0) || (j < first.x)) first.x = j;
					if ((first.y == 0) || (i < first.y)) first.y = i;
					if ((last.x == 0) || (j > last.x)) last.x = j;
					if ((last.y == 0) || (i > last.y)) last.y = i;
				}
			}
		}

		if (tracking) {
			// Calculate directional movement and determine cursor position.
			mid.x = first.x + (abs((last.x - first.x)) / 2); mid.y = first.y + (abs((last.y - first.y)) / 2);
			checkDirection(mid, old);
			switch (direction) {
				case 0: cursor.x = old.x; cursor.y = old.y; break;
				case 1: cursor.x = first.x; cursor.y = first.y + (abs((last.y - first.y)) / 2); break;
				case 2: cursor.x = first.x; cursor.y = first.y; break;
				case 3: cursor.x = first.x + (abs((last.x - first.x)) / 2); cursor.y = first.y; break;
				case 4: cursor.x = last.x; cursor.y = first.y; break;
				case 5: cursor.x = last.x; cursor.y = first.y + (abs((last.y - first.y)) / 2); break;
				case 6: cursor.x = last.x; cursor.y = last.y; break;
				case 7: cursor.x = first.x + (abs((last.x - first.x)) / 2); cursor.y = last.y; break;
				case 8: cursor.x = first.x; cursor.y = last.y; break;		
			};
			
			//Uncomment the following lines to draw 'directional' markers on screen.
			/*if ((abs(last.x - first.x) > 15) || (abs(last.y - first.y) > 15)) {
				if ((direction > 0) && (direction <= 4)) {
					drawLineScreen(first.x, first.y, last.x, last.y, 0xFFC0C0C0);
				} else {
					drawLineScreen(last.x, last.y, first.x, first.y, 0xFFC0C0C0);
				}
				switch (direction) {
					case 0: break;
					case 1: drawLineScreen(last.x, last.y + ((last.y - first.y) / 2), first.x, first.y + ((last.y - first.y) / 2), 0xFFC0C0C0); break; // W
					case 2: drawLineScreen(last.x, last.y, first.x, first.y, 0xFFC0C0C0); break; // NW
					case 3: drawLineScreen(first.x + ((last.x - first.x) / 2), last.y, first.x + ((last.x - first.x) / 2), first.y, 0xFFC0C0C0); break; // N
					case 4: drawLineScreen(first.x, last.y, last.x, first.y, 0xFFC0C0C0); break; // NE
					case 5: drawLineScreen(first.x, first.y + ((last.y - first.y) / 2), last.x, first.y + ((last.y - first.y) / 2), 0xFFC0C0C0); break; // E
					case 6: drawLineScreen(first.x, first.y, last.x, last.y, 0xFFC0C0C0); break; // SE
					case 7: drawLineScreen(first.x + ((last.x - first.x) / 2), first.y, first.x + ((last.x - first.x) / 2), last.y, 0xFFC0C0C0); break; // S
					case 8: drawLineScreen(last.x, first.y, first.x, last.y, 0xFFC0C0C0); break; // SW
				};
				drawLineScreen((first.x > last.x) ? last.x : first.x, (first.y > last.y) ? last.y : first.y, (first.x < last.x) ? last.x : first.x, (first.y < last.y) ? last.y : first.y, 0xFFC0C0C0);
			} else {
				drawRectScreen(0xFFC0C0C0, first.x, first.y, last.x - first.x, last.y - first.y);
			}*/
		} else {
			printTextScreenCenter(10, "Please return to the playing area.", 0xFF0000FF);
			if (lastdirection == 0) { cursor.x = old.x; cursor.y = old.y; }
			//if ((aligned) && (!menu) && (_gameState = GAME_RUNNING)) HandlePauseGame();
		}

		if (!aligned) {
			showvideo = 1;
			// Alignment Screen: wait for camera to be aligned to the playing area.
			printTextScreenCenter(126, "Please align the camera to the playing area.", 0xFFFFFFFF);
			printTextScreenCenter(136, "Drag the cursor to the \"Start\" button to continue.", 0xFFFFFFFF);

			if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFF00FF00; aligned = 1; menu = 1; }
			drawButtonScreen(btnStart);
			if (aligned) { btnStart.fillcolor = 0xFF00FFFF; btnStart.x = 240 - (btnStart.w / 2); btnStart.y = 200; }
		} else if (menu) {
			showvideo = 0;
			// Menu Screen: show a splash, logo, menu, etc.
			printTextScreenCenter(126, "eyePSP Pong", 0xFF009900);
			printTextScreenCenter(136, "Please press the \"Start\" button to continue.", 0xFFFF0000);

			if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; menu = 0; }
			drawButtonScreen(btnStart);
		} else {
			// Draw any game objects here.
			if (_gameState == GAME_PAUSED) {
				printTextScreenCenter(100, "Game Paused", COLOR_RED);
				if (tracking) _gameState = GAME_RUNNING;
			} else if (_gameState == GAME_RUNNING) {
				DrawMainText(); // Draw main graphics and supporting text to the screen.
				DrawPaddle(&_paddle); // Draws the paddle to the screen
			} else if (_gameState == GAME_CONTINUE) {
				char sbuffer[50];
				sprintf(sbuffer, "%d Ball%s Remaining...", _resBalls, (_resBalls == 1) ? "" : "s");
				printTextScreenCenter(100, sbuffer, 0xFF000088);

				if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; _gameState = GAME_RUNNING; }
				drawButtonScreen(btnStart);
			} else if (_gameState == GAME_OVER) {
				// Draws game over graphics and waits for user to continue
				DrawGameOverMenu();

				if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; _gameState = GAME_RUNNING; }
				drawButtonScreen(btnStart);
			}
		}

		// Draw cursor (within boundaries) .
		if (tracking) {
			for (i = cursor.y - 5; i <= cursor.y + 5; i++) { if ((i > 0) && (i < 272)) putPixelScreen(!tracking ? 0xFF0000FF : 0xFF009900, cursor.x, i); } // y-axis
			for (j = cursor.x - 5; j <= cursor.x + 5; j++) { if ((j > 0) && (j < 480)) putPixelScreen(!tracking ? 0xFF0000FF : 0xFF009900, j, cursor.y); } // x-axis
		}

		old.x = cursor.x; old.y = cursor.y; lastdirection = direction;
		flipScreen(); sceDisplayWaitVblankStart();
		sceKernelDelayThread(2000);
	}
	sceKernelExitDeleteThread(0);
	return 0;	
}
Exemplo n.º 22
0
void SpringDot::adjust()
{
	changePeriod();
	checkDirection();
}
Exemplo n.º 23
0
void Player2::Update(double dt)
{
	if (std::all_of(moveToDir.begin(), moveToDir.end(), [](bool v){return !v; })) // Check if all boolean in vector list are false
	{
		if (Application::IsKeyPressed(VK_UP) && !checkCollision(2))
			checkMovement(2, dt);
		else if (Application::IsKeyPressed(VK_LEFT) && !checkCollision(0))
			checkMovement(0, dt);
		else if (Application::IsKeyPressed(VK_DOWN) && !checkCollision(3))
			checkMovement(3, dt);
		else if (Application::IsKeyPressed(VK_RIGHT) && !checkCollision(1))
			checkMovement(1, dt);

		if (Application::IsKeyPressed(VK_UP) ||
			Application::IsKeyPressed(VK_LEFT) ||
			Application::IsKeyPressed(VK_DOWN) ||
			Application::IsKeyPressed(VK_RIGHT))
		{
			if (!SE_Engine.isSoundPlaying(SoundList[ST_FOOTSTEPS]))
				SE_Engine.playSound2D(SoundList[ST_FOOTSTEPS]);
		}


		if (Application::IsKeyPressed(VK_LBUTTON) && sonarTimer >= sonarCooldown)
		{
			LuaScript playerScript("character");
			sonarTimer = 0;
			Sonar *SNR;
			SNR = new Sonar();
			SNR->Init(playerScript.get<float>("player.sonar_radius"), playerScript.get<int>("player.sonar_sides"), playerScript.get<float>("player.sonar_speed"));
			SNR->GenerateSonar(position, 1);
			sonarList.push_back(SNR);
		}
		else if (Application::IsKeyPressed(VK_RBUTTON) && specialTimer >= specialCooldown && !isSpecial)
		{
			specialPos = position;
			specialTimer = 0;
			isSpecial = true;
		}
	}
	if (isSpecial && specialCounter < specialDuration)
	{
		if (specialTimer2 >= specialROF)
		{
			LuaScript playerScript("character");
			specialTimer2 = 0;
			Sonar *SNR;
			SNR = new Sonar();
			SNR->Init(playerScript.get<float>("player.special_radius"), playerScript.get<int>("player.special_sides"), playerScript.get<float>("player.special_speed"));
			SNR->GenerateSonar(specialPos, 2);
			sonarList.push_back(SNR);
		}
	}

	if (sonarTimer < sonarCooldown)
		sonarTimer += dt;

	if (specialTimer < specialCooldown)
		specialTimer += dt;

	if (specialTimer2 < specialROF && isSpecial)
		specialTimer2 += dt;

	if (isSpecial)
		specialCounter += dt;

	if (specialCounter >= specialDuration)
	{
		isSpecial = false;
		specialCounter = 0;
		specialTimer2 = 0;
		specialPos.SetZero();
	}


	for (int i = 0; i < sonarList.size(); ++i)
	{
		sonarList[i]->Update(dt);

		if (sonarList[i]->segmentList.empty())
		{
			delete sonarList[i];
			sonarList.erase(sonarList.begin() + i);
		}
	}

	for (int i = 0; i < moveToDir.size(); ++i)
	{
		checkDirection(i, dt);
	}


}
Exemplo n.º 24
0
static short capProcess(PacketNode *head, PacketNode *tail) {
    short capped = FALSE;
    PacketNode *pac, *pacTmp, *oldLast;
    DWORD curTick = timeGetTime();
    DWORD deltaTick = curTick - capLastTick;
    int bytesCapped = (int)(deltaTick * 0.001 * kps * FIXED_EPSILON * 1024);
    int totalBytes = 0;
    LOG("kps val: %d, capped kps %.2f, capped at %d bytes", kps, kps * FIXED_EPSILON, bytesCapped);
    capLastTick = curTick;


    // process buffered packets
    oldLast = tail->prev;
    while (!isBufEmpty()) {
        // TODO should check direction in buffer?
        // sends at least one from buffer or it would get stuck
        pac = bufTail->prev;
        totalBytes += pac->packetLen;
        insertAfter(popNode(pac), oldLast);
        --bufSize;

        LOG("sending out packets of %d bytes", totalBytes);

        if (totalBytes > bytesCapped) {
            break;
        }   
    }

    // process live packets
    pac = oldLast;
    while (pac != head) {
        if (!checkDirection(pac->addr.Direction, capInbound, capOutbound)) {
            pac = pac->prev;
            continue;
        }

        // live packets can all be kept
        totalBytes += pac->packetLen;

        if (totalBytes > bytesCapped) {
            int capCnt = 0;
            capped = TRUE;
            // buffer from pac to head 
            while (bufSize < KEEP_AT_MOST && pac != head) {
                pacTmp = pac->prev;
                insertAfter(popNode(pac), bufHead);
                ++bufSize;
                ++capCnt;
                pac = pacTmp;
            }

            if (pac != head) {
                LOG("! hitting cap max, dropping all remaining");
                while (pac != head) {
                    pacTmp = pac->prev;
                    freeNode(pac);
                    pac = pacTmp;
                }
            }
            assert(pac == head);
            LOG("capping %d packets", capCnt);
            break;
        } else {
            pac = pac->prev;
        }
    }

    return capped;
}
Exemplo n.º 25
0
/**
* \fn int testGround(SDL_Surface* pSurfaceMap, SDL_Surface* pSurfaceMotion, int testValue)
* \brief Checks if a surface is on the ground.
*
* \param[in] pSurfaceMap, pointer to the surface of the map.
* \param[in] pSurfaceMotion, pointer to the surface in motion.
* \param[in] testValue, value of the y offset to test ground
* \returns  1 = onGround, 0 = not on the ground
*/
int testGround(SDL_Surface* pSurfaceMap, SDL_Surface* pSurfaceMotion, int testValue)
{
	return !checkDirection(pSurfaceMap, pSurfaceMotion, 0, testValue, DOWN);
}
Exemplo n.º 26
0
int geneValue(MAP * map, PROTAIN * prot, GENE * gene){
  initMap(map);
  setMap(map, prot, gene);
  /*致死性遺伝子は評価値0*/
  if(gene->val == -1){
    gene->val = 0;
    return gene->val;
  }
  
  int x = map->len / 2;
  int y = map->len / 2;
  int val = 0;
  for(int i = 0; i < prot->len; i++){
    if(map->sq[x][y].pep == H){
      for(int dir = 0; dir < 4; dir++){
        if((dir != map->sq[x][y].prev) && (dir != map->sq[x][y].next)){
          if(checkDirection(map, x, y, dir)){
            PEPTID neib;
            switch(dir){
            case 0:
              neib = map->sq[x-1][y].pep;
              break;
            case 1:
              neib = map->sq[x][y+1].pep;
              break;
            case 2:
              neib = map->sq[x+1][y].pep;
              break;
            case 3:
              neib = map->sq[x][y-1].pep;
              break;
            default:
              break;
            }
            if(neib == H){
              val++;
              map->sq[x][y].HHC = 1;
            }
          }
        }
      }
    }
    switch(map->sq[x][y].next){
    case 0:
      x--;
      break;
    case 1:
      y++;
      break;
    case 2:
      x++;
      break;
    case 3:
      y--;
      break;
    default:
      break;
    }
  }

  gene->val = val / 2;
  
  return gene->val;
}
Exemplo n.º 27
0
/*
 moveCarOneBay(car, d, c) attempts to move car by one bay in the
 direction of d, returning true iff the car was able to successfully
 complete the move.  The requested move is performed (and the carpark
 updated to reflect the move) if the car can move in the given
 direction, the movement does not take the car outside the bounds of
 the carpark, and there is no other car at the destination location.
 */
static bool moveCarOneBay(char car, DIRECTION d, CARINFO c)
{
	LOCATION l;

	if(!isValidCarparkEntry(car))	// check the car is defined in the carpark
	{
		return false;
	}
	
	if(!checkDirection(d, c))	// check the direction is valid
	{
		return false;
	}

	l.row = c.front.row;
	l.col = c.front.col;
	
	if(c.length == 2)	// if car length is equal to 2
	{
		/*
		 The following code moves the car relative to the direction specified
		 provided the car length is equal to 2.
		 */
		
		if(d == SOUTH && carpark.grid[c.front.row + 2][c.front.col] == EMPTY)
		{
			carpark.grid[c.front.row + 2][c.front.col] = car;
			setValue(l, EMPTY);
			c.front.row = c.front.row + 1;
			return true;
		}
		
		if(d == NORTH && carpark.grid[c.front.row - 1][c.front.col] == EMPTY)
		{	
			carpark.grid[c.front.row - 1][c.front.col] = car;
			l.row = c.front.row + 1;
			setValue(l, EMPTY);		
			c.front.row = c.front.row - 1;		
			return true;
		}

		if(d == EAST && carpark.grid[c.front.row][c.front.col + 2] == EMPTY)
		{
			carpark.grid[c.front.row][c.front.col + 2] = car;
			setValue(l, EMPTY);
			c.front.col = c.front.col + 1;
			return true;
		}
	
		if(d == WEST && carpark.grid[c.front.row][c.front.col - 1] == EMPTY)
		{
			carpark.grid[c.front.row][c.front.col - 1] = car;
			l.col = c.front.col + 1;
			setValue(l, EMPTY);
			c.front.col = c.front.col - 1;
			return true;
		}
	}

	if(c.length == 3)	// if car length is equal to 3
	{					
		/*
		 The following code moves the car relative to the direction specified
		 provided the car length is equal to 3.
		 */
		
		if(d == SOUTH && carpark.grid[c.front.row + 3][c.front.col] == EMPTY)
		{
			carpark.grid[c.front.row + 3][c.front.col] = car;
			setValue(l, EMPTY);
			c.front.row = c.front.row + 1;
			return true;
		}
		
		if(d == NORTH && carpark.grid[c.front.row - 1][c.front.col] == EMPTY)
		{	
			carpark.grid[c.front.row - 1][c.front.col] = car;
			l.row = c.front.row + 2;
			setValue(l, EMPTY);		
			c.front.row = c.front.row - 1;		
			return true;
		}

		if(d == EAST && carpark.grid[c.front.row][c.front.col + 3] == EMPTY)
		{
			carpark.grid[c.front.row][c.front.col + 3] = car;
			setValue(l, EMPTY);
			c.front.col = c.front.col + 1;
			return true;
		}
	
		if(d == WEST && carpark.grid[c.front.row][c.front.col - 1] == EMPTY)
		{
			carpark.grid[c.front.row][c.front.col - 1] = car;
			l.col = c.front.col + 2;
			setValue(l, EMPTY);
			c.front.col = c.front.col - 1;
			return true;
		}
	}				
	
	return false;
}