Ejemplo n.º 1
0
int main(void) {

	sf::RenderWindow window(sf::VideoMode(1920,1080), "TEST");
	int word[8] = {7,3,6,2,6,9,1,6};
	printArr(word, 8);
	SORT(word, word + 8);
	printArr(word, 8);

	char numbers[6] = "54321";
	SORT(numbers, numbers + 5);
	printf("%s\n", numbers);

	sf::Sprite sprite;
	sf::Texture texture;
	texture.loadFromFile("../../bin/tileSheets/walkSequence.png");
	//texture.loadFromFile("../../bin/planet.png");

	sprite.setTexture(texture);
	sprite.setTextureRect(sf::IntRect(6144-512,512,512,512));
	HitBoxBase<sf::FloatRect> hbox = *(HitBoxBase<sf::FloatRect>*)GenerateHitBox(sprite);
	printv(hbox._hbox.top);	
	printv(hbox._hbox.left);	
	printv(hbox._hbox.width);	
	printv(hbox._hbox.height);	
	while (window.isOpen()) {
		sf::Event event;
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed)
				window.close();
		}
		window.clear();
		window.draw(sprite);
		window.display();
	}
	

	return 0;
}
Ejemplo n.º 2
0
	void Player::Update(bool keys[], Map &map)
	{
		const int FRAMES_PER_ANIMATION = frameArraySize.x * frameArraySize.x;
		hasMoved = false;

		if(health <= 0 && state != DYING && state != DEAD)
		{
			Die();
			state = DYING;
		}

		const bool moveUp		=	keys[KEY_UP]	|| keys[KEY_W];
		const bool moveLeft		=	keys[KEY_LEFT]	|| keys[KEY_A];
		const bool moveDown		=	keys[KEY_DOWN]	|| keys[KEY_S];
		const bool moveRight	=	keys[KEY_RIGHT] || keys[KEY_D];

		const bool attack		=	keys[KEY_SPACE];

		if(state == DYING || state == DEAD)
		{
			if(attackCounter++ == FRAMES_PER_ANIMATION)
			{
				state = DEAD;
				attackCounter = 0;
			}
		}
		else if(attack)
		{
			if(attacking == false)
			{
				attackCounter = 0;
				attacking = true;
				Attack();
			}
		}

		if(experience >= pow(2.0, level + 1))
		{
			LevelUp();   
		}

		if(state != DYING && state != DEAD)
		{
			if((moveUp || moveLeft || moveDown || moveRight || attacking) == false)
			{
				Rest();
			}
			else if(attacking)
			{
				if(attackCounter++ == FRAMES_PER_ANIMATION) 
				{
					for(std::vector<Enemy*>::iterator it = map.enemies.begin(); it != map.enemies.end(); ++it)
					{
						if(GenerateHitBox(direction).Intersects((*it)->GetBounds()))
						{
							(*it)->health -= 10;
						}
					}

					attacking = false;
					attackCounter = 0;
				}
			}
			else
			{
				Vector2 coords = GetCoords();
				if((coords == previousCoords) == false)
				{
					previousCoords = coords;
					hasMoved = true;
				}

				if(moveUp)
				{
					if(moveLeft)
					{
						Move(map, NORTH_WEST);
					}
					else if(moveRight)
					{
						Move(map, NORTH_EAST);
					}
					else
					{
						Move(map, NORTH);
					}
				}
				else if(moveDown)
				{
					if(moveLeft)
					{
						Move(map, SOUTH_WEST);
					}
					else if(moveRight)
					{
						Move(map, SOUTH_EAST);
					}
					else
					{
						Move(map, SOUTH);
					}
				}
				else if(moveLeft)
				{
					Move(map, WEST);
				}
				else if(moveRight)
				{
					Move(map, EAST);
				}
			}
		}
	}