コード例 #1
0
ファイル: MainGame.cpp プロジェクト: missionfmb/SFML-Bengine
void MainGame::initLevel() {
    // Level 1
    m_levels.push_back(new Level("Levels/level1.txt"));
    m_currentLevel = 0;

    m_player = new Player();
    m_player->init(PLAYER_SPEED, m_levels[m_currentLevel]->getStartPlayerPos(), &m_inputManager, &m_camera, &m_grid);

    m_grid.init(m_levels[m_currentLevel]->getWidth(), m_levels[m_currentLevel]->getHeight(), m_bloodParticleBatch);

    std::mt19937 randomEngine;
    randomEngine.seed(time(nullptr));

    std::uniform_int_distribution<int> randX(2, m_levels[m_currentLevel]->getWidth() - 2);
    std::uniform_int_distribution<int> randY(2, m_levels[m_currentLevel]->getHeight() - 2);

    // Add all the random humans
    m_totalHumans = m_levels[m_currentLevel]->getNumHumans();
    for (int i = 0; i < m_levels[m_currentLevel]->getNumHumans(); i++) {
        m_grid.addHuman(glm::vec2(randX(randomEngine) * TILE_WIDTH, randY(randomEngine) * TILE_WIDTH));
    }

    // Add the zombies
    const std::vector<glm::vec2>& zombiePositions = m_levels[m_currentLevel]->getZombieStartPositions();
    m_totalZombies = m_levels[m_currentLevel]->getZombieStartPositions().size();
    for (int i = 0; i < zombiePositions.size(); i++) {
        m_grid.addZombie(zombiePositions[i]);
    }

    // Set up the players guns
    const float BULLET_SPEED = 20.0f;
    m_player->addGun(new Gun("Magnum", 10, 1, 5.0f, 30, BULLET_SPEED, m_audioEngine.loadSoundEffect("Sound/shots/pistol.wav")));
    m_player->addGun(new Gun("Shotgun", 30, 12, 20.0f, 4, BULLET_SPEED, m_audioEngine.loadSoundEffect("Sound/shots/shotgun.wav")));
    m_player->addGun(new Gun("MP5", 2, 1, 10.0f, 20, BULLET_SPEED, m_audioEngine.loadSoundEffect("Sound/shots/cg1.wav")));
}
コード例 #2
0
ファイル: MainGame.cpp プロジェクト: nerososft/zombieWar
void MainGame::initLevel(){
	//第一关地图
	_levels.push_back(new Level("Levels/level1.nmap"));

	_currentLevel = 0;
	std::map<std::string, NeroEngine::SoundEffect> playerSoundMap;
	playerSoundMap["zombie"] = _audioEngine.loadSoundEffect("Sound/zombie.mp3");
	playerSoundMap["changeGun"] = _audioEngine.loadSoundEffect("Sound/oog/changeGun.ogg");
	//playerSoundMap["walk"] = _audioEngine.loadSoundEffect("Sound/oog/walk.ogg");
	_player = new Player();

	_player->init(PLAYER_SPEED, 
		_levels[_currentLevel]->getPlayerPos(),
		&_inputManager,&_camera,&_bullets,
		playerSoundMap
		);
 
	_humans.push_back(_player);

	std::mt19937 randomEngine;
	randomEngine.seed(time(nullptr));
	std::cout <<"地图长度:"<<(_levels[_currentLevel]->getWidth() - 1)*TILE_WIDTH << std::endl;
	std::cout <<"地图宽度:"<< (_levels[_currentLevel]->getHeight() - 1)*TILE_WIDTH << std::endl;

	//注意换行符和空行
	std::uniform_int_distribution<int> randX(2,_levels[_currentLevel]->getWidth()-2);
	std::uniform_int_distribution<int> randY(2, _levels[_currentLevel]->getHeight() - 2);

	
	std::cout <<"人类:"<< _levels[_currentLevel]->getNumHuman()<<std::endl;
	//添加人类
	for (int i = 0; i < _levels[_currentLevel]->getNumHuman(); i++){
		_humans.push_back(new Human);
		
		
		_miniMap.addAgent();
		_miniMap.getMinimapAgent()[i]->init(_bloodColor,_player->getAgentPos()+glm::vec2(10,10));
		
		
		glm::vec2 pos(randX(randomEngine)*TILE_WIDTH, randY(randomEngine)*TILE_WIDTH);
		_humans.back()->init(HUMAN_SPEED,pos);
	}
	const std::vector<glm::ivec2>& zombiePositions = _levels[_currentLevel]->getZombiesPositions();
	//添加僵尸
	for (int i = 0; i <zombiePositions.size(); i++){
		_zombies.push_back(new Zombie);
		_zombies.back()->init(ZOMBIE_SPEED, zombiePositions[i]);
	}
	//添加枪
	const float BULLET_SPEED = 10.0f;
	_player->addGun(new Gun("沙漠之鹰", 30, 1, 0.0f, 20, BULLET_SPEED, _audioEngine.loadSoundEffect("Sound/oog/tuizi.mp3")));
	_player->addGun(new Gun("雷蛇", 60, 10, 0.6f, 30, BULLET_SPEED,_audioEngine.loadSoundEffect("Sound/oog/M4_Head1.ogg")));
	_player->addGun(new Gun("死亡之眼", 5, 2, 0.03f, 0.1, BULLET_SPEED, _audioEngine.loadSoundEffect("Sound/oog/M4_Auto3.ogg")));
	_player->addGun(new Gun("辐射", 8, 8, 0.3f, 0.1, BULLET_SPEED, _audioEngine.loadSoundEffect("Sound/oog/M4_Tail1.ogg")));


	_miniMap.init(_camera.convertScreenToWorld(glm::vec2(300, 100)),_bloodColor, NeroEngine::ResourceManager::getTexture("Textures/blood.png"));
}
コード例 #3
0
ファイル: MainGame.cpp プロジェクト: Skitzafreak/ZombieGame
void MainGame::initLevel() {
    // Level 1
    _levels.push_back(new Level("Levels/level1.txt"));
    _currentLevel = 0;

    _player = new Player();
    _player->init(PLAYER_SPEED, _levels[_currentLevel]->getStartPlayerPos(), &_inputManager, &_camera, &_bullets);

    _humans.push_back(_player);

    std::mt19937 randomEngine;
    randomEngine.seed(time(nullptr));

    std::uniform_int_distribution<int> randX(2, _levels[_currentLevel]->getWidth() - 2);
    std::uniform_int_distribution<int> randY(2, _levels[_currentLevel]->getHeight() - 2);


	//Add ammo caches
	const std::vector<glm::vec2>& ammoPositions = _levels[_currentLevel]->getAmmoStartPositions();
	for (int i = 0; i < ammoPositions.size(); i++)
	{
		_ammo.push_back(new Ammo);
		_ammo.back()->init(ammoPositions[i]);
	}

	//Add powerUP tokens/Upgrades
	const std::vector<glm::vec2>& powerUPPositions = _levels[_currentLevel]->getPowerUPStartPosition();
	for (int i = 0; i < powerUPPositions.size(); i++)
	{
		_powerUPs.push_back(new PowerUP);
		_powerUPs.back()->init(powerUPPositions[i]);
	}

    // Add all the random humans
    for (int i = 0; i < _levels[_currentLevel]->getNumHumans(); i++) {
        _humans.push_back(new Human);
        glm::vec2 pos(randX(randomEngine) * TILE_WIDTH, randY(randomEngine) * TILE_WIDTH);
        _humans.back()->init(HUMAN_SPEED, pos);
    }

    // Add the zombies
    const std::vector<glm::vec2>& zombiePositions = _levels[_currentLevel]->getZombieStartPositions();
    for (int i = 0; i < zombiePositions.size(); i++) {
        _zombies.push_back(new Zombie);
        _zombies.back()->init(ZOMBIE_SPEED, zombiePositions[i]);
    }




    // Set up the players guns
    const float BULLET_SPEED = 20.0f;
    _player->addGun(new Gun("Magnum", 10, 1, 0.01f, 30, BULLET_SPEED, 100, 1));
    _player->addGun(new Gun("Shotgun", 30, 12, 0.2f, 4, BULLET_SPEED, 12*10, 1));
    _player->addGun(new Gun("MP5", 2, 1, 0.1f, 20, BULLET_SPEED, 250, 1));
}
コード例 #4
0
ファイル: AsteroidGame.cpp プロジェクト: Untamedhawk/Comp3501
///////////////////////////
//Public Helper Functions//
///////////////////////////
Ogre::Vector3 AsteroidGame::createVector3InRange(Ogre::Vector3 aPositiveBounds, Ogre::Vector3 aNegativeBounds) {
	/*
	Ogre::Vector3 r = Ogre::Vector3((float)((aPositiveBounds.x - aNegativeBounds.x) * ( (float)rand() / (float)RAND_MAX ) + aNegativeBounds.x),
									(float)((aPositiveBounds.y - aNegativeBounds.y) * ( (float)rand() / (float)RAND_MAX ) + aNegativeBounds.y),
									(float)((aPositiveBounds.z - aNegativeBounds.z) * ( (float)rand() / (float)RAND_MAX ) + aNegativeBounds.z));
	return r;
	*/

	std::mt19937 rng;
	rng.seed(std::random_device()());

	std::uniform_int_distribution<int> randX ((int)aNegativeBounds.x, (int)aPositiveBounds.x);
	std::uniform_int_distribution<int> randY ((int)aNegativeBounds.y, (int)aPositiveBounds.y);
	std::uniform_int_distribution<int> randZ ((int)aNegativeBounds.z, (int)aPositiveBounds.z);		

	return Ogre::Vector3((float)randX(rng), (float)randY(rng), (float)randZ(rng));
}
コード例 #5
0
ファイル: MainGame.cpp プロジェクト: Snorflake/Skengine
void MainGame::initLevel()
{
	_levels.push_back(new Level("Levels/level1.txt"));
	_currentLevel = 0;

	_player = new Player();
	_player->init(4, _levels[_currentLevel]->getStartPlayerPos(), &_inputManager);
	//shit. only one texture is being drawn.

	_humans.push_back(_player);
	std::mt19937 randomEngine;
	randomEngine.seed(time(nullptr));
	std::uniform_int_distribution<int> randX(1, _levels[_currentLevel]->getWidth() - 1);
	std::uniform_int_distribution<int> randY(1, _levels[_currentLevel]->getHeight() - 1);
	const float HUMAN_SPEED = 1.f;
	for (int i = 0; i < _levels[_currentLevel]->getNumHumans(); i++)
	{
		_humans.push_back(new Human);
		glm::vec2 pos(randX(randomEngine) * TILE_WIDTH, randY(randomEngine) * TILE_WIDTH);
		_humans.back()->init(HUMAN_SPEED, pos);
	}
}
コード例 #6
0
ファイル: MainGame.cpp プロジェクト: fluier/ZombieGame
void MainGame::initLevel() {
	// Level 1
	m_levels.push_back(new Level("Levels/level2.txt"));
	m_currentLevel = 0;

	m_player = new Player();
	m_player->init(PLAYER_SPEED, m_levels[m_currentLevel]->getStartPlayerPos(), &m_inputManager, &m_camera, &m_bullets);

	m_humans.push_back(m_player);

	std::mt19937 randomEngine;
	randomEngine.seed(time(nullptr));

	std::uniform_int_distribution<int> randX(2, m_levels[m_currentLevel]->getWidth() - 2);
	std::uniform_int_distribution<int> randY(2, m_levels[m_currentLevel]->getHeight() - 2);

	// Add all the random humans
	for (int i = 0; i < m_levels[m_currentLevel]->getNumHumans(); i++) {
		m_humans.push_back(new Human);
		glm::vec2 pos(randX(randomEngine) * TILE_WIDTH, randY(randomEngine) * TILE_WIDTH);
		m_humans.back()->init(HUMAN_SPEED, pos);
	}

	// Add the zombies
	const std::vector<glm::vec2>& zombiePositions = m_levels[m_currentLevel]->getZombieStartPositions();
	for (auto i = 0; i < zombiePositions.size(); i++) {
		m_zombies.push_back(new Zombie);
		m_zombies.back()->init(ZOMBIE_SPEED, zombiePositions[i]);
	}

	// Set up the players guns
	const float BULLET_SPEED = 20.0f;
	m_player->addGun(new Gun("Magnum", 200, 1, 0.1f, 30, BULLET_SPEED, m_audioEngine.loadSoundEffect("Sound/shots/pistol.wav")));
	m_player->addGun(new Gun("Shotgun", 500, 100, 1.0f, 4, BULLET_SPEED, m_audioEngine.loadSoundEffect("Sound/shots/shotgun.wav")));
	m_player->addGun(new Gun("MP5", 10, 1, 0.1f, 30, BULLET_SPEED, m_audioEngine.loadSoundEffect("Sound/shots/cg1.wav")));
}
コード例 #7
0
ファイル: D.c プロジェクト: jpbat/aed2011
void worker(char* word)
{
	nodePtr aux;
	int i, size;

	size = strlen(word);

	for (i=0 ; i<size ; i++)
		word[i]=tolower(word[i]);
	
	if ( searchNumber(word) == 0 )
	{
		aux = createNode(word, randX());
		addNode(list, aux, n_lvl);
	}
}
コード例 #8
0
ファイル: Hunter.cpp プロジェクト: Rubiks14/LudumDare33Entry
std::vector<Projectile> Hunter::shootBullets(long currentTime)
{
	std::mt19937 randEng;
	randEng.seed(SDL_GetTicks());
	std::uniform_real_distribution<float> randAngle(-4.0, 4.0);
	std::uniform_int_distribution<int> randX(0, 10);
	std::vector<Projectile> bullets;
	if (currentTime >= shootTime)
	{
		for (int i = 0; i < 5; i++)
		{
			MoveableObject newbulletBody;
			double angle = this->body->getDirection() + randAngle(randEng);
			newbulletBody.init(this->body->getPosition(), angle, 20, 20);
			Projectile bullet;
			bullet.init(newbulletBody, TYPE_BULLET, 600, "bulletTexture");
			bullets.push_back(bullet);
		}
		shootTime = currentTime + shootInterval;
	}
	status = WELL;
	action = TRACK;
	return bullets;
}
コード例 #9
0
ファイル: MainGame.cpp プロジェクト: IAnonymousI/BallGame
void MainGame::initBalls() {

	// Initializes the grid
	_grid = std::make_unique<Grid>(m_screenWidth, m_screenHeight, CELL_SIZE);
	

#define ADD_BALL(p, ...) \
    totalProbability += p; \
    possibleBalls.emplace_back(__VA_ARGS__);

    // Number of balls to spawn
    const int NUM_BALLS = 5000;

    // Random engine stuff
    std::mt19937 randomEngine((unsigned int)time(nullptr));
    std::uniform_real_distribution<float> randX(0.0f, (float)m_screenWidth);
    std::uniform_real_distribution<float> randY(0.0f, (float)m_screenHeight);
    std::uniform_real_distribution<float> randDir(-1.0f, 1.0f);

    // Add all possible balls
    std::vector <BallSpawn> possibleBalls;
    float totalProbability = 0.0f;

	std::uniform_real_distribution<float> r1(2.0f, 6.0f);
	std::uniform_int_distribution<int> r2(0, 255);

    // Adds the balls using a macro
    ADD_BALL(20.0f, Engine::Color(255, 255, 255, 255),
             2.0f, 1.0f, 0.1f, 7.0f, totalProbability);
    ADD_BALL(10.0f, Engine::Color(0, 0, 255, 255),
             3.0f, 2.0f, 0.1f, 3.0f, totalProbability);
	ADD_BALL(1.0f, Engine::Color(255, 0, 0, 255),
			5.0f, 4.0f, 0.0f, 0.0f, totalProbability);
	for (int i = 0; i < 10000; i++){
		ADD_BALL(1.0f, Engine::Color(r2(randomEngine), r2(randomEngine), r2(randomEngine), 255), r1(randomEngine), r1(randomEngine), 0.0f, 0.0f, totalProbability);
	}

    // Random probability for ball spawn
    std::uniform_real_distribution<float> spawn(0.0f, totalProbability);

    // Small optimization that sets the size of the internal array to prevent
    // extra allocations.
    m_balls.reserve(NUM_BALLS);

    // Set up ball to spawn with default value
    BallSpawn* ballToSpawn = &possibleBalls[0];
    for (int i = 0; i < NUM_BALLS; i++) {
        // Get the ball spawn roll
        float spawnVal = spawn(randomEngine);
        // Figure out which ball we picked
        for (size_t j = 0; j < possibleBalls.size(); j++) {
            if (spawnVal <= possibleBalls[j].probability) {
                ballToSpawn = &possibleBalls[j];
                break;
            }
        }

        // Get random starting position
        glm::vec2 pos(randX(randomEngine), randY(randomEngine));

        // Hacky way to get a random direction
        glm::vec2 direction(randDir(randomEngine), randDir(randomEngine));
        if (direction.x != 0.0f || direction.y != 0.0f) { // The chances of direction == 0 are astronomically low
            direction = glm::normalize(direction);
        } else {
            direction = glm::vec2(1.0f, 0.0f); // default direction
        }

        // Add ball
        m_balls.emplace_back(ballToSpawn->radius, ballToSpawn->mass, pos, direction * ballToSpawn->randSpeed(randomEngine),
                             Engine::ResourceManager::getTexture("Textures/circle.png").id,
                             ballToSpawn->color);
		// Add the ball to the grid.
		_grid->addBall(&m_balls.back());
    }
}
コード例 #10
0
void STinsert(Item item)
{	
	insertR(head, NEW(item, randX()), lgN); 
	N++; 
}