// Making the next generation
void Population::reproduction()
{
    // Refill the population with children from the mating pool
    for( int i = 0; i < mPopulation.size(); i++ )
	{
		// Sping the wheel of fortune to pick two parents
		int m = randInt( mMatingPool.size() );
		int d = randInt( mMatingPool.size() );
		// Pick two parents
		Rocket *mom = mMatingPool[m];
		Rocket *dad = mMatingPool[d];
		// Get their genes
		DNA *momgenes = mom->getDNA();
		DNA *dadgenes = dad->getDNA();
		// Mate their genes
		DNA *child = momgenes->crossover( dadgenes );
		// Mutate their genes
		child->mutate( mMutationRate );
		// Fill the new population with the new child
		Vec2f location = Vec2f( getWindowWidth() / 2.0, getWindowHeight() + 20.0 );
		
		delete mPopulation[i]; // get rid of the old rocket
		mPopulation[i] = new Rocket( location, child, mTarget );
    }
    mGenerations++;
}
Exemple #2
0
Rocket Rocket::mate(Rocket partner)
{
    Rocket child = Rocket();
    child.setDNA(dna.crossover(partner.getDNA()));
    child.setTarget(target);
    child.setObstacles(obstacles);
    return child;
}
bool SolarSystem::launchRocket(double vPercent, double angle)
{
    if(activePlanet == NULL)
    {
        return false;
    }
    static double defaultRocketVelocity = 2500;
    Rocket* r = new Rocket(activePlanet, defaultRocketVelocity * vPercent, angle, this);
    solarObjects.push_back(r);
    r->setPos(r->x, r->y);
    return true;
}
Exemple #4
0
void GUI::resetRocket() {
    Rocket *rocket = entityHandler->rocket;


    btTransform trans;
    trans.setIdentity();
    trans.setRotation(btQuaternion(btVector3(0, 1, 0), -90.0/57.0));
    trans.setOrigin({10,1,0});

    entityHandler->lock();
    rocket->getRigidBody()->setCenterOfMassTransform(trans);
    rocket->getRigidBody()->setLinearVelocity({0,0,0});
    rocket->getRigidBody()->setAngularVelocity({0,0,0});
    entityHandler->unlock();
}
void Racer::fireRocket()
{
	Sound::sound->playSoundEffect(SFX_ROCKETLAUNCH, emitter);

	hkpWorldRayCastInput input;
	hkpWorldRayCastOutput output = hkpWorldRayCastOutput();
	hkVector4 from;

	hkTransform trans = body->getTransform();
	from.setTransformedPos(trans, attachGun);

	input = fireWeapon();

	hkVector4 to = input.m_to;

	to.sub(from);

	to.normalize3();
	// Change this so rocket is facing rocketDir when launched
					
	
	Rocket* currentRocket = new Rocket(Renderer::device, this);
					
	currentRocket->owner = this;

	hkVector4 rocketPos;
	hkTransform bodyTransform;
	bodyTransform.set4x4ColumnMajor((const hkFloat32*) gunDraw->getTransform());

	hkVector4 rocketAttach;
	rocketAttach.setXYZ(Racer::attachGun);

	rocketPos.setTransformedPos(bodyTransform, rocketAttach);


	currentRocket->body->setTransform(bodyTransform);
	currentRocket->body->setPosition(rocketPos);

	to.mul(125.0f);
	currentRocket->body->setLinearVelocity(to);
	currentRocket->update(0.0f);

	DynamicObjManager::manager->addObject(currentRocket);
	currentRocket = NULL;
}
Exemple #6
0
void GUI::rocketEngineLight() {
#define ENGINE_LIGHT_STRENGTH 1.0f
    Rocket* rocket = static_cast<Rocket*>(entityHandler->dynamicEnts["rocket"]);
    Pose pose = rocket->getPose();

    if(fireCountdown < 0.01f) {
        if(rocket->engineFiredCount == lastSeenEngineFire) {
            glDisable(GL_LIGHT1);
            return;
        } else {
            fireCountdown = 1.0f;
        }
    }
    fireCountdown -= 0.08f;

    lastSeenEngineFire = rocket->engineFiredCount;

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT1);

    GLfloat ambientLight[] = {
        fireCountdown*ENGINE_LIGHT_STRENGTH*1.0f,
        fireCountdown*ENGINE_LIGHT_STRENGTH*1.0f,
        fireCountdown*ENGINE_LIGHT_STRENGTH*0.0f,
    };
    GLfloat position[] = {
        pose.worldTransform.getOrigin().x(),
        pose.worldTransform.getOrigin().y(),
        pose.worldTransform.getOrigin().z()
    };


    glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.0);
    glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.01);
    glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.01);

    glLightfv(GL_LIGHT1, GL_DIFFUSE, ambientLight);
    glLightfv(GL_LIGHT1, GL_POSITION, position);

    ShapeHandler *sh = ShapeHandler::getHandler();
    OpenGLObject* rocketFireOpenGLObject = sh->getMesh("rocket_fire")->openglobj;
    rocketFireOpenGLObject->setSprite(NULL);
    rocketFireOpenGLObject->draw(rocket->getPose());
    return;
}
Exemple #7
0
bool Rocket::Straw::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex) {
	Project::Element::touchEvent(evt, x, y, contactIndex);
	switch(evt) {
		case Touch::TOUCH_PRESS: {
			Rocket *rocket = (Rocket*)_project;
			MyNode *node = getNode();
			if(rocket->getTouchNode() == node) {
				Vector3 trans = rocket->getTouchPoint() - node->getTranslationWorld();
				Matrix straw = node->getWorldMatrix(), strawInv;
				straw.invert(&strawInv);
				strawInv.transformVector(&trans);
				float scale = ((rocket->_strawLength/2 - trans.z) / rocket->_strawLength) * node->getScaleZ();
				node->setScaleZ(scale);
				rocket->_strawLength = rocket->_originalStrawLength * scale;
			}
		}
	}
}
Exemple #8
0
void	play(int i, Window& win)
{
	nodelay(stdscr, TRUE);
	i = get_difficult(i);
	Player		p(win);
	EnnemyHorde n = EnnemyHorde(i, "^v^");
	Missile miss = Missile(10, "|");
	Rocket rock = Rocket(2, "[]");
	n.randomPOP(win);
	int	input = 0;
	p.setScoreZero();
	while (input != KEY_ECHAP && p.getHP() > 0)
	{
		clear();
		miss.print_score(win);
		win.takeSize();
		win.printBorder();
		input = getch();
		miss.activate(p.getX(), p.getY(), input);
		rock.activate(p.getX(), p.getY(), input);
		miss.checkDamages(n.getHorde(), n.getNumber(), win);
		rock.checkDamages(n.getHorde(), n.getNumber(), win);
		p.checkEnemies(n.getHorde(), n.getNumber(), win);
		p.print_life(win);
		miss.print_chargeur(win);
		rock.print_chargeur(win);
		if (p.getHP() > 0)
		{
			n.printit(win);
			miss.move(win);
			rock.move(win);
			miss.printit(win);
			rock.printit(win);
			p.printit(win);
			p.inputDirection(input);
			wrefresh(win.getWin());
			p.move(win);
			p.printit(win);
			n.move(win);
		}
		while(getch() != ERR);
		usleep(60000);
	}
	if (p.getHP() <= 0)
	{
		clear();
		print_die(win, p);
	}
	 if (p.getScore() > hight_score)
		 hight_score = p.getScore();

}
float RocketLauncher::rocketRange() {
    Rocket* rocket = WorldObjectBuilder(projectileName()).buildRocket();
    float range = rocket->lifetime() * rocket->components().enginePower().directional().x;
    delete rocket;
    return range;
}
Exemple #10
0
void renderScene() {

	glClear(GL_COLOR_BUFFER_BIT);
	//Camera Follow
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(player.position.getX()+width*zoom/2, player.position.getY()-height*zoom/2, 0,
		player.position.getX()+width*zoom/2, player.position.getY() - height*zoom/2,10,
		0,1,0);

	//Render Scene and Draw the stars and moon. 
	for (int i = 0; i < numStars; i++)
	{
		star[i]->draw();
	}
	for (int i = 0; i < numMoons; i++)
	{
		moons[i].draw();
		if (artillery.getLock())
		{
			if (player.distanceTo(moons[i]) < 4000)
			{
				UI->DrawPointers(player.radius, player.getAngleToTarget(moons[i]), player.position, vector(1.0f, 0.0f, 0.0f), vector(1.0f, 0.0f, 0.0f), player.distanceTo(moons[i]) - moons[i].radius-player.radius);
			}
		}
		else
		{
			if (player.distanceTo(moons[i]) < 4000)
			{
				UI->DrawPointers(50, player.getAngleToTarget(moons[i]), player.position, vector(1.0f, 0.0f, 0.0f), vector(1.0f, 0.0f, 0.0f), player.distanceTo(moons[i]) - moons[i].radius - player.radius);
			}
		}
	}
	
	// Draw and display all cannon components
	artillery.draw();

	// Draw and display Lunar-lander
	if (artillery.getLock())
	{
		player.draw();
		UI->DrawPointers(player.radius, player.getAngleToTarget(moons[moonLand]), player.position, vector(0.0f,0.0f,1.0f), vector(1.0f, 1.0f, 1.0f), player.distanceTo(moons[moonLand])- moons[moonLand].radius-player.radius);
	}
	else
	{
		UI->DrawPointers(50, player.getAngleToTarget(moons[moonLand]), player.position, vector(0.0f, 0.0f, 1.0f), vector(1.0f, 1.0f, 1.0f), player.distanceTo(moons[moonLand]) - moons[moonLand].radius - player.radius);
	}
	
	//Main UI Draw and display.

	if (showUI)
	{
		vector color;
		vector UIFuel = vector(player.position.getX() + width * zoom / 2 - 50, player.position.getY() + height * zoom / 2 - 50);
		if (!artillery.getLock())
		{
			if (artillery.getFuel() > 60)
			{
				color = vector(0.0f, 1.0f, 0.0f);
			}

			else if (player.getFuel() > 30 || player.getFuel() < 60)
			{
				color = vector(1.0f * (float)player.getFuel(), 1.0f * (float)player.getFuel() / 100, 0.0f);
			}
			else
			{
				color = vector(1.0f * (float)player.getFuel(), 0.0f, 0.0f);
			}
			UI->drawCircle(UIFuel.getX(), UIFuel.getY(), 32, 50, color, false, 5);
			UI->displayFloat(GLUT_BITMAP_HELVETICA_18, UIFuel.getX() + 15, UIFuel.getY() - 5, round(artillery.getFuel()));
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() + 15, UIFuel.getY() - 25, "Litres");
		}
		else
		{
			if (player.getFuel() > 60)
			{
				color = vector(0.0f, 1.0f, 0.0f);
			}

			else if (player.getFuel() > 30 || player.getFuel() < 60)
			{
				color = vector(1.0f * (float)player.getFuel(), 1.0f * (float)player.getFuel() / 100, 0.0f);
			}
			else
			{
				color = vector(1.0f * (float)player.getFuel(), 0.0f, 0.0f);
			}
			UI->drawCircle(UIFuel.getX(), UIFuel.getY(), 32, 50, color, false, 5);
			UI->displayFloat(GLUT_BITMAP_HELVETICA_18, UIFuel.getX() + (15 * zoom), UIFuel.getY() - (5 * zoom), round(player.getFuel()));
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() + (15 * zoom), UIFuel.getY() - (25 * zoom), "Litres");
		}
		glColor3f(0.0f, 1.0f, 0.0f);
		UI->drawCircle(UIFuel.getX() - (0 * zoom), UIFuel.getY() - (80 * zoom), 32, 25, vector(0, 1, 0), false, 3);
		UI->drawArrow(UIFuel.getX() - (0 *zoom), UIFuel.getY() - (80 * zoom), 20, player.getVelocityAngle(), vector(0, 1, 0));
		UI->displayFloat(GLUT_BITMAP_HELVETICA_18, UIFuel.getX() + (30 * zoom), UIFuel.getY() - (125 * zoom), (float)round(player.getVelocity() * 10));
		if (player.getVelocity() < 10)
		{
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() -(5*zoom), UIFuel.getY() - (125 * zoom), "KM/H");
		}
		else if (player.getVelocity() > 10)
		{
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (15*zoom), UIFuel.getY() - (125 * zoom), "KM/H");
		}

		// User Guide 
		UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (80*zoom), UIFuel.getY() + (20*zoom), "Dampening System (E)");

		UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (80 * zoom), UIFuel.getY() + (-845 * zoom), "Major HINT: Follow Blue arrow. Your goal is to land safely by backing down into your Goal Destination with your Lunar-lander. Max velocity = 600km/h or you crash! ");
		UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (80 * zoom), UIFuel.getY() + (-860 * zoom), "Need more help? Good luck, you're on your own.");
		UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (80 * zoom), UIFuel.getY() + (-930 * zoom), "All Right Reserved by Globobyte Studio.");


		if (!artillery.getLock())
		{
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (250 * zoom), UIFuel.getY() + (-10 * zoom), "Move Cannon Base Left (A)");
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (500 * zoom), UIFuel.getY() + (-10 * zoom), "Move Cannon Base Right (D)");
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (250 * zoom), UIFuel.getY() + (20 * zoom), "Increase Angle of Cannon Barrel (W)");
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (500 * zoom), UIFuel.getY() + (20 * zoom), "Decrease Angle of Cannon Barrel (S)");
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (250 * zoom), UIFuel.getY() + (-30 * zoom), "Shoot Lunar-lander (Use -> Space Bar)");
		}
		else 
		{
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (250 * zoom), UIFuel.getY() + (20 * zoom), "Rotate Lunar-lander Left (A)");
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (500 * zoom), UIFuel.getY() + (20 * zoom), "Rotate Lunar-lander Right (D)");
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (250 * zoom), UIFuel.getY() + (-10 * zoom), "Increase Velocity Forward (W)");
			UI->drawString(GLUT_BITMAP_HELVETICA_12, UIFuel.getX() - (500 * zoom), UIFuel.getY() + (-10 * zoom), "Inrease Velocity Backwards (S)");
		}
		

		if (player.checkDampeners())
		{

			UI->drawString(GLUT_BITMAP_HELVETICA_18, UIFuel.getX() - (80 * zoom), UIFuel.getY(), "Online");
		}
		else
		{
			glColor3f(1.0f, 0, 0);
			UI->drawString(GLUT_BITMAP_HELVETICA_18, UIFuel.getX() - (80 * zoom), UIFuel.getY(), "Offline");
		}

		if (player.checkCrashed())
		{
			glColor3f(1.0f, 0, 0);
			UI->drawString(GLUT_BITMAP_HELVETICA_18, player.position.getX() + 10, player.position.getY() + 35, "Crashed");
		}

		else if (player.checkLanded())
		{
			glColor3f(0, 1.0f, 0);
			UI->drawString(GLUT_BITMAP_HELVETICA_18, player.position.getX() + 10, player.position.getY() + 35, "Landed");
		}


		//End of UI Draws 
	}
	//End of Render Scene
	glutSwapBuffers();

}
Exemple #11
0
int main(int argc, char** argv)
{
	// Starting game window size.

	height = 960;
	width = 1000;

	//Initialize Object Data

	srand(time(NULL));

	// Initialize Tank
	float randomAngle = (float)random(0, 200) / 10;

	artillery = tank(random(-width * 24, width * 24), random(-height * 24, height * 24), 1500, 15, randomAngle);

	player = Rocket(0,0, 100, 0.8f, 10);
	player.follow(artillery); //Sets initial Position to tank

	UI = new UIManager();

	moonLand = random(0, numMoons-1);
	seed = random(-123456, 123456); // Level seed to randomize each level creation between min and max value. 
	int sizeOfMoonLoc = -1; 
	artillery.colRadius = artillery.radius * distanceFromStartMult;
	for (int i = 0; i < numMoons; i++)
	{
		sizeOfMoonLoc++;
		moonLocation[i] = vector(random(-width * 24, width * 24), random(-height * 24, height * 24));
		float moonRadius = random(300, 500);
		moons[i] = Moon(moonLocation[i], moonRadius, 0, 0, 0, 60);

		for (int z = 0; z < sizeOfMoonLoc; z++)
		{
			if (z != i)
			{
				while (moons[i].checkCollision(moons[z]) || moons[i].checkCollision(artillery))
				{
					moonLocation[i] = vector(random(-width * 24, width * 24), random(-height * 24, height * 24));
					moons[i] = Moon(moonLocation[i], moonRadius, 0, 0, 0, round(moonRadius / 10));
				}
				
			}
		}
	}
	artillery.colRadius = artillery.radius;
	for (int i = 0; i < numStars; i++)
	{
		star[i] = new Star(vector(random(-width*24,width*24), random(-height*24,height*24)), vector(0.8f, 0.8f, 0.0f), random(3, 15), random(0,100));
	}

	//End of Initialization

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(0,0);
	glutInitWindowSize(width, height);
	glutCreateWindow("IchyMoo the LunarLunar");
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearColor(0.05, 0.05, 0.05, 0.0);
	glutReshapeFunc(reshape);
	glutDisplayFunc(renderScene);
	glutKeyboardFunc(keyDown);
	glutKeyboardUpFunc(keyUp);
	glutTimerFunc(41,idle,0);
	glutMainLoop();
}
Exemple #12
0
void keyUp(unsigned char key, int x, int y) {
	player.controlEvent(key, false);
	artillery.controlEvent(key, false);
}
Exemple #13
0
void keyDown(unsigned char key, int x, int y)
{
	player.controlEvent(key, true);
	artillery.controlEvent(key, true);
}
Exemple #14
0
void idle(int value)
{

	glutTimerFunc(41, idle, 0);

	// Lunar-lander Shooting from cannon.

	if (artillery.getLock())
	{
		if (!artillery.checkRocketRelease())
		{
			float playerAngle = artillery.getPlayerAngle();
			float cannonAngle = artillery.getCannonRotate();
			float AdjPlayerAngle = playerAngle;

			int turns = ceil(abs(playerAngle) / (2 * M_PI)) - 1;

			if (turns >= 1)
			{
				if (playerAngle< 0)
				{
					AdjPlayerAngle = playerAngle + (M_PI *  2) * turns;
				}
				else
				{
					AdjPlayerAngle = playerAngle - (M_PI * 2) * turns;
				}
			}
			player.setVelocity(40, (M_PI/2) - AdjPlayerAngle + cannonAngle);
		}
		artillery.setRocketRelease(true);
	}

	//Calculate Physics for each frame

	for (int i = 0; i < numStars; i++)
	{
		star[i]->update();
	}
	for (int i = 0; i < numMoons; i++)
	{
		player.gravitateTo(moons[i]);
		if (i == moonLand)
		{
			player.update(moons[i], true);
		}
		else
		{
			player.update(moons[i], false);
		}
	}
	player.update(artillery, false);
	player.gravitateTo(artillery);
	player.update();
	artillery.updateTank();
	if (!artillery.getLock())
	{
		player.follow(artillery);
	}
	

	/* End of Calculation */
	glutPostRedisplay();
}
Exemple #15
0
void Game() {

	bgm.Play();
	sf::Clock clock;
	sf::Event event;
	while (window.isOpen()) {
		//系统关键位置初始化
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed){
				window.close();
			}
		}
		background.Show();
		sf::Time time1 = clock.getElapsedTime();
		//显示分数
		text.ShowScore();
		//显示敌机以及子弹
		for (int i = 0; i < 80; i++) {
			if (time1 >= sf::seconds(1.5*i)) {
				enemy[i].Show();
				window.draw(enemy_bullet[i].enemy_bullet);
				enemy_bullet[i].enemy_bullet.setPosition(sf::Vector2f(enemy[i].enemy.getPosition().x + 30, enemy[i].enemy.getPosition().y + 60));
				enemy_bullet[i].Show();
			}
		}
		//显示飞机、控制移动
		rocket.move();	
		//开炮
		rocket.Gun();
		bullet.Show();
		if (bullet.bullet.getPosition().y <= 10) { 
			bullet.Gone(); 
		}
		//碰撞处理
		sf::FloatRect collision_enemy[80];
		sf::FloatRect collision_enemy_bullet[80];
		sf::FloatRect boundingBox2 = rocket.rocket.getGlobalBounds();
		for (int i = 0; i < 80; i++) {
			collision_enemy[i] = enemy[i].enemy.getGlobalBounds();
			collision_enemy_bullet[i] = enemy_bullet[i].enemy_bullet.getGlobalBounds();
			sf::FloatRect boundingBox1 = bullet.bullet.getGlobalBounds();
				if ((boundingBox1.intersects(collision_enemy[i])) && (enemy[i].enemy.getPosition().y >= 0.0f)) {
					bullet.bullet.setPosition(sf::Vector2f(1000, 0));
					bgs1.Play();
					score += 100;
				}
			if ((boundingBox2.intersects(collision_enemy_bullet[i]))) {
				enemy_bullet[i].enemy_bullet.setPosition(sf::Vector2f(-400, 0));
				bgs2.Play();
				life--;
			}
			if ((boundingBox2.intersects(collision_enemy[i]))) {
				enemy[i].enemy.setPosition(sf::Vector2f(-400, 0));
				bgs2.Play();
				life--;
			}
		}
		window.display();
		//分数迭代
		if (score >= 100 * level) {level++;}
		if (life <= 0) {window.close();}
		if (score >= 7500) {window.close();}	
	}
}