Пример #1
0
void Player::handleInput( KB_BUTTON jump, KB_BUTTON left, KB_BUTTON right, Pulse & pPulse )
{
	//Call movePlayer to handle movement based on given input

	if(Kb.b(KB_1)) {
		changeChar(0);
		characterID = 0;
	} else if(Kb.b(KB_2)) {
		changeChar(1);
		characterID = 1;
	} else if(Kb.b(KB_3)) {
		changeChar(2);
		characterID = 2;
	} else if(Kb.b(KB_4)) {
		changeChar(3);
		characterID = 3;
	} else if((Kb.b(jump) || Kb.b(KB_W) || Kb.b(KB_SPACE)) && this->jumpCount == 0) {
		movePlayer(4, pPulse);
	} else if(Kb.b(left) || Kb.b(KB_A)) {
		movePlayer(1, pPulse);
	} else if(Kb.b(right) || Kb.b(KB_D)) {
		movePlayer(2, pPulse);
	}
	else {
		movePlayer(3, pPulse);
	}
}
Пример #2
0
bool Game::play(void)
{
	if(!m_board)
		return false;

	if(isPlaying())
		return false;

	m_isPlaying = true;
	int i = 0;
	Move mv;
	bool valid_move;
	struct timeval tv_start, tv_end, tv_elapsed;
	movePlayer(Player::Player1, false);

	while(isPlaying() && m_board->winner() == Player::None && i < 40)
	{
		if(!movePlayer(Player::Player2))
			break;

		if(m_board->winner() != Player::None)
			break;

		if(!movePlayer(Player::Player1))
			break;

		i++;
	}

	m_isPlaying = false;
	return true;
}
Пример #3
0
void Game::keyPressEvent(KeyEvent& event) {
    /* Move forward */
    if(event.key() == KeyEvent::Key::Up || event.key() == KeyEvent::Key::W) {
        Vector3 direction = player->transformation().backward();
        Deg angle = Vector3::angle(Vector3::zAxis(), direction);

        if(angle < Deg(30.0f))
            movePlayer({0, -1});
        else if(angle > Deg(60.0f) && angle < Deg(120.0f))
            movePlayer({direction.x() > 0 ? -1 : 1, 0});
        else if(angle > Deg(150.0f))
            movePlayer({0, 1});

        if(!level->remainingTargets()) nextLevel();

    /* Restart level */
    } else if(event.key() == KeyEvent::Key::R) {
        restartLevel();

    /* Switch to menu */
    } else if(event.key() == KeyEvent::Key::Esc)
        pause();

    else return;

    event.setAccepted();
    redraw();
}
Пример #4
0
int updatePlayer( int dir )
{
    if ( conditionDuration != 0 )
    {
        conditionDuration--;
    }
    else
    {
        changeCommanderStatus( NORMAL, 0 );
    }
    
    struct monster *collideWith;
    switch ( dir )
    {
        case UP:
            movePlayer( &playerY, ( playerY > getGameAreaY( ) ), collideWith, CHKUP );
            break;
        case DOWN:
            movePlayer( &playerY, ( playerY < getGameAreaYplusHeight( ) ), collideWith, CHKDOWN );
            break;
        case LEFT:
            movePlayer( &playerX, ( playerX > getGameAreaX( ) ), collideWith, CHKLEFT );
            break;
        case RIGHT:
            movePlayer( &playerX, (playerX < getGameAreaXplusWidth( ) ), collideWith, CHKRIGHT );
            break;
        case NOTHING:
            break;
        default:
            return 1;
            break;
    }
    return 0;
}
Пример #5
0
int main(int argc, const char * argv[]) {
    
    Player player;
    PathSegment *path = GenerateAdventure();
    PrintPath(path);
    
    player.current = path;
    player.current->direction = DirectionMain;
    player.health = 100;
    
    
    
    char input[300];
    
    while (playing) {
        pathPrompt(&player);
        if(playing){
            scanf("%s", input);
            printf("input was %s\n", input);
            if(strstr(input,"Y"))
                movePlayer(&player,DirectionMain);
            else
                movePlayer(&player,DirectionSide);
            printPlayerStatus(&player);
        }
        
    }
    
    FreeAllPathSegments(path);
    
    return 0;
}
Пример #6
0
main()
{
	int key;

	while(1)
	{
		system("cls");
		drawPlayer(x,y);
		key = getch();

        switch(key)
        {
            case 113:
            case  81: //quit on "q"
                exit(0);
                break;
            case 119:
                movePlayer(0,-1);
                break;
            case 115:
                movePlayer(0,1);
                break;
            case  97:
                movePlayer(-1,0);
                break;
            case 100:
                movePlayer(1,0);
                break;
        }
	}
}
Пример #7
0
void ofApp::handleInput (int x, int y) {
	if (movePlayer (x, y)) {
		if (cellmap[playerX][playerY].isGround) {
			cellmap[playerX][playerY].isGround = false;
		} else {
			int newX = playerX + x;
			int newY = playerY + y;
			
			if (newX > 0 && newX < COLS && newY > 0 && newY < ROWS && cellmap[newX][newY].isGround) {
				movePlayer (x, y);
			}
		}
	}
	
	vector<ofPoint> newPoints;
	for (int i = 0; i < treasures.size(); i++) {
		
		
		ofPoint point = treasures[i];
		if (point.x + 1 < COLS) {
			if (!cellmap[int (point.x + 1)][int (point.y)].isGround
				&& !cellmap[int (point.x + 1)][int (point.y)].hasTreasure)
			{
				cellmap[int (point.x + 1)][int (point.y)].hasTreasure = true;
				newPoints.push_back(ofPoint(point.x + 1, point.y));
			}
		}
		if (point.x - 1 > 0) {
			if (!cellmap[int (point.x - 1)][int (point.y)].isGround
				&& !cellmap[int (point.x - 1)][int (point.y)].hasTreasure)
			{
				cellmap[int (point.x - 1)][int (point.y)].hasTreasure = true;
				newPoints.push_back(ofPoint(point.x - 1, point.y));
			}
		}
		if (point.y + 1 < ROWS) {
			if (!cellmap[int (point.x)][int (point.y + 1)].isGround
				&& !cellmap[int (point.x)][int (point.y + 1)].hasTreasure)
			{
				cellmap[int (point.x)][int (point.y + 1)].hasTreasure = true;
				newPoints.push_back(ofPoint(point.x, point.y + 1));
			}
		}
		if (point.y - 1 > 0) {
			if (!cellmap[int (point.x)][int (point.y - 1)].isGround
				&& !cellmap[int (point.x)][int (point.y - 1)].hasTreasure)
			{
				cellmap[int (point.x)][int (point.y - 1)].hasTreasure = true;
				newPoints.push_back(ofPoint(point.x, point.y - 1));
			}
		}
	}
	
	for (int i = 0; i < newPoints.size(); i++) {
		treasures.push_back(newPoints[i]);
	}
}
Пример #8
0
void Map::handleAutoSolve (uint32_t deltaTime)
{
	if (!_autoSolve)
		return;

	if (_solution.empty()) {
		abortAutoSolve();
		error(LOG_SERVER, "no solution");
		return;
	}

	_nextSolveStep -= deltaTime;
	if (_nextSolveStep > 0)
		return;

	_nextSolveStep = Config.getConfigVar("solvestepmillis", "100")->getIntValue();

	if (_solution[0] == '(') {
		abortAutoSolve();
		error(LOG_SERVER, "x() repeat syntax is not supported");
		return;
	}

	int l = 0;
	for (std::string::iterator i = _solution.begin(); i != _solution.end(); ++i) {
		if (*i >= '0' && *i <= '9') {
			++l;
		} else {
			break;
		}
	}

	if (_players.empty()) {
		abortAutoSolve();
		error(LOG_SERVER, "no player connected");
		return;
	}
	Player *p = *_players.begin();
	if (l == 0) {
		const char step = _solution[0];
		movePlayer(p, step);
		_solution = _solution.substr(1);
		return;
	}

	const std::string& rle = _solution.substr(0, l);
	const int n = string::toInt(rle);
	if (n <= 1) {
		_solution = _solution.substr(l);
		movePlayer(p, _solution[0]);
		_solution = _solution.substr(1);
	} else {
		movePlayer(p, _solution[l]);
		_solution = string::toString(n - 1) + _solution.substr(l);
	}
}
Пример #9
0
void DkPongPort::gameLoop() {

	// logic first
	moveBall();

	movePlayer(player1, player1Speed);
	movePlayer(player2, player2Speed);

	//repaint();
	viewport()->update();
	
	//QGraphicsView::update();
}
Пример #10
0
// main program
int main_prog()
{  
	// Initialize game
	initializeGame();
	
	// Initialize interrupts
	initializeInterrupts();
	
    // Send initial co-ordinates for all players
    sendInitialPositionsPackets();
	u8 i;
    for(i = 0; ; i++) {
		
		// Read data
    	numberOfPackets = 0;
    	readQueueData();
		
		//See if any player is inside foul box
		playerInDefendingFoulBox = numberOfPlayersInFoulBox(teamA, DEFENDING_FOUL);
		playerInAttackingFoulBox = numberOfPlayersInFoulBox(teamA, ATTACKING_FOUL);
		
		// Develop strategy for player movement by considering position of ball/players
		strategy();
		
		// offensive/defensive strategy switch
		u8 switches = XGpio_DiscreteRead(&GpioInputSwitch, 1);
		// if 4th bit of switch == 1, offensive
		if((switches >> 3) == 1) {
			//xil_printf("Inside offensive\n");
			// move all players to offensive side
			u8 j;
			for(j = 0; j < 5; j++) {
				if(fieldSide == FIELD_LEFT && teamA.player[j].position.x > 310) {
					position pos = {170, 200};
					movePlayer(&teamA.player[j], &pos);
				}
				else if(fieldSide == FIELD_RIGHT && teamA.player[j].position.x < 310) {
					position pos = {470, 200};
					movePlayer(&teamA.player[j], &pos);
				}
			}
		}
		else {
			// offensive
			// do nothing
		}

		// Send player movement updates
		sendUpdatePackets();
	}
Пример #11
0
void movingPlayer(char buttonToTest){ //C2C Mossing explained concept
        switch(buttonToTest){
        case BIT3:
                player=movePlayer(player,RIGHT);
                break;
        case BIT4:
                player=movePlayer(player, LEFT);
                break;
        case BIT5:
                player=movePlayer(player, UP);
                break;
        case BIT2:
                player=movePlayer(player, DOWN);
        }
}
Пример #12
0
// Game Struct initialisieren
void initGame(Game *g)
{
    // Startwerte
    g->level = 0;
    g->score = 0;
    g->enemyShots = NULL;
    g->player.shot = NULL;
    g->player.lives = 2; // Nur 2, weil danach startNewLevel aufgerufen wird (-> ein Leben mehr)
    g->enemyContainer.ufo.alive = false;
    g->enemyContainer.ufo.posx = 0;
    g->enemyContainer.ufo.lastufo = ms_time();
    
    // Spielerposition
    g->player.rect.x = WIDTH/2 - PLAYER_WIDTH/2;
    g->player.rect.y = PLAYER_Y_POS;
    g->player.rect.w = PLAYER_WIDTH;
    g->player.rect.h = PLAYER_HEIGHT;
    
    g->blocks = malloc(sizeof(Block) * BLOCK_COUNT);
    for (int i = 0; i < BLOCK_COUNT; i++) {
        for (int x = 0; x < BLOCK_WIDTH/BLOCK_TILE_WIDTH; x++) {
            for (int y = 0; y < BLOCK_HEIGHT/BLOCK_TILE_HEIGHT; y++) {
                g->blocks[i].damage[x][y] = 0;
                g->blocks[i].posx[x][y] = WIDTH/BLOCK_COUNT * i - BLOCK_WIDTH/2 + x*BLOCK_TILE_WIDTH + WIDTH/BLOCK_COUNT/2;
                g->blocks[i].posy[x][y] = PLAYER_Y_POS - 100 + y*BLOCK_TILE_HEIGHT;
            }
        }
    }
    
    // Nur zeichen, daher None
    movePlayer(g, None);
}
Пример #13
0
void GameSession::move() {

	_movementTimer++;

	if (_movementTimer != MOVEMENT_TIME) return;

	_movementTimer = 0;

	movePlayer();

	_level->iterate(isGravityInverted());
	_isOddIteration = !_isOddIteration;

	decreaseGravityTime();

	// If the last iteration of the game caused the player to die, we either
	// need to reset the level to its default state or end the game
	if (_level->getPlayerBlock()->isDestroyed()) {
		if (_lives > 0) {
			startLevel();
		} else {
			_isRunning = false;
			_isGameOver = true;
		}
	}
}
Пример #14
0
bool updateGame(void)
{
    /*  In cas of pausing  */
    if (state == STATE_PAUSE) {
        if (arduboy.buttonDown(A_BUTTON | B_BUTTON)) {
            state = STATE_GAME;
            ignoreCnt = 30; // 1/2 sec
            toDraw = true;
            dprintln("Resume");
        }
        return false;
    }

    /*  Move objects  */
    int scrollX = -playerX / 4;
    int scrollY = -playerY / 4;
    playerX += scrollX;
    playerY += scrollY;
    playerRotate += playerTorque;
    if (playerJump > -64) {
        if (--playerJump == 0) {
            pFloorBlur = NULL;
            if (state == STATE_CLEAR) {
                initLevel(false);
            }
        }
    }
    if (state != STATE_OVER) {
        moveFloors(scrollX, scrollY, playerJump);
    }
    moveChips(scrollX, scrollY, playerJump);

    /*  Player interaction  */
    if (state == STATE_GAME || state == STATE_OVER) {
        movePlayer();
        if (state == STATE_GAME) {
            gameFrames++;
            if (floorAry[floorIdxFirst].z < 0) {
                state = STATE_OVER;
                isHiscore = (setLastScore(score, gameFrames) == 0);
                counter = 480; // 8 secs
                arduboy.playScore2(soundOver, 1);
                dprint("Game Over: score=");
                dprintln(score);
            } else if (ignoreCnt == 0 && arduboy.buttonDown(A_BUTTON | B_BUTTON)) {
                state = STATE_PAUSE;
                dprintln("Pause");
            }
        } else {
            counter--;
            if (ignoreCnt == 0 && arduboy.buttonDown(A_BUTTON | B_BUTTON)) {
                initLevel(true);
            }
        }
    }
    if (ignoreCnt > 0) ignoreCnt--;
    toDraw = true;

    return (state == STATE_OVER && counter == 0);
}
Пример #15
0
void Unlag::reconcilePlayerPositions(byte shooter_id, size_t ticsago)
{
	for (size_t i=0; i<player_history.size(); i++)
	{
		player_t *player = player_history[i].player;

		// skip over the player shooting and any spectators
		if (player->id == shooter_id || player->spectator || !player->mo)
			continue;
	
		fixed_t dest_x, dest_y, dest_z; // position to move player to

		if (!reconciled)
		{
			// record the player's current position, which hasn't yet
			// been saved to the history arrays
			player_history[i].backup_x = player->mo->x;
			player_history[i].backup_y = player->mo->y;
			player_history[i].backup_z = player->mo->z;
  
  			size_t cur = (gametic - ticsago) % Unlag::MAX_HISTORY_TICS;

			dest_x = player_history[i].history_x[cur];
			dest_y = player_history[i].history_y[cur];
			dest_z = player_history[i].history_z[cur];

			if (player_history[i].history_size < ticsago)
			{
				// make the player temporarily unshootable since this player
				// was not alive when the shot was fired.  Kind of a hack.
				player_history[i].backup_flags = player->mo->flags;
				player->mo->flags &= ~(MF_SHOOTABLE | MF_SOLID);
				player_history[i].changed_flags = true;
			}

			#ifdef _UNLAG_DEBUG_
			// spawn a marker sprite at the reconciled position for debugging
	        AActor *mo = new AActor(dest_x, dest_y, dest_z, MT_KEEN);
			mo->flags &= ~(MF_SHOOTABLE | MF_SOLID);
			mo->health = -187;
			SV_SpawnMobj(mo);
			#endif // _UNLAG_DEBUG_
		}
		else
		{   // we're moving the player back to proper position
			dest_x = player_history[i].backup_x;
			dest_y = player_history[i].backup_y;
			dest_z = player_history[i].backup_z;

			// restore a player's shootability if we removed it previously
			if (player_history[i].changed_flags)
			{
				player->mo->flags = player_history[i].backup_flags;
				player_history[i].changed_flags = false;
			}
		}   

		movePlayer(player, dest_x, dest_y, dest_z); 
	}
}
Пример #16
0
// update the game logic here
void updateGame() {
	updateBallPosition(ball);
	movePlayer(player1);
	if(ball.speed.x < 0)
		seek(player2, ball);
	
	if( testOnScreen(ball) ) {
		// ball hit side of screen
		if(ball.position.x < 50) {
			// player 1 lost
			player2Score++;
		}
		else {
			// player 2 lost
			player1Score++;
		}
	}

	if(g_gameOver == false) {
		if( abs(player1Score - player2Score) >= 3) {
			// Game Over
			g_gameOver = true;

			int highestScore = player1Score;
			if(player2Score > highestScore) {
				highestScore = player2Score;
			}

			for(int i=0; i<5; i++) {
				if(highestScore > g_highScores[i]) {
					g_highScores[i] = highestScore;
					break;
				}
			}

			// sort the high scores array
			sort(g_highScores, 5);
		}
	}

	if(ball.speed.x < 0) {
		if(checkPaddleCollision(ball, player1) == true)  {
			ball.speed.x *= -1;
		}
	}
	else {
		if(checkPaddleCollision(ball, player2) == true)  {
			ball.speed.x *= -1;
		}
	}


	RotateSprite(player1.sprite, 0);
	MoveSprite(player1.sprite, player1.position.x, player1.position.y);

	RotateSprite(player2.sprite, 0 );
	MoveSprite(player2.sprite, player2.position.x, player2.position.y);

	MoveSprite(ball.sprite, (int)ball.position.x, (int)ball.position.y);
}
Пример #17
0
//Function used to determine which button has been pushed without polling
void testAndRespondToButtonPush(char buttonToTest) {
	if (buttonToTest & P1IFG) {

		if (buttonToTest & P1IES) {

			if (flag == 5) {
				LCDclr();
				location = initPlayer();
				printPlayer(location);
				flag = 0;
			}

			else {
				//This code is used to prevent the player (*) from moving outside of the game bounds.
				int mod = 0;
				mod = movePlayerInResponseToButtonPush(buttonToTest);
				clearPlayer(location);
				location += mod;
				location = movePlayer(location, mod);
				clearTimer();
			}

			//Debounces the button
		} else {
			debounce();
		}

		//Toggles between reading rising and falling edge
		P1IES ^= buttonToTest;
		P1IFG &= ~buttonToTest;
	}

}
Пример #18
0
Файл: main.cpp Проект: Sour/Game
void gameLoop()
{
	while(playing == true)
	{
		movePlayer(moveX, moveY);
	}
}
Пример #19
0
void Player2::checkMovement(int mode, double dt)
{
	movePlayer(mode, dt);

	float check;

	if (mode <= 1)
		check = (float)position.x / (MainScene::GetInstance()->ML_map.worldSize * 2);
	else
		check = (float)position.y / (MainScene::GetInstance()->ML_map.worldSize * 2);

	if (moveToDir[mode] == false)
	{
		switch (mode)
		{
		case 0:
			currTile.x--;
			break;
		case 1:
			currTile.x++;
			break;
		case 2:
			currTile.y--;
			break;
		case 3:
			currTile.y++;
			break;
		}
	}

	if (check != (int)check)
		moveToDir[mode] = true;

}
Пример #20
0
void handleKeyDownWorld(int keycode)
{
	switch(keycode){
		case CC_KEY_W:
			movePlayer(0, -1);
			break;
		case CC_KEY_S:
			movePlayer(0, 1);
			break;
		case CC_KEY_A:
			movePlayer(-1, 0);
			break;
		case CC_KEY_D:
			movePlayer(1, 0);
			break;
	}
}
Пример #21
0
void readInput(Player *player1) {
  fpurge(stdin);
  char input[20];
  scanf("%20[^\n]", input);
  if (strcasecmp(input, "right" ) == 0) {
    movePlayer(player1, player1->inRoom->right);
  }
  if (strcasecmp(input, "left") == 0) {
    movePlayer(player1, player1->inRoom->left);
  }
  if (strcasecmp(input, "top") == 0) {
    movePlayer(player1, player1->inRoom->top);
  }
  if (strcasecmp(input, "bottom") == 0) {
    movePlayer(player1, player1->inRoom->bottom);
  }
}
Пример #22
0
void Player::doSomething()
{
	int dir;
	StudentWorld *sw = getWorld();

	if(sw->getKey(dir)) //if there is an input
	{
		switch(dir)
		{
		case KEY_PRESS_SPACE:
			if(canShoot) //if the player can shoot a water droplet during this tick
			{
				int x, y;
				getLocation(x, y);

				//Determine the water droplets' positions first
				int dropletX = x;
				int dropletY = y+1;

				//while(dropletX>=0 && dropletX<GARDEN_WIDTH && dropletY>=0 && dropletY<GARDEN_HEIGHT)
				while(dropletX<=GARDEN_WIDTH-1 && dropletY<=GARDEN_HEIGHT-1)
				{
					if(getWorld()->insectThere(dropletX, dropletY) || getWorld()->mushroomThere(dropletX, dropletY))
					{
						getWorld()->attackObjects(dropletX, dropletY); //attack that object and give player points
						break; //no more droplets are to be shot!
					}
					else
					{
						WaterDroplet* w = new WaterDroplet(getWorld(), dropletX, dropletY); //Display a new water droplet
						getWorld()->storeObject(w);
						dropletY++; //Update the position of the next possible water droplet
					}
				}

				canShoot=false; //if a water droplet was shot this tick, make it so that one cannot be shot next tick
			}
			else
				canShoot=true; //if this round, no water droplet was shot, then one can be shot next tick
			break;
		default:
			movePlayer(dir); //if a key is pressed, move in that direction
			canShoot=true; //this counts as another tick, so next tick, another water droplet can be shot
			break;
		}
	}
	else
	{
		canShoot=true; //if canShoot was false earlier, no WaterDroplet was shot. Next round, the player can shoot again
	}

	int x, y;
	getLocation(x, y);
	if(getWorld()->insectThere(x, y)) //if the player is at or moves onto an insect, kill the player
		setDead();
	

}
Пример #23
0
void executeGo(const char *noun)
{
    OBJECT *obj = getVisible("where you want to go", noun);
    switch (getDistance(player, obj))
    {
    case distOverthere:
        movePlayer(getPassage(player->location, obj));
        break;
    case distNotHere:
        printf("You don't see any %s here.\n", noun);
        break;
    case distUnknownObject:
        // already handled by getVisible
        break;
    default:
        movePlayer(obj);
    }
}
Пример #24
0
void Game::keyPressEvent(QKeyEvent *event){
    int key = event->key();
    if (key == Qt::Key_Space){
        rotate();
    }
    else if (key == Qt::Key_A || key == Qt::Key_B || key == Qt::Key_C || key == Qt::Key_D ||
             key == Qt::Key_E || key == Qt::Key_I || key == Qt::Key_J || key == Qt::Key_K ||
             key == Qt::Key_L || key == Qt::Key_M || key == Qt::Key_O || key == Qt::Key_P ||
             key == Qt::Key_Q || key == Qt::Key_R || key == Qt::Key_S || key == Qt::Key_U ||
             key == Qt::Key_V || key == Qt::Key_W || key == Qt::Key_X || key == Qt::Key_Y) {
        insertStone(event->text().toUpper().toStdString().c_str());
    }
    else if (key == Qt::Key_Left){
        movePlayer("l");
    }
    else if (key == Qt::Key_Right){
        movePlayer("p");
    }
    else if (key == Qt::Key_Up){
        movePlayer("n");
    }
    else if (key == Qt::Key_Down){
        movePlayer("d");
    }
    else if (hrac_posunul == true && (key == Qt::Key_Enter || key == Qt::Key_Return)) {
        hracNaTahu++;
        if(hracNaTahu == pocetHracu) {
            hracNaTahu = 0;
        }
        hrac_posunul = false;
        posunuto = false;
        updateGame();
    }
    else if (key == Qt::Key_Control) {
        predmet = new Predmet();
        predmet->vykresliPredmet(hrac[hracNaTahu].hledany_predmet());
        predmet->setPos(125+(velikost*52),170);
        scene->addItem(predmet);
    }
    else if (key == Qt::Key_Escape) {
        if(running && !menu) showInGameMenu();
        else if(menu) updateGame();
    }
}
Пример #25
0
/**
* @brief verify that the movePlayer function correctly handle moves when the player is cerned by walls.
*/
void verifyPlayerCantMove() {
    int x_init = 1;
    int y_init = 1;
    int score_init = 2000;

    GRID grid;
    grid.height = 3;
    grid.width = 3;

    int matrix[3][3] = {
        {WALL, WALL, WALL},
        {WALL, PLAYER, WALL},
        {WALL, WALL, WALL}
    };

    grid.matrix = (int**) matrix;

    CHARACTER player;
    player.pos_x = x_init;
    player.pos_y = y_init;
    player.score = score_init;

    movePlayer(&grid, &player, 'z');                                            /*Test up move.*/
    CU_ASSERT(player.pos_x == x_init);
    CU_ASSERT(player.pos_y == y_init);
    CU_ASSERT(player.score == score_init);

    movePlayer(&grid, &player, 'q');                                            /*Test left move.*/
    CU_ASSERT(player.pos_x == x_init);
    CU_ASSERT(player.pos_y == y_init);
    CU_ASSERT(player.score == score_init);

    movePlayer(&grid, &player, 's');                                            /*Test down move.*/
    CU_ASSERT(player.pos_x == x_init);
    CU_ASSERT(player.pos_y == y_init);
    CU_ASSERT(player.score == score_init);

    movePlayer(&grid, &player, 'd');                                            /*Test right move.*/
    CU_ASSERT(player.pos_x == x_init);
    CU_ASSERT(player.pos_y == y_init);
    CU_ASSERT(player.score == score_init);
}
Пример #26
0
Файл: term.c Проект: gto76/race
void checkMove(char c, PLAYER (*ppp)[]) {
	int i, j;
	for (i = 0; i < numOfPlayers; i++) {
		for (j = 0; j < 4; j++) {
			if ((*ppp)[i].dir[j] == c) {
				movePlayer(ppp, i, j);
				return;
			}
		}
	}
}
Пример #27
0
void movecursor(char buttonToTest)
{
	clearPlayer(player);
	ClearTimer();
	switch(buttonToTest){
		case BIT1:
			player = movePlayer(player,RIGHT);
			break;
		case BIT2:
			player = movePlayer(player,LEFT);
			break;
		case BIT3:
			player = movePlayer(player,UP);
			break;
		case BIT4:
			player = movePlayer(player,DOWN);
			break;
	}
	printPlayer(player);
}
Пример #28
0
// Leben verloren
void playerDead(Game *g)
{
    freeShotList(g->enemyShots);
    g->enemyShots = NULL;
    if (g->player.shot != NULL) {
        free(g->player.shot);
        g->player.shot = NULL;
    }
    
    g->player.lives -= 2; // startNewLevel erhöht um 1
    g->level--;
    g->enemyContainer.ufo.alive = false;
    g->enemyContainer.ufo.lastufo = ms_time();
    
    // Spielerposition
    g->player.rect.x = WIDTH/2 - PLAYER_WIDTH/2;
    g->player.rect.y = PLAYER_Y_POS;
    g->player.rect.w = PLAYER_WIDTH;
    g->player.rect.h = PLAYER_HEIGHT;
    
    SDL_Rect area = {0, BORDER_TOP, WIDTH, HEIGHT - BORDER_TOP};
    SDL_FillRect(g->screen, &area, SDL_MapRGB(g->screen->format, 0, 0, 0));
    
    if (g->player.lives+2 == 0) {
        free(g->blocks);
        
        showGameOver(g);
        saveHighscore(g->score);
        showHighscore(g);
        
        SDL_Flip(g->screen);
        
        // Warten auf Tastendruck
        SDL_Event e;
        SDL_WaitEvent(&e);
        
        SDL_FillRect(g->screen, &area, SDL_MapRGB(g->screen->format, 0, 0, 0));
        
        initGame(g);
        startNewLevel(g);
        
        return;
    }
    
    SDL_Flip(g->screen);
    usleep(100000);
    
    // Nur zeichen, daher None
    movePlayer(g, None);
    
    startNewLevel(g);
}
bool CharacterUpdaterPlayer::update(const float delta)
{
    movePlayer( delta );

    if( shootingState != state_stopped )
    {
        if( shootingState == state_shooting )
        {
            if( shootingTarget != NULL )
            {
                if( shootingTarget->isActive() == false )
                {
                    shootingTarget = NULL;
                }

                // Update our shoot target as we follow our target
                else if( shootingBurstTimer > 0.0f )
                {
                    shootingLocation = *shootingTarget->positionPtr;
                }
            }

            player->shootWeapon( shootingLocation );

            shootingBurstTimer += delta;
            if( shootingBurstTimer >= 1.0f )
            {
                shootingBurstTimer = 1.0f;
                shootingState = state_stopping;
                shootingTarget = NULL;
            }
        }
        else
        {
            shootingBurstTimer -= delta * 2.0f;
            if( shootingBurstTimer > 0.0f )
            {
//                    if( shootAudioUsingIndex != -1 )
//                    {
//                        gEngine->audioManager->setVolume( shootAudioSampleIndices[shootAudioUsingIndex], shootTimer );
//                    }
            }
            else
            {
                stopShooting();
            }
        }
    }

    return true;
}
Пример #30
0
void turnEvent(int event){
  if(event < 4){
    if(event == EVENT_MOVE_UP){
      movePlayer(0,-1);
    } else if(event == EVENT_MOVE_RIGHT){
      movePlayer(1,0);
    } else if(event == EVENT_MOVE_DOWN){
      movePlayer(0,1);
    } else {
      movePlayer(-1,0);
    }
  } else {
    if(event == EVENT_SHOOT_UP){
      shootDirection(0,-1);
    } else if(event == EVENT_SHOOT_RIGHT){
      shootDirection(1,0);
    } else if(event == EVENT_SHOOT_DOWN){
      shootDirection(0,1);
    } else {
      shootDirection(-1,0);
    }
  }
  enemyTurn();
}