コード例 #1
0
ファイル: MovieStub.cpp プロジェクト: CodeBlueDev/DGEngine
void Movie2::update(Game& game)
{
	if (visible == false)
	{
		return;
	}
	game.Events().addBack(actionComplete);
}
コード例 #2
0
ファイル: StringButton.cpp プロジェクト: CodeBlueDev/DGEngine
void StringButton::click(Game& game, bool playSound)
{
	if (enabled == false)
	{
		return;
	}
	if (clickAction != nullptr)
	{
		if (focusEnable == true)
		{
			game.Resources().setFocused(this);
			if (focusOnClick == true)
			{
				game.Events().addBack(focusAction);
			}
		}
		if (playSound == true)
		{
			game.addPlayingSound(clickSound.get());
		}
		if (toggleAction == nullptr)
		{
			game.Events().addBack(clickAction);
		}
		else
		{
			if (toggled == false)
			{
				toggled = true;
				game.Events().addBack(clickAction);
			}
			else
			{
				toggled = false;
				game.Events().addBack(toggleAction);
			}
		}
	}
}
コード例 #3
0
ファイル: Movie2.cpp プロジェクト: mewbak/DGEngine
void Movie2::update(Game& game)
{
	if (visible == false)
	{
		return;
	}

	movie.update();

	if (movie.getStatus() == sfe::Status::Stopped)
	{
		game.Events().addBack(actionComplete);
	}
}
コード例 #4
0
ファイル: Player.cpp プロジェクト: pezr/DGEngine
void Player::update(Game& game, Level& level)
{
	auto rect = sprite.getGlobalBounds();
	if (rect.contains(level.MousePosition()))
	{
		if (game.getMouseButton() == sf::Mouse::Left)
		{
			if (game.wasMouseClicked() == true)
			{
				game.clearMouseClicked();
				if (clickAction != nullptr)
				{
					game.Events().addBack(clickAction);
				}
			}
		}
	}
	if (rect.width > 0 && rect.height > 0)
	{
		calculatePosition(level, sf::Vector2u(rect.width, rect.height));
	}

	if (frameRange.first > frameRange.second)
	{
		return;
	}

	// add delta time
	m_currentTime += game.getElapsedTime();

	// if current time is bigger then the frame time advance one frame
	if (m_currentTime >= m_frameTime)
	{
		// reset time, but keep the remainder
		m_currentTime = sf::microseconds(m_currentTime.asMicroseconds() % m_frameTime.asMicroseconds());

		currentFrame++;
		if (currentFrame < frameRange.first || currentFrame >= frameRange.second)
		{
			currentFrame = frameRange.first;
		}

		if (currentFrame < celTexture->size(celIdx))
		{
			sprite.setTexture(celTexture->get(celIdx, currentFrame), true);
		}
	}
}
コード例 #5
0
ファイル: ScrollableText.cpp プロジェクト: mewbak/DGEngine
void ScrollableText::update(Game& game)
{
	if (pause == true || visible == false)
	{
		return;
	}

	// add delta time
	currentTime += game.getElapsedTime();

	// if current time is bigger then the frame time advance one frame
	if (currentTime >= frameTime)
	{
		// reset time, but keep the remainder
		currentTime = sf::microseconds(currentTime.asMicroseconds() % frameTime.asMicroseconds());

		auto rect = view.getCenter();
		auto yy = (int)text->Size().y;
		if (rect.y - (height / 2) < yy)
		{
			rect.y++;
		}
		else
		{
			rect.y = -(float)height;

			if (loop == false)
			{
				pause = true;
			}

			game.Events().addBack(action);
		}

		view.setCenter(rect);
	}
}
コード例 #6
0
ファイル: StringButton.cpp プロジェクト: CodeBlueDev/DGEngine
void StringButton::update(Game& game)
{
	if (visible == false)
	{
		return;
	}

	text->update(game);

	auto rect = text->getGlobalBounds();
	if (rect.contains(game.MousePosition()))
	{
		if (hovered == false)
		{
			hovered = true;
			if (hoverEnterAction != nullptr)
			{
				game.Events().addBack(hoverEnterAction);
			}
		}
		if (game.getMouseButton() == sf::Mouse::Left)
		{
			if (game.wasMouseClicked() == true)
			{
				game.clearMouseClicked();
				beingDragged = true;
				if (clickInAction != nullptr)
				{
					game.Events().addFront(clickInAction);
				}
				if (clickUp == false)
				{
					click(game, true);
					if (game.wasMouseDoubleClicked() == true)
					{
						if (doubleClickAction != nullptr)
						{
							game.Events().addBack(doubleClickAction);
						}
					}
				}
			}
			else if (game.wasMouseReleased() == true)
			{
				if (clickOutAction != nullptr)
				{
					game.Events().addFront(clickOutAction);
				}
				if (clickUp == true && beingDragged == true)
				{
					click(game, true);
				}
				beingDragged = false;
			}
		}
	}
	else
	{
		if (game.wasMouseReleased() == true && game.getMouseButton() == sf::Mouse::Left)
		{
			beingDragged = false;
			if (clickOutAction != nullptr)
			{
				game.Events().addFront(clickOutAction);
			}
		}
		if (hovered == true)
		{
			hovered = false;
			if (hoverLeaveAction != nullptr)
			{
				game.Events().addFront(hoverLeaveAction);
			}
		}
	}
	if (beingDragged == true && game.wasMouseMoved() == true)
	{
		if (clickDragAction != nullptr)
		{
			game.Events().addFront(clickDragAction);
		}
	}
}
コード例 #7
0
ファイル: StringButton.cpp プロジェクト: CodeBlueDev/DGEngine
void StringButton::focus(Game& game)
{
	game.addPlayingSound(focusSound.get());
	game.Events().addBack(focusAction);
}
コード例 #8
0
ファイル: ParseMovie.cpp プロジェクト: pezr/DGEngine
	void parseMovie(Game& game, const Value& elem)
	{
		if (isValidString(elem, "id") == false || isValidString(elem, "file") == false)
		{
			return;
		}

		std::shared_ptr<Action> action;
		if (elem.HasMember("onComplete"))
		{
			action = parseAction(game, elem["onComplete"]);
		}
		auto movie = std::make_shared<Movie2>(elem["file"].GetString());
		if (movie->load() == false)
		{
			if (action != nullptr)
			{
				game.Events().addBack(action);
			}
			return;
		}
		else
		{
			if (action != nullptr)
			{
				movie->setActionComplete(action);
			}
		}

		auto anchor = getAnchor(elem, "anchor");
		movie->setAnchor(anchor);
		auto pos = getVector2f<sf::Vector2f>(elem, "position");
		auto size = getVector2i<sf::Vector2f>(elem, "size", movie->Size());
		if (getBool(elem, "relativeCoords", true) == true)
		{
			GameUtils::setAnchorPosSize(anchor, pos, size, game.RefSize(), game.MinSize());
			if (game.StretchToFit() == false)
			{
				GameUtils::setAnchorPosSize(anchor, pos, size, game.MinSize(), game.WindowSize());
			}
		}
		movie->Position(pos);
		movie->Size(size);

		auto volume = getVariable(elem, "volume");
		auto vol = game.getVariable<int64_t, unsigned>(volume, game.MusicVolume());
		if (vol > 100)
		{
			vol = 100;
		}
		movie->setVolume((float)vol);

		movie->Visible(getBool(elem, "visible", true));

		game.Resources().addDrawable(elem["id"].GetString(), movie);

		try
		{
			movie->play();
		}
		catch (std::exception ex)
		{
			std::cerr << ex.what();
		}
	}