Beispiel #1
0
char ttCanMoveDown(tetris_table* t)
{
        block* b = t->next_block[0];
        for (uint16_t s = 0; s < blockSize(b); ++s)
        {
                position p = blockPosition(b, s);
                p.x += t->currentPos.x;
                p.y += t->currentPos.y + 1;

                if (p.x < t->size.x && p.y >= 0 && p.x >= 0)
                        if (p.y >= t->size.y || !t->tab[p.y][p.x].empty)
                                return 0;
        }
        return 1;
}
Beispiel #2
0
char ttCanMove(tetris_table* t, char right)
{
        block* b = t->next_block[0];
        for (uint16_t s = 0; s < blockSize(b); ++s)
        {
                position p = blockPosition(b, s);
                p.x += t->currentPos.x + ((right)?1:-1);
                p.y += t->currentPos.y;

                if (p.y < t->size.y && p.y >= 0)
                        if (p.x >= t->size.x || p.x < 0 || !t->tab[p.y][p.x].empty)
                                return 0;
        }
        return 1;
}
Beispiel #3
0
void ttFillWithCurrentBlock(tetris_table* t)
{
        block* b = t->next_block[0];
        for (uint16_t s = 0; s < blockSize(b); ++s)
        {
                position p = blockPosition(b, s);
                p.x += t->currentPos.x;
                p.y += t->currentPos.y;

                if (p.x < t->size.x && p.y < t->size.y && p.x >= 0 && p.y >= 0)
                {
                        t->tab[p.y][p.x].type = blockType(b);
                        t->tab[p.y][p.x].empty = 0;
                }
        }
}
Beispiel #4
0
char ttCanTurn(tetris_table* t, char right)
{
        block b;
        blockInitWithBlock(&b, t->next_block[0]);
        blockRotate(&b, right);

        for (uint16_t i = 0; i < blockSize(&b); ++i)
        {
                position p = blockPosition(&b, i);
                p.x += t->currentPos.x;
                p.y += t->currentPos.y;

                if (p.x < 0 || p.y >= t->size.y || p.x >= t->size.x || (p.y >= 0 && !t->tab[p.y][p.x].empty))
                {
                        blockFree(&b);
                        return 0;
                }
        }

        blockFree(&b);
        return 1;
}
		void addSplat(int textureIndex, const TextureSplat &splat)
		{
			if(blendings.empty())
				return;

			BlendStorage &storage = blendings[textureIndex];
			if(storage.weights.empty())
				storage.weights.resize(size.x * size.y);

			int limitY = splat.size.y;
			int limitX = splat.size.x;

			if(limitX + splat.position.x >= size.x - 2)
				limitX = size.x - 2 - splat.position.x;
			if(limitY + splat.position.y >= size.y - 2)
				limitY = size.y - 2 - splat.position.y;

			for(int j = 0; j < limitY; ++j)
			for(int i = 0; i < limitX; ++i)
			{
				int positionX = splat.position.x + i;
				int positionY = j + splat.position.y;
				int position = positionY * size.x + positionX;

				if(positionX < 0 || positionX >= size.x)
					continue;
				if(positionY < 0 || positionX >= size.x)
					continue;

				int oldWeight = storage.weights[position];
				int newWeight = splat.weights[j * splat.size.x + i];
				if(newWeight < oldWeight)
					continue;

				VC2I blockIndex(positionX / (BLOCK_SIZE - 1), positionY / (BLOCK_SIZE - 1));
				VC2I blockPosition(positionX - blockIndex.x * (BLOCK_SIZE - 1), positionY - blockIndex.y * (BLOCK_SIZE - 1));
				
				//if(blockPosition.x < 0 || blockPosition.y < 0)
				//	continue;
				//if(blockPosition.x >= blockAmount.x || blockPosition.y >= blockAmount.y)
				//	continue;

				// Normalize old weights
				{
					int sum = 255 - newWeight;
					for(unsigned int k = 0; k < blendings.size(); ++k)
					{
						int original = blendings[k].weights[position];
						blendings[k].weights[position] = sum * blendings[k].weights[position] / 255;

						if(original)
							setPixel(blockIndex, blockPosition, k, blendings[k].weights[position]);
					}

					int newSum = 0;
					for(unsigned int k = 0; k < blendings.size(); ++k)
					{
						if(int(k) != textureIndex)
							newSum += blendings[k].weights[position];
					}

					int diff = sum - newSum;
					newWeight += diff;
				}

				storage.weights[position] = newWeight;
				setPixel(blockIndex, blockPosition, textureIndex, newWeight);
			}
		}