Example #1
0
bool Map::checkCollision(Player* player, Direction direction, bool isRunning){
    int playerX = player->getX();
    int playerY = player->getY();
    int step = isRunning ? 8 : 4;
    switch(direction){
        case UP:
            playerY -= step;
        break;
        case DOWN:
            playerY += step;
        break;
        case LEFT:
            playerX -= step;
        break;
        case RIGHT:
            playerX += step;
        break;
    }
    if(checkMapBorderCollision(playerX, playerY)){
        return true;
    }else if(checkWallCollision(playerX, playerY, direction)){
        return true;
    }else{
        return false;
    }
    //Sprawdzić kolizję z NPC
}
Example #2
0
bool Enemy::wallInPath(const std::vector<wall> & w, float dir, float xPos,
                       float yPos) {
    for (int i{10}; i < 100; i += 16) {
        if (checkWallCollision(w, xPos + cos(dir) * i, yPos + sin(dir) * i)) {
            return true;
        }
    }
    return false;
}
Example #3
0
void		Nibbler::popFood( int i, std::vector<AComponent *> foodElements )
{
	int x = (rand() % (this->getWidth() - 1)+ 1);
	int y = (rand() % (this->getHeight() - 1) ) + 1;

	_food->getComponents()[i]->setPos(Vec2i( x,  y));
	if (checkBasicCollision(_food->getComponents()[i]) || checkWallCollision(_food->getComponents()[i]) || checkFoodCollision(_food->getComponents()[i], i))
		popFood(i, foodElements);
	return ;
}
Example #4
0
bool Projectile::act() {
	if(TYPE == THUNDERSHOCK && PA_GetSpriteAnimFrame(MAIN_SCREEN, num) == 44) {
		Floor f = checkFloorCollision(32, 64);
		if(f.length != 0) {
			dy = 0;
			y = f.y-64;
			PA_StartSpriteAnimEx(MAIN_SCREEN, num, 45, 47, 20, ANIM_LOOP, -1);
		}
		Wall w = checkWallCollision(32, 64);
		if(w.length != 0) dx *= -1;
	}
	else if(TYPE == THUNDERSHOCK && PA_GetSpriteAnimFrame(MAIN_SCREEN, num) >= 45 && PA_GetSpriteAnimFrame(MAIN_SCREEN, num) <= 47) {
		if(checkWallCollision(32, 64).length != 0) dx *= -1;
		if(dy == 0) {
			dy = 1;
			if(checkFloorCollision(32, 64).length == 0) {
				dy = GLOBALGRAVITY;
				PA_StartSpriteAnimEx(MAIN_SCREEN, num, 44, 44, 20, ANIM_LOOP, -1);
			}
			else dy = 0;
		}
	}
	if(TYPE == FIREBALL) {
		dy += .1;
		if(dy > GLOBALGRAVITY) dy = GLOBALGRAVITY;
		Floor f = checkFloorCollision(32, 32);
		if(f.length != 0) dy *= -1;
		Wall w = checkWallCollision(32, 32);
		if(w.length != 0) dx *= -1;
		Ceiling c = checkCeilingCollision(32, 32);
		if(c.length != 0) dy *= -1;
	}
	x += dx;
	y += dy;
	PA_SetSpriteXY(MAIN_SCREEN, num, (int)(x - display->scrollx), (int)(y - display->scrolly));
	if (x + 64 - display->scrollx < 0 || x - display->scrollx > 256 || y + 64 - display->scrolly < 0 || y - display->scrolly > 192) PA_SetSpriteXY(MAIN_SCREEN, num, -64, -64);
	time++;
	if (time > length) return true;
	return false;
}