implement laser target offset
This commit is contained in:
@@ -118,6 +118,7 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
|
||||
, m_demolishMode(false)
|
||||
, m_demolishHoverId(kInvalidEntityId)
|
||||
, m_debugDraw(false)
|
||||
, m_rng(std::random_device{}())
|
||||
, m_boxSelecting(false)
|
||||
, m_scrollLeft(false)
|
||||
, m_scrollRight(false)
|
||||
@@ -158,9 +159,25 @@ void GameWorldView::onFrame()
|
||||
const std::vector<FireEvent> fires = m_sim->drainFireEvents();
|
||||
for (const FireEvent& fe : fires)
|
||||
{
|
||||
float maxRadius = 0.125f;
|
||||
const Building* tBld = m_sim->buildings().findBuilding(fe.target);
|
||||
if (tBld)
|
||||
{
|
||||
const int shorter = std::min(tBld->footprint.width(),
|
||||
tBld->footprint.height());
|
||||
maxRadius = shorter / 2.0f;
|
||||
}
|
||||
|
||||
std::uniform_real_distribution<float> angleDist(0.0f, 6.28318530f);
|
||||
std::uniform_real_distribution<float> radiusDist(0.0f, maxRadius);
|
||||
const float angle = angleDist(m_rng);
|
||||
const float radius = radiusDist(m_rng);
|
||||
|
||||
ActiveBeam beam;
|
||||
beam.event = fe;
|
||||
beam.emittedWallMs = m_wallMs;
|
||||
beam.targetOffset = QVector2D(radius * std::cos(angle),
|
||||
radius * std::sin(angle));
|
||||
m_activeBeams.push_back(beam);
|
||||
}
|
||||
}
|
||||
@@ -821,7 +838,8 @@ void GameWorldView::drawBeams(QPainter& painter)
|
||||
const std::optional<QVector2D> shooterPos = entityPosition(beam.event.shooter);
|
||||
const std::optional<QVector2D> targetPos = entityPosition(beam.event.target);
|
||||
if (!shooterPos.has_value() || !targetPos.has_value()) { continue; }
|
||||
painter.drawLine(worldToWidget(*shooterPos), worldToWidget(*targetPos));
|
||||
painter.drawLine(worldToWidget(*shooterPos),
|
||||
worldToWidget(*targetPos + beam.targetOffset));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
@@ -116,6 +117,7 @@ private:
|
||||
{
|
||||
FireEvent event;
|
||||
qint64 emittedWallMs;
|
||||
QVector2D targetOffset;
|
||||
};
|
||||
|
||||
struct ToastEntry
|
||||
@@ -136,6 +138,7 @@ private:
|
||||
TickDriver m_tickDriver;
|
||||
QElapsedTimer m_frameTimer;
|
||||
qint64 m_wallMs;
|
||||
std::mt19937 m_rng;
|
||||
double m_gameSpeedMultiplier;
|
||||
double m_prevNonZeroSpeed;
|
||||
float m_scrollXTiles;
|
||||
|
||||
Reference in New Issue
Block a user