Ejemplo n.º 1
0
void ofApp::generateMap() {
	int numberOfSteps = 2;
	for (int i = 0; i < numberOfSteps; i++) {
		int deathLimit = 3;
		int birthLimit = 4;
		for (int y = 0; y < GRIDH; y++) {
			for (int x = 0; x < GRIDW; x++) {

				int nbs = countAliveNeighbors(backgrounds, x, y);
				basicSprite* tile = getTile (x, y);
				
				if (tile->isWall) {
					if (nbs < deathLimit) {
						tile->isWall = false;
					}
			  //otherwise if cell is dead, check if it has the right number of neighbors to be born
				} else {
					if (nbs > birthLimit) {
						tile->isWall = true;
					}
				}
			}
		}
	}
}
Ejemplo n.º 2
0
void ofApp::generateMap() {
	int numberOfSteps = 5;
	for (int i = 0; i < numberOfSteps; i++) {
		int deathLimit = 3;
		int birthLimit = 4;
		for (int x = 0; x < COLS; x++) {
			for (int y = 0; y < ROWS; y++) {
				int nbs = countAliveNeighbors(cellmap, x, y);
				if (cellmap[x][y].isGround) {
					if (nbs < deathLimit) {
						cellmap[x][y].isGround = false;
					} else {
						cellmap[x][y].isGround = true;
					}
			  //otherwise if cell is dead, check if it has the right number of neighbors to be born
				} else {
					if (nbs > birthLimit) {
						cellmap[x][y].isGround = true;
					} else {
						cellmap[x][y].isGround = false;
					}
				}
				
			}
		}
	}
	
}
Ejemplo n.º 3
0
void ofApp::placeTreasure() {
	int hiddenLimit = 5;
	for (int i = 0; i < COLS; i++) {
		for (int j = 0; j < ROWS; j++) {
			if (!cellmap[i][j].isGround) {
				int nbs = countAliveNeighbors(cellmap, i, j);
				if (nbs >= hiddenLimit) {
					treasures.push_back(ofPoint (i,j));
					cellmap[i][j].hasTreasure = true;
				}
			}
		}
	}
}
Ejemplo n.º 4
0
void Life::next(Cell* current, int index) {
	int alive, state, nextIndex;

	nextIndex = wrapi(index + 1, 0, 2);

	alive = countAliveNeighbors(current, index);
	state = current->states[index];

	if (state == 1.0) {
		current->states[nextIndex] = _survivals[alive];
	}
	else
	{
		current->states[nextIndex] = _births[alive];
	}

}
Ejemplo n.º 5
0
void Faders::next(Cell* current, int index) {
	int alive, state, nextIndex;

	nextIndex = wrapi(index + 1, 0, 2);

	alive = countAliveNeighbors(current, index);
	state = current->states[index];
	if (state > 1.0) {
		if (state < numStates()) {
			current->states[nextIndex] = state + 1.0;
		}
		else
		{
			current->states[nextIndex] = 0.0;
		}
	}
	else
	{
		if (state == 0.0)
		{
			current->states[nextIndex] = _births[alive];
		}
		else
		{
			if (_survivals[alive] == 0.0) {
				if (state < numStates()) {
					current->states[nextIndex] = state + 1.0;
				}
				else
				{
					current->states[nextIndex] = 0.0;
				}
			}
			else
			{
				current->states[nextIndex] = 1.0;
			}
		}
	}

}
Ejemplo n.º 6
0
void Node::nextGeneration(int* births, int* survivals, int numStates, int index) {
	int alive, state, nextIndex;
	
	nextIndex = wrapi(index + 1, 0, 2);
	
	alive = countAliveNeighbors(index);
	state = this->states[index];
	if (state > 1.0) {
		if (state < numStates) {
			this->states[nextIndex] = state + 1.0;
		}
		else
		{
			this->states[nextIndex] = 0.0;
		}
	}
	else
	{
		if (state == 0.0)
		{
			this->states[nextIndex] = births[alive];
		}
		else
		{
			if (survivals[alive] == 0.0) {
				if (state < numStates) {
					this->states[nextIndex] = state + 1.0;
				}
				else
				{
					this->states[nextIndex] = 0.0;
				}
			}
			else
			{
				this->states[nextIndex] = 1.0;
			}
		}
	}
	
}