Exemple #1
0
/**
* CGrenadeWeapon::fireWeapon
* @date Modified April 27, 2006
*/
bool CGrenadeWeapon::fireWeapon()
{
	// limit the amount of shooting per second
	if (m_unGrenadeCounter && CTimer::getInstance().getTime() - m_fFireTimer > 0.2f)
	{
		CGrenadeWeapon *poGrenade = (CGrenadeWeapon*)CObjectManager::getInstance().createObject(OBJ_WEAPON_GRENADE);
		poGrenade->m_pMesh = m_poGrenadeMesh;
		// set the color to the grenade to a random one
		poGrenade->setColor(getRandomColor());
		// increase reference count
		m_poGrenadeMesh->addRef();
		poGrenade->setPosition(m_poCharacter->getBV().centerPt + m_poCharacter->getOrientation() * 5);
		poGrenade->m_oBV.centerPt = poGrenade->getPosition();
		poGrenade->m_oBV.fRadius = 1.0f;
		poGrenade->setOrientation(m_poCharacter->getOrientation());
		poGrenade->m_vVelocity = poGrenade->getOrientation() * 25.0f;
		poGrenade->m_vVelocity.y += 25.0f;
		poGrenade->m_fTimer = CTimer::getInstance().getTime();
		poGrenade->activate();
		poGrenade->m_nDamage = m_nDamage;
		poGrenade->m_nAreaOfEffect = m_nAreaOfEffect;
		poGrenade->setPlayer((CPlayer*)m_poCharacter);
		m_fFireTimer = CTimer::getInstance().getTime();
		poGrenade->setScale(D3DXVECTOR3(3.0f, 3.0f, 3.0f));
		--m_unGrenadeCounter;
		return true;
	}
	return false;
}
/*
    Permet d'avoir la couleur d'un ensemble
*/
char* WriteFic::getCouleurPixel(void* ptr) {

    bool trouve = false;
    std::vector<unsigned long int>::iterator itor = listPtrEnsemble.begin ();
    int i = 0;

    //Tant que le representant na pas ete trouve dans listPtrEnsemble on continu de le chercher
    while (itor != listPtrEnsemble.end () && !trouve) {

        if (listPtrEnsemble[i] == (unsigned long int) ptr) {
            trouve = true;
        }else {
            i++;
        }
        ++itor;
    }
    /*Si on ne le trouve pas cest que cest un nouvel ensemble pas encore stocké dans listPtrEnsemble
        et on lui ajoute une couleur corespondante dans listColor (au meme indice que dans listPtrEnsemble)
    */
    if (!trouve) {
        listPtrEnsemble.push_back((unsigned long int) ptr);
        listColor.push_back(getRandomColor());
    }

    //On renvoi la couleur correspondant a lensemble
    return listColor[i];

}
//Constructor
BunnyWorld::BunnyWorld():
m_population(0),
m_radioactivePopulation(0),
m_first(new Bunny)
{
    //clears output.txt when world created.
    std::ofstream outputFile("output.txt");
    outputFile.close();
    std::ofstream populationFile("population.txt");
    populationFile.close();
    //Set up an empty first bunny to start the program
    m_first->m_next = nullptr;
    Bunny* tracker = m_first;

    //create first 5 bunnies
    for (int i = 0; i < 5; i++)
    {
        int color = getRandomColor();
        Bunny* newBunny = new Bunny(color);
        newBunny->m_next = nullptr;
        tracker->m_next = newBunny;
        tracker = newBunny;
        m_population++;
        if (newBunny->getRadioactive()){
            m_radioactivePopulation++;
        }
    }
    printBunnies();

}
Pattern5x5 Pattern5x5::getRandomPattern(std::default_random_engine& engine) {
  Pattern5x5 p;
  for (unsigned int i = 0; i < 12; ++i) {
    p.hash += getRandomColor(engine);
  }
  p.hash += 'B';
  for (unsigned int i = 0; i < 12; ++i) {
    p.hash += getRandomColor(engine);
  }

  p.determineRandomGoodMoves(engine);

  if (p.isLegalPattern()) {
    return p;
  }
  return getRandomPattern(engine);
}
Exemple #5
0
/*
 * Flicker the walls in the hallway. This randomly flickers up
 * to maxflicker stripes on each wall
 */
void flickerWalls(int maxflicker)
{
  int i, flicker, strip;

  /* do the left wall */
  flicker =  (int)(maxflicker * drand48()) + 1;
  for (i=0;i<flicker;i++) {
    strip = (int) hallway.numStrips * drand48();
    getRandomColor(&(hallway.stripsLeft[strip]));
  }

  /* and the right */
  flicker =  (int)(maxflicker * drand48()) + 1;
  for (i=0;i<flicker;i++) {
    strip = (int) hallway.numStrips * drand48();
    getRandomColor(&(hallway.stripsRight[strip]));
  }
}
uint16_t twinkleTwinkle(uint16_t tick, uint32_t color, uint8_t cycles) {
  for (uint16_t i=0; i<NUM_LEDS; i++) {
    if(getLedColor(i) > BLACK) {
      setLedColor(i, dim256(getLedColor(i), map(cycles, NUM_CYCLES, 0, 10, 100)));
    } else if (chanceOneIn(map(cycles, NUM_CYCLES, 0, 500, 10))) {
      setLedColor(i, getRandomColor());
    }
  }

  return 1;
}
Exemple #7
0
Color const getColor(const std::string &id, std::map<std::string, Color> &colors)
{
    for (auto it = colors.begin(); it != colors.end(); ++it)
    {
        if (id == it->first)
            return it->second;
    }
    WARN("Key \"%s\" not found in color lookup table.", id.c_str());
    Color c = getRandomColor();
    colors.insert(std::pair<std::string, Color>(id, c));
    return c;
}
Exemple #8
0
const Color* getColor(const std::string &id, std::map<std::string, Color*> &colors)
{
	for (std::map<std::string, Color*>::const_iterator it=colors.begin(); it !=colors.end(); ++it)
	{
		if (id.compare(it->first) == 0)
			return it->second;
	}
	std::cout << "Key \"" << id << "\" not found in color lookup table..." << std::endl;
	Color* c = getRandomColor();
	colors.insert(std::pair<std::string, Color*>(id, c));
	return c;
}
uint16_t competitivePixels(uint16_t tick, uint32_t color) {
  uint8_t speed;

  for (uint16_t i=0; i<NUM_LEDS; i++) {
    if(getLedColor(i) > BLACK) {
      speed = getLedColor(i) % 5;
      setLedColor(i + speed, getLedColor(i));
      setLedColor(i, BLACK);
      i = i + speed;
    } else if(i == 0 && chanceOneIn(100)) {
      setLedColor(i, getRandomColor());
    }
  }

  return 1;
}
Exemple #10
0
Rectangle::Rectangle()
{
	id = counter;
	proportion = getRandomProportion();	// set it random
	color = getRandomColor();			// set it random among fixed values

	position = glm::vec4(0, 0, 0, 1);

	scaleMatrix = glm::scale(glm::mat4(1), glm::vec3(2, 2, 1));
	rotationMatrix = glm::rotate(glm::mat4(1), 0.0f, glm::vec3(0, 0, 1));
	translationMatrix = getInitialPosition();
	// modelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
	// TODO change next lines
	modelMatrix = translationMatrix * rotationMatrix * scaleMatrix * glm::mat4(1);
	// modelMatrix = translationMatrix * glm::mat4(1);

	isPinned = false;
	isDead = false;

	previousTime = glfwGetTime();
	currentTime = glfwGetTime();

	counter++;

	// rectangle's vertices (object space) [-1:1]
	float ratio = proportion.x / proportion.y;
	float scaleFactor = 0;
	if (ratio > 1) {
		scaleFactor = 2 / proportion.x;
	} else {
		scaleFactor = 2 / proportion.y;
	}
	float halfx = proportion.x / 2.0;
	float halfy = proportion.y / 2.0;
	float scaledHalfx = scaleFactor * halfx;
	float scaledHalfy = scaleFactor * halfy;

	// int zbuffer = static_cast<int>(std::rand() * 1.0 / RAND_MAX * 2 - 1);
	zbuffer = 0;

	vertexa = glm::vec4(-scaledHalfx, scaledHalfy, zbuffer, 1);
	vertexb = glm::vec4(scaledHalfx, scaledHalfy, zbuffer, 1);
	vertexc = glm::vec4(-scaledHalfx, -scaledHalfy, zbuffer, 1);
	vertexd = glm::vec4(scaledHalfx, -scaledHalfy, zbuffer, 1);
}
Exemple #11
0
void Game::spawnAllBlocks() {
	float z = -currentLevel->length + 16.0f + 6 * currentStep;

	for (int i = 0; i < currentLevel->height; ++i) {
		for (int j = 0; j < currentLevel->width; ++j) {
			float x = 2.0f * j - currentLevel->width;
			float y = i*2.0f + 1.0f;

			if (1 == rand() % 2) {
				mainBlocks.push_back(std::make_shared<GameObject>(Point3f(x, y, z), 2.0f, SDL_COLOR_BLUE));
			}
			else {
				freeBlockSlots.push_back(Point3f(x, y, z));
			}
		}
	}

	int blocksNeeded = currentLevel->width * currentLevel->height - mainBlocks.size();

	for (int i = 0; i < blocksNeeded; ++i) {
		Point3f p((float)getRandom(-currentLevel->width, currentLevel->width), 4 + (blocksNeeded-i)*2.0f, player->getCenter().z + getRandom(-5, 5));
		extraBlocks.push_back(std::make_shared<GameObject>(p, 2.0f, getRandomColor(50, 200)));
	}
}
void testApp::customDraw ( )
{
    int numUsers = openNIDevice.getNumTrackedUsers();
    // iterate through users
    
    ofColor col1 = ofColor( 0 , 255 , 0 ) ;
    ofColor col2 = ofColor( 0 , 0 , 255 ) ;
    
    /*
 
    for ( int i = 0 ; i < fakeSkeleton.size() ; i++ )
    {
        float ratio = ( float ) i / ( float ) fakeSkeleton.size() ;
        ofPoint p = fakeSkeleton[i] ;
        ofColor c = col1.lerp( col2, ratio ) ;
        ofSetColor( c ) ;
       
        //ofCircle( p.x , p.y , 15 ) ;
        ofDrawBitmapStringHighlight( ofToString(i) , p.x , p.y - 15 ) ;
    }
  */
     //   return ;
    
    
    float xRatio = (float)ofGetWidth() / (float)roiArea.width;
    //xRatio *= .5 ;

    for (int i = 0; i < numUsers; i++)
    {
        ofxOpenNIUser & user = openNIDevice.getTrackedUser(i);
       // user.drawMask();
               
        int numLimbs = user.getNumJoints() ;
        for ( int j = 0 ; j < user.getNumJoints() ; j++ )
        {
            float ratio = ( float ) j / ( float ) user.getNumJoints() ;
            
            ofxOpenNIJoint joint = user.joints[j] ;
            ofPoint p = joint.getProjectivePosition() ;
            p.z = 0 ;
            p.x *= xRatio ;
            p.y *= xRatio ;
            skeleton[j] = p ;
            //cout << " joint[" << j << "] : " << p << endl ;
            ofColor c = col1.lerp( col2, ratio ) ;
            ofSetColor( c ) ;
            ofCircle( p.x , p.y , 15 ) ;
            ofDrawBitmapStringHighlight( ofToString(j) , p.x , p.y - 15 ) ;
        }
        
        //user.drawSkeleton() ;
    }
    
    if ( ofGetElapsedTimef() > ( lastSpawn + spawnDelay ) )
    {
        for ( int i = 0 ; i < spawnPerBeat ; i++ )
        {
            if ( agents.size() < maxParticles )
            {
                Agent a ;
                int index = (int)jointRoutes[0].getRandomTargetIndex() ;
                
                ofPoint randomOffset = ofPoint ( ofRandom ( -25 , 25 ) , ofRandom ( -25 , 25 ) ) ;
                ofPoint p = skeleton[0] + randomOffset ;

                a.setup( p ,  skeleton[index] , index ) ;
                ofColor col = getRandomColor() ;
                a.color = col ; 
                agents.push_back( a )  ;
            }
            
        }
        
        lastSpawn = ofGetElapsedTimef() ; 
        setParticleParams() ; 
    }

}
Exemple #13
0
GraphicTile::GraphicTile(char ch) :
    fgColor(getRandomColor()),
    bgColor(getRandomColor()),
    graphicTileChar(ch)
{
}
void PlayState::setAppleFillColor()
{	
		
	_apple->setFillColor(getRandomColor());

}
Exemple #15
0
void configureHallway()
{
  FILE* hallway_file;
  char str [256];
  float n1, n2;
  int i;
  
  if((hallway_file = fopen (CONFIG_FILE, "r")) == NULL) {
    fprintf(stderr,"Unable to read %s\n", CONFIG_FILE);
    exit(1);
  }

  /* skip coments */
  do   {
    if(fgets (str, 256, hallway_file) == NULL){
      fprintf(stderr,"unexpected end of file in config file\n");
      exit(1);
    }
  } while (str [0] == '%');
  
  /* read hallway length */
  sscanf (str, "%f", &n1); 
  hallway.length = n1;

  /* skip coments */
  do  {
    if(fgets (str, 256, hallway_file) == NULL) {
      fprintf(stderr,"unexpected end of file in config file\n");
      exit(1);
    }
  } while (str [0] == '%');

  /* read hallway width and height */
  sscanf (str, "%f %f", &n1, &n2); 
  hallway.width = n1;
  hallway.height = n2;

  /* skip coments */
  do  {
    fgets (str, 256, hallway_file);
  } while (str [0] == '%');

  /* read strip length */
  sscanf (str, "%f", &n1); 
  hallway.stripLength = n1;
  
  fclose(hallway_file);
  
  /* initialize the rest of the hallway */
  hallway.numStrips = (int) hallway.length / hallway.stripLength;
  hallway.stripsLeft = (color*) malloc(hallway.numStrips * sizeof(color));
  hallway.stripsRight = (color*) malloc(hallway.numStrips * sizeof(color));
  if((hallway.stripsLeft == (color *)NULL)||(hallway.stripsRight == (color *)NULL)) {
    fprintf(stderr,"Out of memory in configure_hallway\n");
    exit(0);
  }
  
  seedRandomGenerator();
  
  for(i=0;i<hallway.numStrips;i++)  {
    getRandomColor(&(hallway.stripsLeft[i]));
    getRandomColor(&(hallway.stripsRight[i]));
  }
}
/**
 * This is the main loop for the program.  It is given a reference image and
 * the size, as well as various parameters used to define polygon type,
 * how many to use, and the target difference percentage.
 */
static void main_loop(Color_t *original, int width, int height,
        int n_points, int n_polygons, double target_percentage)
{
    int old_diff = -1;
    unsigned int new_diff;
    unsigned int n_used, n_tried;
    unsigned int max_diff;
    double current_percent = 0.0f;
    char output[64];
    Color_t *temporary;
    Color_t *canvas;

    n_used = n_tried = 0;

    /* The most different a test image can be. */
    max_diff = MAX_COLOR_VALUE * (unsigned int)width * (unsigned int)height * 3;

    /* Allocate the buffers used--one for a temporary buffer, and one for
     * holding our work-in-progress. */
    temporary = malloc(width * height * sizeof(Color_t));
    if (!temporary)
        abort_("Unable to allocate temporary buffer.\n");

    canvas = malloc(width * height * sizeof(Color_t));
    if (!canvas)
        abort_("Unable to allocate canvas buffer.\n");

    /* Start with a blank canvas. */
    clearCanvas(canvas, width, height);

    do {
        n_tried++;

        /* Generate a randomly-colored polygon. */
        Color_t color = getRandomColor();
        Polygon_t polygon = getRandomPolygon(width, height, n_points);

        /* Create the temporary canvas by starting with the current work in
         * progress. */
        memcpy(temporary, canvas, width*height*sizeof(Color_t));

        /* Generate a random weighting to use for merging in the new polygon. */
        double weight = drandrange(0.25, 0.75);

        /* Add a polygon. */
        drawPolygon(temporary, width, height, polygon, n_points, color, weight);

        /* Compare to the original. */
        new_diff = isSecondOneBetter(original, temporary, width, height, old_diff);
        if (new_diff < 0)
            continue;

        /* If we've improved, keep the new version */
        if (old_diff < 0 || new_diff < old_diff) {
            n_used++;
            current_percent =
                100.0f - ((100.0f * (double)new_diff) / (double)max_diff);

            printf("%d / %d (tested %d) -- %.02f%% (Weight %2.2f)\n",
                    n_used, n_polygons, n_tried, current_percent, weight);

            memcpy(canvas, temporary, width*height*sizeof(Color_t));
            old_diff = new_diff;
            sprintf(output, "./out/img_%d.png", n_used);
            writePNG(output, canvas, width, height);

            if (current_percent > target_percentage && target_percentage > 0.0f)
                break;
        }
    } while (n_used < n_polygons);

    free(temporary);
    free(canvas);
}