mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Correções em Platform
This commit is contained in:
parent
3e93d0ffbe
commit
febf3182dd
@ -24,6 +24,10 @@ namespace xna {
|
||||
impl->_dxSoundEffect = unew<DxSoundEffect>(AudioEngine::impl->_dxAudioEngine.get(), file.c_str());
|
||||
}
|
||||
|
||||
SoundEffect::~SoundEffect() {
|
||||
impl = nullptr;
|
||||
}
|
||||
|
||||
SoundEffect::SoundEffect(
|
||||
std::vector<Byte> const& format,
|
||||
std::vector<Byte> const& data,
|
||||
|
@ -34,6 +34,7 @@ namespace xna {
|
||||
Int loopStart,
|
||||
Int loopLength,
|
||||
TimeSpan const& duration);
|
||||
~SoundEffect();
|
||||
void Play();
|
||||
void Play(float volume, float pitch, float pan);
|
||||
uptr<SoundEffectInstance> CreateInstance();
|
||||
|
@ -476,6 +476,9 @@ namespace xna {
|
||||
};
|
||||
|
||||
struct SoundEffect::PlatformImplementation {
|
||||
~PlatformImplementation() {
|
||||
}
|
||||
|
||||
uptr<DirectX::SoundEffect> _dxSoundEffect = nullptr;
|
||||
};
|
||||
|
||||
|
@ -13,10 +13,10 @@ namespace PlatformerStarterKit {
|
||||
|
||||
void AnimationPlayer::Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch, xna::Vector2& position, xna::SpriteEffects spriteEffects) {
|
||||
if (animation == nullptr)
|
||||
std::exception();
|
||||
std::exception("No animation is currently playing.");
|
||||
|
||||
// Process passing time.
|
||||
time += (float)gameTime.ElapsedGameTime.TotalSeconds();
|
||||
time += static_cast<float>(gameTime.ElapsedGameTime.TotalSeconds());
|
||||
|
||||
while (time > animation->FrameTime()) {
|
||||
time -= animation->FrameTime();
|
||||
|
@ -15,7 +15,7 @@ namespace PlatformerStarterKit {
|
||||
}
|
||||
|
||||
void Gem::Update(xna::GameTime const& gameTime)
|
||||
{
|
||||
{
|
||||
constexpr float BounceHeight = 0.18f;
|
||||
constexpr float BounceRate = 3.0f;
|
||||
constexpr float BounceSync = -0.75f;
|
||||
@ -28,11 +28,12 @@ namespace PlatformerStarterKit {
|
||||
|
||||
void Gem::OnCollected(xna::sptr<Player>& collectedBy)
|
||||
{
|
||||
collectedSound->Play();
|
||||
collectedSound->Play();
|
||||
isCollected = true;
|
||||
}
|
||||
|
||||
void Gem::Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch)
|
||||
{
|
||||
{
|
||||
spriteBatch.Draw(texture, Position(), nullptr, Color, 0.0f, origin, 1.0f, xna::SpriteEffects::None, 0.0f);
|
||||
}
|
||||
}
|
@ -31,6 +31,10 @@ namespace PlatformerStarterKit {
|
||||
void Update(xna::GameTime const& gameTime);
|
||||
void OnCollected(xna::sptr<Player>& collectedBy);
|
||||
void Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch);
|
||||
|
||||
constexpr bool IsCollected() const {
|
||||
return isCollected;
|
||||
}
|
||||
|
||||
private:
|
||||
xna::PTexture2D texture = nullptr;
|
||||
@ -39,6 +43,7 @@ namespace PlatformerStarterKit {
|
||||
xna::Vector2 basePosition{};
|
||||
float bounce{ 0.0F };
|
||||
xna::sptr<PlatformerStarterKit::Level> level = nullptr;
|
||||
bool isCollected{ false };
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace PlatformerStarterKit {
|
||||
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);
|
||||
timeRemaining = xna::TimeSpan::FromMinutes(2.0);
|
||||
@ -112,7 +112,7 @@ namespace PlatformerStarterKit {
|
||||
if (player != nullptr)
|
||||
std::exception("A level may only have one starting point.");
|
||||
|
||||
start = RectangleExtensions::GetBottomCenter(GetBounds(x, y));
|
||||
start = RectangleExtensions::GetBottomCenter(GetBounds(x, --y));
|
||||
const auto _this = shared_from_this();
|
||||
player = xna::snew<PlatformerStarterKit::Player>(_this, start);
|
||||
|
||||
@ -149,10 +149,12 @@ namespace PlatformerStarterKit {
|
||||
for (size_t i = 0; i < gems.size(); ++i) {
|
||||
auto& gem = gems[i];
|
||||
|
||||
gem->Update(gameTime);
|
||||
if (gem->IsCollected())
|
||||
continue;
|
||||
|
||||
gem->Update(gameTime);
|
||||
|
||||
if (gem->BoundingCircle().Intersects(player->BoundingRectangle())) {
|
||||
gems.erase(gems.begin() + i--);
|
||||
OnGemCollected(gem, player);
|
||||
}
|
||||
}
|
||||
@ -168,6 +170,8 @@ namespace PlatformerStarterKit {
|
||||
for (size_t i = 0; i < enemies.size(); ++i) {
|
||||
auto& enemy = enemies[i];
|
||||
|
||||
enemy->Update(gameTime);
|
||||
|
||||
if (enemy->BoundingRectangle().Intersects(player->BoundingRectangle())) {
|
||||
OnPlayerKilled(enemy);
|
||||
}
|
||||
@ -223,7 +227,10 @@ namespace PlatformerStarterKit {
|
||||
|
||||
UpdateGems(gameTime);
|
||||
|
||||
if (player->BoundingRectangle().Top() >= Height() * Tile::Height)
|
||||
auto playerBounds = player->BoundingRectangle();
|
||||
auto heigth = Height();
|
||||
|
||||
if (playerBounds.Top() >= heigth * Tile::Height)
|
||||
OnPlayerKilled(nullptr);
|
||||
|
||||
UpdateEnemies(gameTime);
|
||||
@ -250,6 +257,10 @@ namespace PlatformerStarterKit {
|
||||
|
||||
for (size_t i = 0; i < gems.size(); ++i) {
|
||||
auto& gem = gems[i];
|
||||
|
||||
if (gem->IsCollected())
|
||||
continue;
|
||||
|
||||
gem->Draw(gameTime, spriteBatch);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ namespace PlatformerStarterKit {
|
||||
gamePadState.IsButtonDown(JumpButton) ||
|
||||
keyboardState.IsKeyDown(xna::Keys::Space) ||
|
||||
keyboardState.IsKeyDown(xna::Keys::Up) ||
|
||||
keyboardState.IsKeyDown(xna::Keys::W);
|
||||
keyboardState.IsKeyDown(xna::Keys::W);
|
||||
}
|
||||
|
||||
void Player::OnKilled(xna::sptr<Enemy>& killedBy)
|
||||
@ -171,15 +171,15 @@ namespace PlatformerStarterKit {
|
||||
void Player::HandleCollisions()
|
||||
{
|
||||
auto bounds = BoundingRectangle();
|
||||
auto leftTile = std::floor(static_cast<float>(bounds.Left()) / Tile::Width);
|
||||
auto rightTile = std::ceil((static_cast<float>(bounds.Right()) / Tile::Width)) - 1;
|
||||
auto topTile = std::floor(static_cast<float>(bounds.Top()) / Tile::Height);
|
||||
auto bottomTile = std::ceil((static_cast<float>(bounds.Bottom()) / Tile::Height)) - 1;
|
||||
auto leftTile = static_cast<int>(std::floor(static_cast<float>(bounds.Left()) / Tile::Width));
|
||||
auto rightTile = static_cast<int>(std::ceil((static_cast<float>(bounds.Right()) / Tile::Width))) - 1;
|
||||
auto topTile = static_cast<int>(std::floor(static_cast<float>(bounds.Top()) / Tile::Height));
|
||||
auto bottomTile = static_cast<int>(std::ceil((static_cast<float>(bounds.Bottom()) / Tile::Height))) - 1;
|
||||
|
||||
isOnGround = false;
|
||||
isOnGround = false;
|
||||
|
||||
for (size_t y = topTile; y <= bottomTile; ++y) {
|
||||
for (size_t x = leftTile; x <= rightTile; ++x) {
|
||||
for (int y = topTile; y <= bottomTile; ++y) {
|
||||
for (int x = leftTile; x <= rightTile; ++x) {
|
||||
auto collision = level->GetCollision(x, y);
|
||||
if (collision != TileCollision::Passable) {
|
||||
auto tileBounds = level->GetBounds(x, y);
|
||||
@ -189,11 +189,12 @@ namespace PlatformerStarterKit {
|
||||
auto absDepthY = std::abs(depth.Y);
|
||||
|
||||
if (absDepthY < absDepthX || collision == TileCollision::Platform) {
|
||||
if (previousBottom <= tileBounds.Top())
|
||||
isOnGround = true;
|
||||
const auto tileBoundsTop = tileBounds.Top();
|
||||
if (previousBottom <= tileBoundsTop)
|
||||
isOnGround = true;
|
||||
|
||||
if (collision == TileCollision::Impassable || IsOnGround()) {
|
||||
Position = xna::Vector2(Position.X, Position.Y + depth.Y);
|
||||
Position = xna::Vector2(Position.X, Position.Y + depth.Y);
|
||||
bounds = BoundingRectangle();
|
||||
}
|
||||
}
|
||||
@ -206,7 +207,7 @@ namespace PlatformerStarterKit {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
previousBottom = bounds.Bottom();
|
||||
}
|
||||
|
||||
|
@ -60,15 +60,17 @@ namespace PlatformerStarterKit {
|
||||
float jumpTime = false;
|
||||
xna::Rectangle localBounds{};
|
||||
|
||||
static constexpr float MoveAcceleration = 14000.0f;
|
||||
static constexpr float MaxMoveSpeed = 2000.0f;
|
||||
static constexpr float GroundDragFactor = 0.58f;
|
||||
static constexpr float AirDragFactor = 0.65f;
|
||||
static constexpr float MoveAcceleration = 13000.0f;
|
||||
static constexpr float MaxMoveSpeed = 1750.0f;
|
||||
static constexpr float GroundDragFactor = 0.48;
|
||||
static constexpr float AirDragFactor = 0.58f;
|
||||
|
||||
static constexpr float MaxJumpTime = 0.35f;
|
||||
static constexpr float JumpLaunchVelocity = -4000.0f;
|
||||
static constexpr float GravityAcceleration = 3500.0f;
|
||||
static constexpr float MaxFallSpeed = 600.0f;
|
||||
static constexpr float JumpControlPower = 0.14f;
|
||||
static constexpr float JumpLaunchVelocity = -3500.0f;
|
||||
static constexpr float GravityAcceleration = 3400.0f;
|
||||
static constexpr float MaxFallSpeed = 550.0f;
|
||||
static constexpr float JumpControlPower = 0.14f;
|
||||
|
||||
static constexpr float MoveStickScale = 1.0f;
|
||||
static constexpr xna::Buttons JumpButton = xna::Buttons::A;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user