예제 #1
0
void Bullet::moveUp( std::vector<SDL_Rect>& otherColliders )
{
	mVelY++;

    //Move the dot left or right
    mPosX += mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
        if (!bulletsUp.empty())
		{
			bulletsUp.pop_back();
		}
		mVelY = 0;
    }

    //Move the dot up or down
    mPosY -= mVelY;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        if (!bulletsUp.empty())
		{
			bulletsUp.pop_back();
			mVelY = 0;
		}
    }
}
예제 #2
0
void LevelPlaySelect::checkMouse(ImageManager &imageManager, SDL_Renderer &renderer){
	int x,y;
	
	//Get the current mouse location.
	SDL_GetMouseState(&x,&y);
	
	//Check if we should replay the record.
	if(selectedNumber!=NULL){
		SDL_Rect mouse={x,y,0,0};
		if(!bestTimeFilePath.empty()){
			SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-130,372,32};
			if(checkCollision(box,mouse)){
				Game::recordFile=bestTimeFilePath;
				levels->setCurrentLevel(selectedNumber->getNumber());
				setNextState(STATE_GAME);
				return;
			}
		}
		if(!bestRecordingFilePath.empty()){
			SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-98,372,32};
			if(checkCollision(box,mouse)){
				Game::recordFile=bestRecordingFilePath;
				levels->setCurrentLevel(selectedNumber->getNumber());
				setNextState(STATE_GAME);
				return;
			}
		}
	}
	
	//Call the base method from the super class.
    LevelSelect::checkMouse(imageManager, renderer);
}
예제 #3
0
void Enemy::move( std::vector<SDL_Rect>& otherColliders )
{
	mVelY++;

    //Move the dot left or right
    mPosX += mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + ENEMY_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
		POINTS +=100;
       mPosX = randomRange(0, SCREEN_WIDTH);
	   mVelX = 0;
	   shiftColliders();

    }

    //Move the dot up or down
    mPosY += mVelY - mPosY/2;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + ENEMY_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
		POINTS +=100;
        mPosY = randomRange(0, SCREEN_HEIGHT);
		mVelY = 0;
		shiftColliders();
    }

}
예제 #4
0
void BallController::updateCollision(Grid* grid)
{
	for (int i = 0; i < grid->_cells.size(); i++)
	{
		int x = i % grid->_numXCells;
		int y = i / grid->_numXCells;

		Cell* cell = grid->getCell(x, y);
		for (int j = 0; j < cell->balls.size(); j++)
		{
			Ball* ball = cell->balls[j];
			checkCollision(ball, cell->balls, j+1);

			if (x > 0)
			{
				checkCollision(ball, grid->getCell(x - 1, y)->balls, 0);
				if (y > 0)
				{
					checkCollision(ball, grid->getCell(x-1,y-1)->balls, 0);
				}
				if (y < grid->_numYCells - 1)
				{
					checkCollision(ball, grid->getCell(x - 1, y + 1)->balls, 0);
				}
			}

			if (y > 0)
			{
				checkCollision(ball, grid->getCell(x, y - 1)->balls, 0);
			}
		}
	}
}
예제 #5
0
void Dot::move( SDL_Rect& wall )
{
    //Move the dot left or right
    mPosX += mVelX;
	mCollider.x = mPosX;

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mCollider, wall ) )
    {
        //Move back
        mPosX -= mVelX;
		mCollider.x = mPosX;
    }

    //Move the dot up or down
    mPosY += mVelY;
	mCollider.y = mPosY;

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mCollider, wall ) )
    {
        //Move back
        mPosY -= mVelY;
		mCollider.y = mPosY;
    }
}
예제 #6
0
파일: Game.cpp 프로젝트: wmolicki/riverride
void CGame::collideShellsWithEnemies()
{
	//get list of all plane shells
	std::list<std::unique_ptr<SDL_Rect>> *shells = plane.getShellsFired();

	//iterate over enemies
	for (std::list<std::unique_ptr<CEnemy>>::iterator enemy = enemyList.begin(); enemy != enemyList.end(); enemy++)
	{
		//check if enemy is on screen, and is alive
		if (checkCollision(plane.getCamera(), (*enemy)->getBox()) && (*enemy)->isAlive())
		{
			//iterate over plane shells
			for (std::list<std::unique_ptr<SDL_Rect>>::iterator shell = shells->begin(); shell != shells->end(); shell++)
			{
				SDL_Rect shell_rect = {(*shell)->x, (*shell)->y, (*shell)->w, (*shell)->h };
				if (checkCollision(shell_rect, (*enemy)->getBox()))
				{
					shell->release();
					shells->erase(shell++);
					if ((*enemy)->type == BRIDGE)
					{
						//if killed a bridge, set new starting pos
						SDL_Rect bridge = (*enemy)->getBox();
						plane.setStartingPos(bridge.x + bridge.w / 2, bridge.y - bridge.h);
						updateScoreTexture(1000);
					}
					(*enemy)->kill();
					updateScoreTexture(1000);
					break;
				}
			}
		}
	}
}
void Dot::move( std::vector<SDL_Rect>& otherColliders )
{
    //Move the dot left or right
    mPosX += mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
        mPosX -= mVelX;
		shiftColliders();
    }

    //Move the dot up or down
    mPosY += mVelY;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        //Move back
        mPosY -= mVelY;
		shiftColliders();
    }
}
예제 #8
0
파일: intersect.c 프로젝트: zear/g-ball
void getAdjacents(int i, int j, int* a)
{
	a[0] = (checkCollision(i,j-1) == COLLISION_SOLID);
	a[1] = (checkCollision(i+1,j) == COLLISION_SOLID);
	a[2] = (checkCollision(i,j+1) == COLLISION_SOLID);
	a[3] = (checkCollision(i-1,j) == COLLISION_SOLID);
}
예제 #9
0
void BallController::updateCollision(Grid* grid) {
    for (int i = 0; i < grid->m_cells.size(); i++) {

        int x = i % grid->m_numXCells;
        int y = i / grid->m_numXCells;

        Cell& cell = grid->m_cells[i];

        // Loop through all balls in a cell
        for (int j = 0; j < cell.balls.size(); j++) {
            Ball* ball = cell.balls[j];
            /// Update with the residing cell
            checkCollision(ball, cell.balls, j + 1);

            /// Update collision with neighbor cells
            if (x > 0) {
                // Left
                checkCollision(ball, grid->getCell(x - 1, y)->balls, 0);
                if (y > 0) {
                    /// Top left
                    checkCollision(ball, grid->getCell(x - 1, y - 1)->balls, 0);
                }
                if (y < grid->m_numYCells - 1) {
                    // Bottom left
                    checkCollision(ball, grid->getCell(x - 1, y + 1)->balls, 0);
                }
            }
            // Up cell
            if (y > 0) {
                checkCollision(ball, grid->getCell(x, y - 1)->balls, 0);
            }
        }
    }
}
예제 #10
0
void Bullet::enemyMove( std::vector<SDL_Rect>& otherColliders )
{
	mVelX++;
	mVelY++;

    //Move the dot left or right
    mPosX -= mVelX;
    shiftColliders();

    //If the dot collided or went too far to the left or right
    if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH >= SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
    {
		if (!enemyBullets.empty())
		{
			enemyBullets.pop_back();
		}
    }

    //Move the dot up or down
    mPosY += mVelY;
	shiftColliders();

    //If the dot collided or went too far up or down
    if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT >= SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
    {
        if (!enemyBullets.empty())
		{
			enemyBullets.pop_back();
		}
    }
}
예제 #11
0
파일: Pacman.cpp 프로젝트: pisc3s/Pacman
//Eat pac-dots and the power pallets
void Pacman::eat() {
	for (unsigned int row = 0; row < map->size(); row++) {
		for (unsigned int col = 0; col < (*map)[row].size(); col++) {
			//Detect is it collided with the pac-dots
			//Add 100 score if true and erase the dot from the map
			if ((*map)[row][col] == "o") {
				if (checkCollision((col * 30) + 15, (row * 30) + 15, 0, 0)) {
					Mix_PlayChannel(-1, sound_food, 0);
					(*map)[row][col] = " ";
					score += 100;
					return;
				}
			}

			//Detect is it collided with the power pallets
			//Add 500 score if true and erase the power palletes from the map
			if ((*map)[row][col] == "p") {
				if (checkCollision((col * 30) + 15, (row * 30) + 15, 0, 0)) {
					Mix_PlayChannel(-1, sound_powerup, 0);
					(*map)[row][col] = " ";
					score += 500;
					setPowerUp(true);
					return;
				}
			}
		}
	}
}
예제 #12
0
파일: hero.cpp 프로젝트: Adriqun/C-CPP-SDL2
void Hero::motion( SDL_Rect rect )
{
    /* Dla kazdego warunku - jesli uzytkownik kliknal LEFT to postac porusza sie w lewo z okreslona predkoscia, itd... */
    if( key[ SDL_SCANCODE_LEFT ] )
    {
        if( x > 0 )
        {
            x -= speed;
        }

    /* Dla kazdego warunku - jesli wystapila kolizja to cofa postac jeszcze przed wyrenderowaniem calej sytuacji */
        if( checkCollision( rect ) )
        {
            x += speed;
        }
    }

    else if( key[ SDL_SCANCODE_RIGHT ] )
    {
        if( x < 800 - texture.getWidth() )
        {
            x += speed;
        }

        if( checkCollision( rect ) )
        {
            x -= speed;
        }
    }

    if( key[ SDL_SCANCODE_UP ] )
    {
        if( y > 104 )
        {
            y -= speed;
        }

        if( checkCollision( rect ) )
        {
            y += speed;
        }
    }

    else if( key[ SDL_SCANCODE_DOWN ] )
    {
        if( y < 600 - texture.getHeight() )
        {
            y += speed;
        }

        if( checkCollision( rect ) )
        {
            y -= speed;
        }
    }
}
예제 #13
0
void LevelPlaySelect::render(ImageManager& imageManager, SDL_Renderer &renderer){
	//First let the levelselect render.
    LevelSelect::render(imageManager,renderer);
	
	int x,y,dy=0;
	
	//Get the current mouse location.
	SDL_GetMouseState(&x,&y);

	if(levelScrollBar)
		dy=levelScrollBar->value;
	//Upper bound of levels we'd like to display.
	y+=dy*64;
	
	SDL_Rect mouse={x,y,0,0};
	
	//Show currently selected level (if any)
	if(selectedNumber!=NULL){
        selectedNumber->show(renderer, 0);
		
        levelInfoRender.render(renderer);
		
        //Only show the replay button if the level is completed (won).
		if(selectedNumber->getNumber()>=0 && selectedNumber->getNumber()<levels->getLevelCount()) {
			if(levels->getLevel(selectedNumber->getNumber())->won){
				if(!bestTimeFilePath.empty()){

					SDL_Rect r={0,0,32,32};
                    const SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-130,372,32};
					
					if(checkCollision(box,mouse)){
						r.x=32;
                        SDL_SetRenderDrawColor(&renderer, 0xFF,0xCC,0xCC,0xCC);
                        SDL_RenderDrawRect(&renderer, &box);
					}
                    const SDL_Rect dstRect = {SCREEN_WIDTH-80,SCREEN_HEIGHT-130,r.w,r.h};
                    SDL_RenderCopy(&renderer,playButtonImage.get(),&r, &dstRect);
				}
				
				if(!bestRecordingFilePath.empty()){
					SDL_Rect r={0,0,32,32};
                    const SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-98,372,32};
					
					if(checkCollision(box,mouse)){
                        r.x=32;
                        SDL_SetRenderDrawColor(&renderer, 0xFF,0xCC,0xCC,0xCC);
                        SDL_RenderDrawRect(&renderer, &box);
					}
					
                    const SDL_Rect dstRect = {SCREEN_WIDTH-80,SCREEN_HEIGHT-98,r.w,r.h};
                    SDL_RenderCopy(&renderer,playButtonImage.get(),&r, &dstRect);
				}
			}
		}
	}
}
예제 #14
0
파일: Pacman.c 프로젝트: uysalere/pacman
/* refresh pacmans position */
void refreshPacman(void) {
  checkCollision();

  updatePacmanPosition();
  updatePacmanMovement();
  checkPacmanMovement();

  addScores();
  checkCollision();
}
예제 #15
0
파일: Game.cpp 프로젝트: TioMinho/CarMayhem
//Método principal para atualização do game em tempo real
void Game::gameUpdate(){
	//Limite de Frame Rate
	gameWindow.setFramerateLimit(60);

	//Checa se algum dos players completou as 3 voltas
	isRaceOver();

	//Verifica se a tecla ESC é pressionada, abrindo o menuPause
	renderPause();
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
		menuPause.abrirMenu();

	//Toca a música que será reproduzida durante a corrida
	raceBGM.playMusic();
	raceBGM.setVolume(100);

	//Ativa os métodos de entrada de keyboard para os controles de ambos os players
	player[0].ativarMovimentos(0);
	player[1].ativarMovimentos(1);

	//Checa todas as colisões possíveis dentro da partida para cada Player
	checkCollision(0);
	checkCollision(1);

	//Checa se os players estão no sentido correto da pista (caso eles percorram ao contrário), seus
	//carros explodirão
	player[0].checarSentido();
	player[1].checarSentido();

	//Checa durante a partida quando a linha de chegada é ultrapassada
	checkLap();
	
	//Centralizando cada câmera em seu respectivo player
	player[0].centralizarCamera();
	player[1].centralizarCamera();

	//Renderizações na tela do Player1
	gameWindow.setView(player[0].getCamera());
	renderMap();
	gameWindow.draw(player[0].getSprite());
	gameWindow.draw(player[1].getSprite());
	renderProjeteis();
	renderGUI(0);
	
	//Renderizações na tela do Player 2
	gameWindow.setView(player[1].getCamera());
	renderMap();
	gameWindow.draw(player[1].getSprite());
	gameWindow.draw(player[0].getSprite());
	renderProjeteis();
	renderGUI(1);

	gameWindow.display();
	gameWindow.clear();
}
예제 #16
0
파일: Game.cpp 프로젝트: wmolicki/riverride
bool CGame::standingOnCollapsingBridge(SDL_Rect A)
{
	for (std::list<std::unique_ptr<CEnemy>>::iterator it = enemyList.begin(); it != enemyList.end(); it++)
	{
		//checks all bridges on screen, and returns whether A is standing on dead brigde
		if ((*it)->type == BRIDGE && checkCollision((*it)->getBox(), plane.getCamera()) && !(*it)->isAlive())
		{
			return checkCollision(A, (*it)->getBox());
		}
	}
	return false;
}
예제 #17
0
/***********************************************************************
; Name:         checkCharHitChar
; Description:  This function checks for collisions between the attack
;								of one character and the position of another character.
;								It doesn't matter which character calls the	function,
;								it performs correctly.
;***********************************************************************/
char checkCharHitChar(struct character *self, char attackx, char attacky, unsigned char attackw, unsigned char attackh)
{
    char ret = 0;
		if (self->player == 0)
		{
				ret = checkCollision(attackx, attacky, attackw, attackh, player1.x, player1.y, player1.framew, player1.frameh);
		}
		else
		{
				ret = checkCollision(attackx, attacky, attackw, attackh, player0.x, player0.y, player0.framew, player0.frameh);
		}
		return ret;
}
예제 #18
0
bool ShapeRay::checkCollision( ShapeRect const *const other ) const
{
	// TODO: Do this properly (not with ray approximation
	ShapeRay bltr;
	bltr.pos = other->getCorner( diBOTTOMLEFT );
	bltr.target = other->getCorner( diTOPRIGHT );
	ShapeRay brtl;
	brtl.pos = other->getCorner( diBOTTOMRIGHT );
	brtl.target = other->getCorner( diTOPLEFT );
	if ( checkCollision( &bltr ) || checkCollision( &brtl ) )
		return true;
	return false;
}
예제 #19
0
void PlayState::update()
{
	if (TheInputHandler::Instance()->isKeyDown(SDL_SCANCODE_ESCAPE))
	{
		TheGame::Instance()->getStateMachine()->pushState(new PauseState());
	}
	for (int i = 0; i < m_gameObjects.size(); i++)
	{
		m_gameObjects[i]->update();
	}
	//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->
	//if (m_gameObjects[0]->g);
	//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getBullet()->setBulletX(dynamic_cast<SDLGameObject*>(m_gameObjects[0])->getPlayer()->getPosition().getX());
	//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getVIBullet()[0]->setBulletX(dynamic_cast<SDLGameObject*>(m_gameObjects[0])->getPlayer()->getPosition().getX());
	//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getPlay
	for (int i = 2; i < m_gameObjects.size(); i++)
	{
		if (checkCollision(
			dynamic_cast<SDLGameObject*>(m_gameObjects[1]),
			dynamic_cast<SDLGameObject*>(m_gameObjects[i])))
		{

			std::string textureID = "bullet";
			std::string typeID = "Bullet";


			//pGameObject->load(new LoaderParams(x, y, width, height, textureID, numFrames, callbackID, animSpeed));

			m_gameObjects.erase(m_gameObjects.begin() + i);
			//m_gameObjects.erase(m_gameObjects.begin() + 1);

			//GameObject* pGameObject = TheGameObjectFactory::Instance()->create(typeID);
			m_gameObjects[1] = TheGameObjectFactory::Instance()->create(typeID);;
			m_gameObjects[1]->load(new LoaderParams(200, 350, 21, 21, textureID, 1, 0, 1));

			//m_gameObjects.push_back(pGameObject);
			//std::string _textID = "Bullet";
			//(x, y, width, height, textureID, numFrames, callbackID, animSpeed))
			//m_gameObjects[1]->load(LoaderParams(100, 100, 100, 100, _textID, 1, 0, 0));
			//StateParser stateParser;
			//stateParser.parseState("text.xml", s_playID, &m_gameObjects, &m_textureIDList);
		}
		if (checkCollision(
			dynamic_cast<SDLGameObject*>(m_gameObjects[0]),
			dynamic_cast<SDLGameObject*>(m_gameObjects[i])))
		{
			TheGame::Instance()->setState(State::GameOver);
		}
	}
}
예제 #20
0
void Bomb::explode()
{
	_explodeTime = Director::getInstance()->getTotalFrames();
	_isFire = true;
	_isRemote = false;
	_tick = 9999;
	GameSounds::Instance().playSound(ES_BOMB, false);
	if (_player)
	{
		_player->explodeBomb();
		_player = nullptr;
	}
	if (_brick)
	{
		_brick->explodeBomb();
		_brick = nullptr;
	}
	animate(_sprite, FCENTER);
	checkCollision(_sprite);
	_fires.push_back(_sprite);
	for (auto p : sPoints)
	{
		for (int i = 1; i <= _size; i++)
		{
			FireType type = i == _size ? FTAIL : FBODY;
			auto sprite = Sprite::createWithSpriteFrameName(typeStr[type] + "_1.png");
			sprite->setPosition(_sprite->getPosition() + p * i);

			Direction dir = pointToDir(p);
			if (dir == RIGHT)
			{
				sprite->setRotation(90);
			}
			else if (dir == LEFT)
			{
				sprite->setRotation(270);
			}
			else if (dir == DOWN)
			{
				sprite->setFlippedY(true);
			}

			animate(sprite, type);
			if (checkCollision(sprite)) break;
			_fires.push_back(sprite);
			addChild(sprite);
		}
	}
}
예제 #21
0
void MyRect::move()
{
    bool isColliding= checkCollision();
    //move down
    if(isColliding==false){
        if(pos().y()< 600){
            setPos(x(),y()+30);
            //setPos(x(),600);
            //qDebug()<<"position change";
        }
        else{
            qDebug()<<"count:"<<count;
            points+=2;
            myGame.printText(QString("Nice 2 Points: "),700,count,1.5);
            myGame.printText(QString::number(points),900,count,1.5);
            count+=50;

            if(count>=500){
                count=30;
            }
            isRowFilled(pos().y()+15);
            //qDebug()<<"rim";
            time->stop();
            myGame.spawn();
        }
    }
    else if(pos().y() < 29 &&isColliding){
        qDebug()<<"lose";
        scene()->clear();
        //        scene()->removeItem(this);
        //        delete this;
        QString yolo = QString ("You Lose");
        myGame.printText(yolo,425,250,3);
    }
    else if(checkCollision()){
        points+=2;
        myGame.printText(QString("Nice 2 Points: "),700,count,1.5);
        myGame.printText(QString::number(points),900,count,1.5);
        count+=50;
        if(count>=500){
            count=30;
        }

        isRowFilled(pos().y()+15);
        qDebug()<<"spawning";
        time->stop();
        myGame.spawn();
    }
}
예제 #22
0
void Bullet::update(){
    float deltaX = 0;
    float deltaY = 0;

    deltaX = sin(this->angle) * this->moveSpeed;
    deltaY = -cos(this->angle) * this->moveSpeed;

    if(!inShop){
        if(this->playerShot){
            for(int i = 0; i < MAX_ZOMBIES; i++){
                if(zombieList[i] != NULL && zombieList[i]->checkActive()){
                    if(checkCollision(this->posX, this->posY, zombieList[i]->posX, zombieList[i]->posY, this->width, this->height, zombieList[i]->width, zombieList[i]->height)){
                        zombieList[i]->health -= this->damage;
                        this->active = false;
                    }
                }
            }
        }else{
            if(checkCollision(this->posX, this->posY, playerCenterX, playerCenterY, this->width, this->height, playerWidth, playerHeight)){
                playerHealth -= this->damage;
                this->active = false;
            }
        }

        if(isPassable(this->posX+deltaX, this->posY, this->width, this->height, deltaX, deltaY)){
            this->posX += deltaX;
        }else{
            this->active = false;
        }

        if(isPassable(this->posX, this->posY+deltaY, this->width, this->height, deltaX, deltaY)){
            this->posY += deltaY;
        }else{
            this->active = false;
        }
    }else{
        if(this->posX+deltaX >= 0 && this->posX+deltaX + this->width < 400 && this->posY >= 0 && this->posY + this->height < 400){
            this->posX += deltaX;
        }else{
            this->active = false;
        }
        if(this->posX >= 0 && this->posX + this->width < 400 && this->posY+deltaY >= 0 && this->posY+deltaY + this->height < 400){
            this->posY += deltaY;
        }else{
            this->active = false;
        }
    }
}
예제 #23
0
파일: Item.cpp 프로젝트: 7ung/NMGAME
float Item::checkCollision(BaseObject* object, float dt)
{
	auto collisionBody = (CollisionBody*)_listComponent["CollisionBody"];
	auto objeciId = object->getId();
	eDirection direction;

	if (collisionBody->checkCollision(object, direction, dt))
	{
		if (objeciId == eID::LAND || objeciId == eID::BRIDGE)		// => ??
		{
			if (this->getVelocity().y > 0)
				return 0.0;
			if (direction == eDirection::TOP)
			{
				auto gravity = (Gravity*)this->_listComponent["Gravity"];
				gravity->setStatus(eGravityStatus::SHALLOWED);
				gravity->setGravity(VECTOR2ZERO);

				auto move = (Movement*) this->_listComponent["Movement"];
				move->setVelocity(VECTOR2ZERO);
			}
		}
		if (objeciId == eID::BILL)
		{
			this->setStatus(eStatus::DESTROY);
			((Bill*)object)->changeBulletType(this->_type);
		}
	}
	return 0.0f;
}
예제 #24
0
void Layer::handleCollisions()
{
	std::vector<Projectile*>& pProjectiles = TheProjectileManager::Instance()->getProjectiles();

	for (int i = 0; i < pProjectiles.size(); i++)
	{ //Loop though all bullets
		for (int j = 0; j < mGameObjects.size(); j++)
		{
			SDLGameObject* object = dynamic_cast<SDLGameObject*>(mGameObjects.at(j));
			if ((pProjectiles.at(i))->getTag() != object->getTag())
			{
				if (checkCollision(pProjectiles.at(i), object))
				{
					TheProjectileManager::Instance()->destroyProjectile(pProjectiles.at(i));
					dynamic_cast<Ship*>(object)->damage(1);
					if (!dynamic_cast<Ship*>(object)->isAlive())
					{ //Ship is dead
						dynamic_cast<Ship*>(object)->clean();
						delete object;
						mGameObjects.erase(mGameObjects.begin() + j);
						j--;
					}
					
				}
			}
		}
	}
}
예제 #25
0
파일: game.c 프로젝트: ex/blocks
/* Hard drop */
static void dropTetromino(StcGame *game) {
#ifdef STC_SHOW_GHOST_PIECE
    /* Shadow has already calculated the landing position. */
    game->fallingBlock.y += game->shadowGap;

    /* Force lock. */
    moveTetromino(game, 0, 1); 

    /* Update score */
    if (game->showShadow) {
        game->stats.score += (long)(SCORE_2_FILLED_ROW * (game->stats.level + 1) 
                                    / SCORE_DROP_WITH_SHADOW_DIVISOR);
    }
    else {
        game->stats.score += (long)(SCORE_2_FILLED_ROW * (game->stats.level + 1) 
                                    / SCORE_DROP_DIVISOR);
    }
#else
    int y = 0;
    /* Calculate number of cells to drop */
    while (!checkCollision(game, 0, ++y));
    moveTetromino(game, 0, y - 1);
    moveTetromino(game, 0, 1); /* Force lock */

    /* Update score */
    game->stats.score += (long)(SCORE_2_FILLED_ROW * (game->stats.level + 1) 
                                / SCORE_DROP_DIVISOR);
#endif
}
예제 #26
0
bool Player::touchesLevelObject(SDL_Rect box, std::list <LevelObject> levelObjects)
{
	std::list<LevelObject>::iterator it = levelObjects.begin();
	while (it != levelObjects.end())
	{
		if (it->Type() == LevelObjectType::PLATFORM)
		{
			if ((box.y + 4) <= it->LevelObjectBox().y)
			{
				if (checkCollision(box, it->LevelObjectBox()))
				{
					if (it->Flip())
						playerBox.x -= 1;
					else if (!it->Flip())
						playerBox.x += 1;

					return true;
				}
			}
		}

		it++;
	}

	return false;
}
예제 #27
0
void Robot::update(int deltaTime)
{
	Vector3 v = velocity * float(deltaTime);
  translate(v);
	if (!checkCollision())
	{
		translate(-v);
		setRandDirection();
	}
  
  if (shotCooldown)
  {
    shotTimer += deltaTime;
    if (shotTimer >= shotTimerMax)
    {
      shotTimer = 0;
      shotCooldown = false;
}
  }
  Room * playerRoom = Game::instance->roomAt(Game::instance->player->getWorldPos());
  Room * room = Game::instance->roomAt(getWorldPos());
  if (playerRoom == room)
  {
    Vector3 dir = Game::instance->player->getWorldPos() - getWorldPos();
    float ang = atan2f(dir.z, dir.x);
    ang *= (1.0f / DEG2RAD);
    setRotation(Vector3(0, -ang + 90, 0));
    if (!shotCooldown) {
      spawnBullet();
      shotCooldown = true;
    }
  }
}
void gameClass::moveProjectiles(float deltaTime)
{
	for (int i = 0; i < projectiles.size(); i++) {

		int dirX, dirY;
		projectiles[i].getDirection(dirX, dirY);

		glm::vec2 oldPos = projectiles[i].tile.getPos();
		float velocity = projectiles[i].getSpeed() * deltaTime;
		
		glm::vec2 newPos = { velocity * dirX, velocity * dirY };
		projectiles[i].tile.adjustPos(newPos);
		
		bool eraseFlag = false;

		*activeProjectile = projectiles[i];
		if (checkCollision(activeProjectile, eraseFlag)  ||  !projectiles[i].tile.isOnScreen(renderingPort)) {
			projectiles.erase(projectiles.begin() + i);			
		}
		else {
			projectiles[i].increaseAnimationTime(deltaTime);
			if (projectiles[i].getAnimationTime() >= Constants::animationFrameTime) {
				projectiles[i].increaseIndex();
				projectiles[i].resetAnimationTime();
			}
		}
		
	}
}
예제 #29
0
void cubiverse::VoxelEditor::render(float playerX, float playerY, float playerZ) {
	//Zeichne einen Kreis
	float x = 0.0f;
	float z = 0.0f;
	float radius = 10.0f;

	glBegin(GL_POLYGON);
	for( double theta = 0.0; theta < M_PI; theta +=  M_PI / 360.0 ) {
		x =  ( cos( theta ) * radius );
		z =  ( sin( theta ) * radius);
		glVertex3f( x, 20.0f, z );
	}

	vaEngine::Vector coll = checkCollision(playerX, playerY, playerZ);
	//if(coll->y != playerY) {
	//	Cube::pointer_t newCube = boost::make_shared<Cube>(1);
	//	voxels[0][make_pair(coll->x,make_pair(coll->y,coll->z))] = newCube;
		
	//}
		
	//Und dann die Meshs
	//for(int mesh = 0; mesh < meshs.size(); mesh++)
		//meshs[mesh]->render();

	//if(coll->y != playerY) {
	//	delVoxel(coll->x, coll->y, coll->z, 0);
		
	//}
}
예제 #30
0
const std::vector<BoundingShape*> CollisionDetect::checkAgainstGroup(
        BoundingShape* bounding,
        const std::string& group )
{
    // the list of boundings collisions are occurring with
    std::vector<BoundingShape*> collisions;

    // iterate over detectors in the group
    for ( std::vector<CollisionDetector*>::iterator detector =
          m_groups[group].begin(); detector != m_groups[group].end();
          ++detector )
    {
        // iterate over the boundings in the detector
        for ( std::vector<std::unique_ptr<BoundingShape>>::iterator bd =
             (*detector)->m_boundings.begin();
             bd != (*detector)->m_boundings.end(); ++bd )
        {
            // check collision
            if ( checkCollision( bounding, bd->get() ) )
            {
                // a collision was found, record it in the list
                collisions.push_back( bd->get() );
            }
        }
    }

    return collisions;
}