mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações Platform
This commit is contained in:
parent
febf3182dd
commit
fcb6ed41bd
@ -300,6 +300,14 @@ namespace xna {
|
|||||||
return a._ticks <= b._ticks;
|
return a._ticks <= b._ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend bool operator>(TimeSpan const& a, TimeSpan const& b) {
|
||||||
|
return a._ticks > b._ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator>=(TimeSpan const& a, TimeSpan const& b) {
|
||||||
|
return a._ticks >= b._ticks;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int64_t _ticks{ 0 };
|
int64_t _ticks{ 0 };
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef XNA_GRAPHICS_VIEWPORT
|
#ifndef XNA_GRAPHICS_VIEWPORT
|
||||||
#define XNA_GRAPHICS_VIEWPORT
|
#define XNA_GRAPHICS_VIEWPORT
|
||||||
|
|
||||||
|
#include "common/numerics.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
struct Viewport {
|
struct Viewport {
|
||||||
float X{ 0 };
|
float X{ 0 };
|
||||||
@ -23,6 +25,15 @@ namespace xna {
|
|||||||
&& MinDetph == other.MinDetph
|
&& MinDetph == other.MinDetph
|
||||||
&& MaxDepth == other.MaxDepth;
|
&& MaxDepth == other.MaxDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Rectangle Bounds() const {
|
||||||
|
return {
|
||||||
|
static_cast<int>(X),
|
||||||
|
static_cast<int>(Y),
|
||||||
|
static_cast<int>(Width),
|
||||||
|
static_cast<int>(Height),
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +119,56 @@ namespace PlatformerStarterKit {
|
|||||||
LoadNextLevel();
|
LoadNextLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawHud()
|
||||||
|
{
|
||||||
|
auto titleSafeArea = graphicsDevice->Viewport().Bounds();
|
||||||
|
auto hudLocation = Vector2(titleSafeArea.X, titleSafeArea.Y);
|
||||||
|
auto center = Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
|
||||||
|
titleSafeArea.Y + titleSafeArea.Height / 2.0f);
|
||||||
|
|
||||||
|
//string timeString = "TIME: " + to_string(level->TimeRemaining().Minutes()) + ":" + to_string(level->TimeRemaining().Seconds());
|
||||||
|
string timeString = "TIME";
|
||||||
|
Color timeColor;
|
||||||
|
if (level->TimeRemaining() > WarningTime ||
|
||||||
|
level->ReachedExit() ||
|
||||||
|
static_cast<int>(level->TimeRemaining().TotalSeconds()) % 2 == 0)
|
||||||
|
{
|
||||||
|
timeColor = Colors::Yellow;
|
||||||
|
} else {
|
||||||
|
timeColor = Colors::Red;
|
||||||
|
}
|
||||||
|
DrawShadowedString(*hudFont, timeString, hudLocation, timeColor);
|
||||||
|
|
||||||
|
|
||||||
|
float timeHeight = hudFont->MeasureString(timeString).Y;
|
||||||
|
DrawShadowedString(*hudFont, "SCORE: " + to_string(level->Score()), hudLocation + Vector2(0.0f, timeHeight * 1.2f), Colors::Yellow);
|
||||||
|
|
||||||
|
PTexture2D status = nullptr;
|
||||||
|
if (level->TimeRemaining() == TimeSpan::Zero())
|
||||||
|
{
|
||||||
|
if (level->ReachedExit()) {
|
||||||
|
status = winOverlay;
|
||||||
|
} else {
|
||||||
|
status = loseOverlay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!level->Player()->IsAlive()) {
|
||||||
|
status = diedOverlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
const auto statusSize = Vector2(status->Width(), status->Height());
|
||||||
|
spriteBatch->Draw(status, center - statusSize / 2, Colors::White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawShadowedString(SpriteFont& font, String const& value, Vector2 const& position, Color const& color)
|
||||||
|
{
|
||||||
|
spriteBatch->DrawString(font, value, position + Vector2(1.0f, 1.0f), Colors::Black);
|
||||||
|
spriteBatch->DrawString(font, value, position, color);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sptr<GraphicsDeviceManager> graphics = nullptr;
|
sptr<GraphicsDeviceManager> graphics = nullptr;
|
||||||
sptr<SpriteBatch> spriteBatch = nullptr;
|
sptr<SpriteBatch> spriteBatch = nullptr;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
namespace PlatformerStarterKit {
|
namespace PlatformerStarterKit {
|
||||||
Level::Level(xna::sptr<xna::IServiceProvider> const& serviceProvider, xna::String const& path) : path(path)
|
Level::Level(xna::sptr<xna::IServiceProvider> const& serviceProvider, xna::String const& path) : path(path)
|
||||||
{
|
{
|
||||||
//srand(354668);
|
srand(354668);
|
||||||
|
|
||||||
content = xna::snew<xna::ContentManager>("Content", serviceProvider);
|
content = xna::snew<xna::ContentManager>("Content", serviceProvider);
|
||||||
timeRemaining = xna::TimeSpan::FromMinutes(2.0);
|
timeRemaining = xna::TimeSpan::FromMinutes(2.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user