Exemplo n.º 1
0
void drawSpiral(Turtle& turtle, double size) {
    while (size < 1.25) {
        turtle.forward(size);
        turtle.right(15);
        size = size * 1.02;
    }
}
Exemplo n.º 2
0
void TreeGeneratorApp::update()
{
    screenRotation += (dRotation-screenRotation) / 16.0f;
    Vec3f centerOfEverything = Vec3f(0,0,0);
    if(turtles.size()>0){
    for(int i=0;i<turtles.size();i++){
        centerOfEverything += turtles.at(i).curPos;
    }
    }
    centerOfEverything /= turtles.size();
   // console() << "CENTER: " << centerOfEverything.x << ", " << centerOfEverything.y << "." << endl;
    
    for(int i=0;i<turtles.size();i++) {
        turtles.at(i).update();
        if(turtles.at(i).forwardVelocity<0.05f && turtles.at(i).forwardVelocity>0.0f){
            turtles.at(i).forwardVelocity=0.0f;
            for(int j=0;j<2;j++){
                if(turtles.size()<maxNum){
                Turtle newTurtle = Turtle();
            newTurtle.setup(turtles.at(i).curPos,centerOfEverything);
          
                turtles.push_back(newTurtle);
                }
            }
            }
    }
}
void ObjectFactory::spawnSeaCreature(float xPos, float yPos,vector<Station*> *ships)
{
	int seaCreatureSpawnNum = rand() % 7;
	int rotation =  rand() % 360;
	switch (seaCreatureSpawnNum)
	{
	case 0:
	ships->push_back( new Whale(xPos, yPos, rotation));
	break;
	case 1:
	ships->push_back( new Hydra(xPos, yPos, rotation));
	break;
	case 2:
	ships->push_back( new Jellyfish(xPos, yPos, rotation));
	break;
	case 3:
	ships->push_back( new Octopus(xPos, yPos, rotation));
	break;
	case 4:
	ships->push_back( new Squid(xPos, yPos, rotation));
	break;
	case 5:
	ships->push_back( new Serpent(xPos, yPos, rotation));
	break;
	case 6:
	Turtle* myTurtle = new Turtle(xPos ,yPos,rotation);
	Helm* helm = new Helm(0, 10, 32, TextureManager::getManager()->helm,myTurtle);
	myTurtle->getHelms()->push_back(helm);
	ships->push_back(myTurtle);
	break;
	}
}
Exemplo n.º 4
0
void drawStar(Turtle& turtle, double size, int sides) {
    for (int i = 0; i < sides; i++) {
        turtle.forward(size);
        turtle.right(360.0 / sides);
        turtle.forward(size);
        turtle.left(2 * 360.0 / sides);
    }
}
Exemplo n.º 5
0
void drawRosette(Turtle& turtle, double size, int squares) {
    double angle = 360.0 / squares;
    for (int i = 0; i < squares; i++) {
        for (int j = 0; j < 4; j++) {
            turtle.forward(size);
            turtle.right(90);
        }
        turtle.right(angle);
    }
}
Exemplo n.º 6
0
Turtle* Turtle::create() {
    Turtle *sprite = new Turtle();
    if (sprite && sprite->initWithFile("turtle_1.png")){
        sprite->setup();
        sprite->autorelease();
        return sprite;
    }
    CC_SAFE_DELETE(sprite);
    return nullptr;
}
Exemplo n.º 7
0
// Use Koch fractal to draw a "snowflake"
void kochSnowflake(Turtle& turtle, int level, double size) {
    double angle = 60;
    turtle.left(angle);
    koch(turtle, level, size, angle);
    turtle.right(angle);
    turtle.right(angle);
    koch(turtle, level, size, angle);
    turtle.right(angle);
    turtle.right(angle);
    koch(turtle, level, size, angle);
}
Exemplo n.º 8
0
int main(){
	Pig pig;
	Turtle turtle;
	pig.eat();
	pig.sleep();
	pig.climb();
	turtle.swim();
	turtle.drool();

	return 0;
}
Exemplo n.º 9
0
void symetric_star(int number_of_sides, const int IMAGE_SIZE, std::string file_name){

	Turtle turtle (IMAGE_SIZE/2,IMAGE_SIZE/2,IMAGE_SIZE);
	int angle = 180 - 180/number_of_sides;
	turtle.pendown();
	for (int x = 0; x < number_of_sides; ++x)
	{
		turtle.left(angle);
		turtle.forward(5);
	}
	turtle.save(file_name);
}
Exemplo n.º 10
0
void drawArc(Point2 centre, float radius, float startAngle, float sweep)
{
	Turtle t;
	const int n = 30;
	float angle = startAngle * M_PI / 180;
	float angleInc = sweep * M_PI / (180 * n);
	float cx = centre.getX(), cy = centre.getY();
	t.moveTo(Point2(cx + radius*cos(angle), cy + radius*sin(angle)));
	for (int k = 1; k < n; k++, angle += angleInc)
	{
		t.lineTo(Point2(cx + radius*cos(angle), cy + radius*sin(angle)));
	}
}
Exemplo n.º 11
0
void WorldPainter::paint(QPainter &p, Turtle &turtle, int xt, int yt) {
	auto oldPen = p.pen();
	auto oldBrush = p.brush();
	p.setPen(pen(turtle.getColor()));
	p.setBrush(brush(turtle.getColor()));

	auto triangle = getTriangle();
	auto position = turtle.getPosition();
	paint(p, triangle, position.getValue(0) + xt, position.getValue(1) + yt, turtle.getAngle(), 5.0);

	p.setPen(oldPen);
	p.setBrush(oldBrush);
}
Exemplo n.º 12
0
// Recursive Koch fractal
void koch(Turtle& turtle, int level, double size, double angle) {
    if (level == 0) {
        turtle.forward(size);
    } else {
        koch(turtle, level - 1, size, angle);
        turtle.left(angle);
        koch(turtle, level - 1, size, angle);
        turtle.right(angle);
        turtle.right(angle);
        koch(turtle, level - 1, size, angle);
        turtle.left(angle);
        koch(turtle, level - 1, size, angle);
    }
}
Exemplo n.º 13
0
void drawArc(Point centre, float radius, float startAngle, float sweep)
{
	Turtle t;
	const int n = 30;
	float angle = startAngle * M_PI / 180; //convert to radian
	float angleInc = sweep * M_PI / (180 * n);
	float cx = centre.getX(), cy = centre.getY();	//200,200
	float a, b;
	a = cx + radius*cos(angle);
	b = cy + radius*sin(angle);
	t.moveTo(Point(a, b));
	for (int k = 1; k < n; k++, angle += angleInc)
	{
		t.lineTo(Point(cx + radius*cos(angle), cy + radius*sin(angle)));
	}
}
Exemplo n.º 14
0
int main(int argc, const char* argv[]) {
    Parser p;
    ifstream f(argv[1]);
    string prod, drawing;
    if (f.is_open()) {
        p.parse(f);
        f.close();
        Lsystem lsys(p.getAlphabet(), p.getAxiom(), p.getRules());
        prod = lsys.produce(p.getIterations());
        Turtle ninja;
        drawing = ninja.rewrite(prod, p.getTurtle(),
            p.getReductionScale(), p.getInitPos(), p.getInitAng());
        cout << drawing;
        return EXIT_SUCCESS;
    } else {
        cout << "error opening file" << endl;
        return EXIT_FAILURE;
    }
}
Exemplo n.º 15
0
int main(int argc, char** argv)
{
    Win110ct win;
    Turtle * t = win.getTurtle();
    t->penDown();
    t->setPosition(512,200);
    t->setColour({128,128,255});

    for(int i=0; i<24; ++i)
    {
        t->setPosition(512,200);
        dragon(t, i, 400);
        win.render();
        SDL_Delay(2000);
        win.clearBack();
    }

    win.getchar();
    return 0;
}
Exemplo n.º 16
0
void UniverseSTL::addRace(){
    // init race here
    int sx = rand() % board.GetH();
	int sy = rand() % board.GetW();
	int ex= rand() % board.GetH();
    int ey=sy;
    Race* Ra = new Race(sx,sy,ex,ey);
    RList.push_back(Ra);
    for( auto&it: MList ){
        if( isA<Rabbit>(it) )
        {
            Rabbit* r = (Rabbit*)it;
            r->triggerRace(Ra);
        }
        else if( isA<Turtle>(it)){
            Turtle* t = (Turtle*)it;
            t->triggerRace(Ra);
        }
    }

}
Exemplo n.º 17
0
int main( int argc, char* args[] )
{
    Win110ct win;
    int d;

    win.setTextColour({64,255,64});
    win.setPosition(5,10);
    win << "Enter max snowflake depth: ";

    win >> d;

    win.setTextColour({128,128,255});

    Stopwatch s;

    Turtle * t = win.getTurtle();
    win.render();
    win.getchar();

    t->setPosition(800, 100);
    t->setColour({255,64,64});
    win.hideTurtle();

    for(int i=1; i<=d; ++i)
    {
        win.clearBack();
        kochFlake(t,i, 600);
        win.render();
        SDL_Delay(1000);
        t->setPosition(800, 100);
        t->turn(-120);
    }

    win.clear();
    win.setPosition(10,20);
    win << "Press any key to exit program";
    win.getchar();

    return 0;
}
Exemplo n.º 18
0
void DrawScene()
{
	modelViewMatrix.PushMatrix();	
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);

		// Transform the light position into eye coordinates
		M3DVector4f vLightPos = { LIGHT_POSITION[0], LIGHT_POSITION[1], LIGHT_POSITION[2], LIGHT_POSITION[3] };
		M3DVector4f vLightEyePos;
		m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

    /* ------------ */
    /* FERRIS WHEEL */

    modelViewMatrix.PushMatrix();
        /* Position the ferris wheel appropriately. */
      modelViewMatrix.Translate(FERRIS_WHEEL_POSITION[0], FERRIS_WHEEL_POSITION[1], FERRIS_WHEEL_POSITION[2]);

      /* Apply the Translation to this entire block of objects */
      modelViewMatrix.PushMatrix();
        //theWheel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos, capTexture, wheelTexture, wallTexture, carTexture, currentTextureIndex);
      modelViewMatrix.PopMatrix();

    modelViewMatrix.PopMatrix();

    /* -------------- */
    /* ROLLER COASTER */

    modelViewMatrix.PushMatrix();
      modelViewMatrix.Translate(0.0, 0.0, -10.0);
      //track.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
    modelViewMatrix.PopMatrix();

    /* -------- */
    /* CAROUSEL */  

    modelViewMatrix.PushMatrix();
      //modelViewMatrix.Translate(3.0f, 0.0f, -3.0f);
      modelViewMatrix.Translate(0.0f, 0.0f, -3.0f);
      //carousel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
      modelViewMatrix.Translate(0.0f, 0.0f, -2.0f);
      //unicorn.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
      //ostrich.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
      turtle.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
    modelViewMatrix.PopMatrix();

	modelViewMatrix.PopMatrix();
}
Exemplo n.º 19
0
void UniverseList::addRace(){
    // init race here
    int sx = rand() % board.GetH();
	int sy = rand() % board.GetW();
	int ex= rand() % board.GetH();
    int ey=sy;
    Race *Ra=new Race(sx,sy,ex,ey);
    RList.push_back(Ra);
    for( auto its = MList.begin(); its != MList.end(); its = its->next)
    {
        Organism *it = its->val;
        if( isA<Rabbit>(it) )
        {
            Rabbit* r = (Rabbit*)it;
            r->triggerRace(Ra);
        }
        else if( isA<Turtle>(it)){
            Turtle* t = (Turtle*)t;
            t->triggerRace(Ra);
        }
    }

}
Exemplo n.º 20
0
Station* ObjectFactory::seaCreatureSelect(float xPos, float yPos)
{
	int seaCreatureNum = rand() % 7;
	int rotation =  rand() % 360;
	if (seaCreatureNum == 0)
	{
		return new Whale(xPos, yPos, rotation);
	}
	else if (seaCreatureNum == 1)
	{
		return new Hydra(xPos, yPos, rotation);
	}
	else if (seaCreatureNum == 2)
	{
		return new Jellyfish(xPos, yPos, rotation);
	}
	else if (seaCreatureNum == 3)
	{
		return new Octopus(xPos, yPos, rotation);
	}
	else if (seaCreatureNum == 4)
	{
		return new Squid(xPos, yPos, rotation);
	}
	else if (seaCreatureNum == 5)
	{
		return new Serpent(xPos, yPos, rotation);
	}
	else if (seaCreatureNum == 6)
	{
		Turtle* myTurtle = new Turtle(xPos ,yPos,rotation);
		Helm* helm = new Helm(0, 10, 32, TextureManager::getManager()->helm,myTurtle);
		myTurtle->getHelms()->push_back(helm);
		return myTurtle;
	}
}
Exemplo n.º 21
0
// Recursive fractal "tree" structure
void tree(Turtle& turtle, int level, double size, double angle,
        double scale) {
    if (level == 0) {
        turtle.forward(size);
        turtle.backward(size);
    } else {
        turtle.forward(size);
        turtle.left(angle);
        tree(turtle, level - 1, size * scale, angle, scale);
        turtle.right(angle);
        turtle.right(angle);
        tree(turtle, level - 1, size * scale, angle, scale);
        turtle.left(angle);
        turtle.backward(size);
    }
}
Exemplo n.º 22
0
 bool Painter::move(Turtle& turtle) {
     turtle.Forward(10);
     turtle.Turn(46);
     return true;
 }
Exemplo n.º 23
0
void SetupRenderingContext()
{
	int i, j;

	// Initialze Shader Manager
	shaderManager.InitializeStockShaders();	
	glEnable(GL_DEPTH_TEST);
	//glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  glClearColor(0.94f, 0.94f, 1.0f, 1.0f); // Blue Sky

  /* ------------- */
  /* Scene objects */

  track.SetupRenderingContext();
	theWheel.SetupRenderingContext();
  carousel.SetupRenderingContext();

  unicorn.SetupRenderingContext();
  ostrich.SetupRenderingContext();
  turtle.SetupRenderingContext();

  /* --------------- */
	/* Make the ground */

	GLfloat texSize = 50.0f;
	groundBatch.Begin(GL_TRIANGLE_FAN, 4, 1);
		groundBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
		groundBatch.Vertex3f(-0.5f * FLOOR_GRID_WIDTH, FLOOR_HEIGHT, 0.5f * FLOOR_GRID_WIDTH);	
		groundBatch.MultiTexCoord2f(0, texSize, 0.0f);
		groundBatch.Vertex3f(0.5f * FLOOR_GRID_WIDTH, FLOOR_HEIGHT, 0.5f * FLOOR_GRID_WIDTH);	
		groundBatch.MultiTexCoord2f(0, texSize, texSize);
		groundBatch.Vertex3f(0.5f * FLOOR_GRID_WIDTH, FLOOR_HEIGHT, -0.5f * FLOOR_GRID_WIDTH);	
		groundBatch.MultiTexCoord2f(0, 0.0f, texSize);
		groundBatch.Vertex3f(-0.5f * FLOOR_GRID_WIDTH, FLOOR_HEIGHT, -0.5f * FLOOR_GRID_WIDTH);
	groundBatch.End();

  /* ------------------------------- */
	/* Make texture object for ground. */

	glGenTextures(1, &groundTexture);
	glBindTexture(GL_TEXTURE_2D, groundTexture);
	LoadBMPTexture(GROUND_TEXTURE_FILENAME, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT);
	
  /* ----------------------------- */
	/* Make texture objects for cap. */

	glGenTextures(NBR_TEXTURE_SETS, capTexture);
	for ( i = 0; i < NBR_TEXTURE_SETS; i++ )
	{
		glBindTexture(GL_TEXTURE_2D, capTexture[i]);
		LoadBMPTexture(CAP_TEXTURE_FILENAME[i], GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
	}

  /* ------------------------------------------ */
	/* Make texture objects for wheel components. */

	glGenTextures(NBR_WHEEL_TEXTURES, wheelTexture);
	for ( i = 0; i < NBR_WHEEL_TEXTURES; i++ )
	{
		glBindTexture(GL_TEXTURE_2D, wheelTexture[i]);
		LoadBMPTexture(WHEEL_TEXTURE_FILENAME[i], GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
	}

  /* ------------------------------------------------ */
	/* Make texture objects for Ferris wheel car walls. */

	for ( i = 0; i < NBR_TEXTURE_SETS; i++ )
	{
		glGenTextures(NBR_WALL_TEXTURES, wallTexture[i]);
		for ( j = 0; j < NBR_WALL_TEXTURES; j++ )
		{
			glBindTexture(GL_TEXTURE_2D, wallTexture[i][j]);
			LoadBMPTexture(WALL_TEXTURE_FILENAME[i][j], GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
		}
	}

  /* ---------------------------------------- */
	/* Make texture objects for car components. */

	glGenTextures(NBR_CAR_TEXTURES, carTexture);
	for ( i = 0; i < NBR_CAR_TEXTURES; i++ )
	{
		glBindTexture(GL_TEXTURE_2D, carTexture[i]);
		LoadBMPTexture(CAR_TEXTURE_FILENAME[i], GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
	}
}
void AngleConversionApp::setup()
{
    // SETUP CAMERA
	mCameraDistance = 1200.0f;
	mEye			= Vec3f( 0.0f, 0.0f, mCameraDistance );
	mCenter			= Vec3f( 0.0f, 0.0f, 0.0f );
	mUp				= Vec3f::yAxis();
	mCam.setPerspective( 75.0f, getWindowAspectRatio(), 5.0f, 3000.0f );
    
    // CAMERA ROTATION
    xAngle = 0.0f;
    yAngle = 0.0f;
    zAngle = 0.0f;
    
    // OBJECT ROTATION
    rotateX0 = 0.0f;
    rotateY0 = 0.0f;
    rotateZ0 = 0.0f;
    
    // OBJECT ROTATION
    rotateX1 = 0.0f;
    rotateY1 = 0.0f;
    rotateZ1 = 0.0f;
    
    //PARAMS
    mParams = params::InterfaceGl( "Control Panel", Vec2i( 200, 160 ) );
    mParams.addParam( "Scene Rotation", &mSceneRotation );
    mParams.addParam( "Eye Distance", &mCameraDistance, "min=50.0 max=1500.0 step=50.0 keyIncr=s keyDecr=w" );
    mParams.addParam( "X Angle", &xAngle, "min=0.0 max=360.0 step=5.0 keyIncr=r keyDecr=f" );
    mParams.addParam( "Y Angle", &yAngle, "min=0.0 max=360.0 step=5.0 keyIncr=t keyDecr=g" );
    mParams.addParam( "Z Angle", &zAngle, "min=0.0 max=360.0 step=5.0 keyIncr=y keyDecr=h" );
    
    mParams.addParam( "Rotate X0", &rotateX0, "min=0.0 max=360.0 step=5.0 keyIncr=u keyDecr=j" );
    mParams.addParam( "Rotate Y0", &rotateY0, "min=0.0 max=360.0 step=5.0 keyIncr=i keyDecr=k" );
    mParams.addParam( "Rotate Z0", &rotateZ0, "min=0.0 max=360.0 step=5.0 keyIncr=o keyDecr=l" );
    
    mParams.addParam( "Rotate X1", &rotateX1, "min=0.0 max=360.0 step=5.0 keyIncr=u keyDecr=j" );
    mParams.addParam( "Rotate Y1", &rotateY1, "min=0.0 max=360.0 step=5.0 keyIncr=i keyDecr=k" );
    mParams.addParam( "Rotate Z1", &rotateZ1, "min=0.0 max=360.0 step=5.0 keyIncr=o keyDecr=l" );

    
    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
	
	gl::enableDepthWrite();
	gl::enableDepthRead();
	gl::enableAlphaBlending();
    
    glDisable( GL_TEXTURE_2D );
    
    mDirectional = 1.0f;
    
    camAngle = 0;
    
    // TURTLE
    startPosition.set( 0.0f, 0.0f, 0.0f);
    zeroDirection.set( 0.0f, 0.0f, 0.0f);
    initialDirection.set( 0.0f, 0.0f, 0.0f);
    
    direction1.set( 0.0f, 0.0f, 0.0f );
    direction2.set( 0.0f, 0.0f, 0.0f );
    
    testTurtle.init( Vec3f(0.0f, 0.0f, 0.0f), Vec3f(0.0f, 30.0f, 30.0f), direction1, 200.0f, 20.0f );
    mTurtles.push_back(testTurtle);
    
    //testTurtle2.init( testTurtle.mFinalPosition, 
    
    
    
    for (int i = 0; i < mTurtles.size(); i++ ) {
        string textString;
        
        textFinalAngle.push_back(textString);
        
        textSetAngle.push_back(textString);
        
        textPreviousAngle.push_back(textString);
        
        textFinalPosition.push_back(textString);
        
        textStartPosition.push_back(textString);
        
        textLocalCoordinates.push_back(textString);
        
        textWorldCoordinates.push_back(textString);
    }

}
Exemplo n.º 25
0
 void DrawLine(int x0, int y0, int x1, int y1) {
     turtle.GoTo(x0, y0);
     turtle.PenDown();
     turtle.GoTo(x1, y1);
     turtle.PenUp();
 }
Exemplo n.º 26
0
 bool Painter::paint(Turtle& turtle) {
     turtle.PenUp();
     turtle.PenDown();
     return true;
 }
Exemplo n.º 27
0
		// draw the given lsystem starting at the given position
		void drawSystem(LSystem* sys, vec4 startPoint, vec4 color, bool setColor) {
			Turtle* turtle = sys->getTurtleCopy();
			stack<mat4> modelView;
			// move to start point and point the tree upwards
			modelView.push(Translate(startPoint) * RotateX(-90));
			turtle->ctm = &modelView;
			string turtleString = sys->getTurtleString();

			if(setColor) {
				GLuint colorLoc = glGetUniformLocationARB(program, "inColor");
				glUniform4fv(colorLoc, 1, color);
			}

			for(string::iterator it = turtleString.begin(); it != turtleString.end(); ++it) {
				char currentChar = *it;
				
				if(currentChar == 'F') {
					drawTurtleComponent(turtle, sphere);
					drawTurtleComponent(turtle, cylinder);
				}

				switch(currentChar) {
					case 'F':
					case 'f':
						turtle->forward();
						break;
					case '+':
						turtle->rotate(Turtle::X, true);
						break;
					case '-':
						turtle->rotate(Turtle::X, false);
						break;
					case '&':
						turtle->rotate(Turtle::Y, true);
						break;
					case '^':
						turtle->rotate(Turtle::Y, false);
						break;
					case '\\':
						turtle->rotate(Turtle::Z, true);
						break;
					case '/':
						turtle->rotate(Turtle::Z, false);
						break;
					case '|':
						turtle->turnAround();
						break;
					case '[':
						turtle->push();
						break;
					case ']':
						turtle->pop();
						break;
				}
			}

			delete turtle;

		}
Exemplo n.º 28
0
void Bullet::visit(Turtle& t)
{
    cout << "Turtle gets attacks by Bullet!" << endl;
    t.deductHp(5);
}
Exemplo n.º 29
0
//------------------------------------------------------------
void Level::makeLevel(int levelNumber)
{
    //if the level already exists delete it
	if ((activeDrawable_.first() != NULL) || (activeMovable_.first() != NULL) || (activeBlocks_.first() != NULL)) {
		resetLevel();
	}
	
	// Mac environment variable for home directory
    char *cHomeDir = NULL;
    
    cHomeDir = getenv("HOME");
    
    // I think Windows uses HOMEPATH
    if (!cHomeDir) {
        cHomeDir = getenv("HOMEPATH");
    }
    string homeDir = cHomeDir;
    homeDir += "/CS330/";
    string fname;
    
	ifstream inFile;
	if (levelNumber== 1) {
        fname = homeDir + "levelfiles/level1.txt";
		inFile.open(fname.c_str());
	}
	else if (levelNumber== 2) {
        fname = homeDir + "levelfiles/level3.txt";
		inFile.open(fname.c_str());
	}
	int xcoord = 0, ycoord = 0, type, reward;
	char object;
	
	while (inFile.good()) {
		object= inFile.get();

		
		/*at this point the variable 'object' has the next item in the .txt 
		 and here the 'object' and it's xcord and ycord are sent off to the 
		 correct LList*/
		if (object== 'b') {
			//create breakable block
			Breakable *bBlock = new Breakable;
			bBlock->setTop(ycoord  + 16);
			bBlock->setBottom(ycoord);
			bBlock->setLeft(xcoord);
			bBlock->setRight(xcoord + 16);
			//add block to the list
			if (xcoord<256){
				activeBlocks_.append(bBlock);
			}
			else {
				levelBlocks_.append(bBlock);
			}
		}

		else if (object== 'B' || object=='M' || object=='C' || object=='S'){
			// sets the type and reward based off the letter passed and creates the block
			
			if (object == 'B') {
				type = REGULAR;
				reward = 0;
			}
			else if (object == 'M'){
				type = QUESTION;
				reward = MUSHROOM;
			}
			else if (object == 'S'){
				type = QUESTION;
				reward = STAR;
			}
			else if (object == 'C'){
				type = QUESTION;
				reward = COIN;
			}
			
			Nonbreakable *nBlock = new Nonbreakable(type, reward);

			nBlock->setTop(ycoord  + 16);
			nBlock->setBottom(ycoord);
			nBlock->setLeft(xcoord);
			nBlock->setRight(xcoord + 16);
			
			//place in correct list
			if (xcoord<256) {
				activeBlocks_.append(nBlock);
			}
			else {
				levelBlocks_.append(nBlock);
			}

		}
		else if (object == 'c') {
			
			//create coin
			Coin *coin = new Coin;
			coin->setTop(ycoord  + 16);
			coin->setBottom(ycoord);
			coin->setLeft(xcoord);
			coin->setRight(xcoord + 16);
			
			//place in correct list
			if (xcoord<256) {
				activeDrawable_.append(coin);
			}
			else {
				levelDrawable_.append(coin);
			}
		}
		else if (object== 'f'){
			//create flag pole
			Flag *flag = new Flag;
			flag->setTop(ycoord  + 16);
			flag->setBottom(ycoord);
			flag->setLeft(xcoord+6);
			flag->setRight(xcoord + 10);
			//place in correct list
			if (xcoord<256){
				activeBlocks_.append(flag);
			}
			else {
				levelBlocks_.append(flag);
			}
		}
		else if (object== 'P'){
			//create Pipe top
			Pipe *pipe = new Pipe;
			pipe->setType(0);
			pipe->setTop(ycoord  + 16);
			pipe->setBottom(ycoord);
			pipe->setLeft(xcoord);
			pipe->setRight(xcoord + 32);
			//place in correct list
			if (xcoord<256){
				activeBlocks_.append(pipe);
			}
			else {
				levelBlocks_.append(pipe);
			}
		}
		else if (object== 'p'){
			//create Pipe body
			Pipe *pipe = new Pipe;
			pipe->setType(1);
			pipe->setTop(ycoord  + 16);
			pipe->setBottom(ycoord);
			pipe->setLeft(xcoord);
			pipe->setRight(xcoord + 32);
			//place in correct list
			if (xcoord<256){
				activeBlocks_.append(pipe);
			}
			else {
				levelBlocks_.append(pipe);
			}
		}
		else if (object== 'g'){
			//create goomba
			Goomba *goomba = new Goomba;
			goomba->setTop(ycoord  + 16);
			goomba->setBottom(ycoord);
			goomba->setLeft(xcoord);
			goomba->setRight(xcoord + 16);
			
			//place in correct list
			if (xcoord<256) {
				activeMovable_.append(goomba);
			}
			else {
				levelMovable_.append(goomba);
			}
		}
		else if (object == 'k') {
			
			//create koopa
			Turtle *koopa = new Turtle;
			koopa->setTop(ycoord  + 24);
			koopa->setBottom(ycoord);
			koopa->setLeft(xcoord);
			koopa->setRight(xcoord + 16);
			
			//place in correct list
			if (xcoord<256) {
				activeMovable_.append(koopa);
			}
			else {
				levelMovable_.append(koopa);
			}
		}
		else if (object == 's') {
			
			//creates the coordinates for marios starting point
			leftStart_ = xcoord;
			bottomStart_ = ycoord;
		}
        else if (object== 'u' || object=='y' || object=='w' || object=='1'|| object=='2' || object=='3' || object=='7' || object =='8' || object== 'v' || object== 't' || object== 'd'){
            //create bush
            Background *background = new Background(object);
            background->setTop(ycoord  + background->getHeight());
            background->setBottom(ycoord);
            background->setLeft(xcoord);
            background->setRight(xcoord + background->getWidth());
            
            //place in correct list
            if (xcoord<256) {
                activeDrawable_.append(background);
            }
            else {
                levelDrawable_.append(background);
            }
        }
        


		if (ycoord < 224) {
			ycoord += 16;
		}
		else if (ycoord == 224) {
         xcoord += 16;
         ycoord = 0; 
		}
	
	}
	inFile.close();
}
Exemplo n.º 30
-2
void drawPolygon(Turtle& turtle, double size, int sides) {
    double angle = 360.0 / sides;
    for (int count = 0; count < sides; count++) {
        turtle.forward(size);
        turtle.left(angle);
    }
}