Skip to content

Commit

Permalink
Merge pull request #23 from BlackYoup/issue/20
Browse files Browse the repository at this point in the history
Set ship yaw accordingly to the keys the user is holding
  • Loading branch information
Noodlefu committed Apr 1, 2018
2 parents 895f874 + c725c6f commit 61474d2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
77 changes: 69 additions & 8 deletions Interface/ViewTactical.cpp
Expand Up @@ -101,6 +101,7 @@ ViewTactical::ViewTactical() :
m_CameraZoomLevel = 3;

m_fYaw = m_fYawV = 0.0f;
YawStatePressed m_yawState = YawStatePressed::None;
m_SetHeading = m_SetHeadingV = 0.0f;
m_SetVelocity = m_SetVelocityV = 0.0f;
m_BeginControl = false;
Expand Down Expand Up @@ -780,8 +781,13 @@ bool ViewTactical::onMessage( const Message & msg )
case HK_LEFT:
if ( m_bYawControl )
{
if ( m_fYaw > -1.0f )
if ( m_yawState != YawStatePressed::Left && m_yawState != YawStatePressed::Both )
{
if (m_yawState == YawStatePressed::Right)
m_yawState = YawStatePressed::Both;
else
m_yawState = YawStatePressed::Left;

m_BeginControl = true;
m_UpdateControl = true;
m_fYaw = -1.0f;
Expand All @@ -796,9 +802,13 @@ bool ViewTactical::onMessage( const Message & msg )
case 'A':
if ( m_bYawControl )
{
if ( m_fYaw > -1.0f )
if ( m_yawState != YawStatePressed::Left && m_yawState != YawStatePressed::Both )
{
m_BeginControl = true;
if (m_yawState == YawStatePressed::Right)
m_yawState = YawStatePressed::Both;
else
m_yawState = YawStatePressed::Left;

m_fYawV = -SET_YAW_RATE;
if ( m_fYaw > 0.0f )
Expand All @@ -814,8 +824,13 @@ bool ViewTactical::onMessage( const Message & msg )
case HK_RIGHT:
if ( m_bYawControl )
{
if ( m_fYaw < 1.0f )
if ( m_yawState != YawStatePressed::Right && m_yawState != YawStatePressed::Both )
{
if (m_yawState == YawStatePressed::Left)
m_yawState = YawStatePressed::Both;
else
m_yawState = YawStatePressed::Right;

m_BeginControl = true;
m_UpdateControl = true;
m_fYaw = 1.0f;
Expand All @@ -830,9 +845,13 @@ bool ViewTactical::onMessage( const Message & msg )
case 'D':
if ( m_bYawControl )
{
if ( m_fYaw < 1.0f )
if ( m_yawState != YawStatePressed::Right && m_yawState != YawStatePressed::Both )
{
m_BeginControl = true;
if (m_yawState == YawStatePressed::Left)
m_yawState = YawStatePressed::Both;
else
m_yawState = YawStatePressed::Right;

m_fYawV = SET_YAW_RATE;
if ( m_fYaw < 0.0f )
Expand Down Expand Up @@ -880,19 +899,61 @@ bool ViewTactical::onMessage( const Message & msg )
}
return true;
case HK_LEFT:
if (m_yawState == YawStatePressed::Both) {
m_yawState = YawStatePressed::Right;
m_fYaw = 1.0f;
m_UpdateControl = true;
}
else if (m_yawState == YawStatePressed::Left) {
m_yawState = YawStatePressed::None;
m_fYaw = m_fYawV = 0.0f;
m_UpdateControl = true;
}
return true;
case HK_RIGHT:
if ( m_fYaw != 0.0f )
{
if (m_yawState == YawStatePressed::Both) {
m_yawState = YawStatePressed::Left;
m_fYaw = -1.0f;
m_UpdateControl = true;
}
else if (m_yawState == YawStatePressed::Right) {
m_yawState = YawStatePressed::None;
m_fYaw = m_fYawV = 0.0f;
m_UpdateControl = true;
}
return true;
case 'A':
if (m_bYawControl) {
if (m_yawState == YawStatePressed::Both) {
m_yawState = YawStatePressed::Right;
m_fYawV = 1.0f;
m_UpdateControl = true;
}
else if (m_yawState == YawStatePressed::Left) {
m_yawState = YawStatePressed::None;
m_fYawV = 0.0f;
m_UpdateControl = true;
}
}
else
{
if ( m_SetHeadingV != 0.0f )
{
m_SetHeadingV = 0.0f;
m_UpdateControl = true;
}
}
return true;
case 'D':
if ( m_bYawControl )
{
if ( m_fYawV != 0.0f )
{
if (m_yawState == YawStatePressed::Both) {
m_yawState = YawStatePressed::Left;
m_fYawV = -1.0f;
m_UpdateControl = true;
}
else if (m_yawState == YawStatePressed::Right) {
m_yawState = YawStatePressed::None;
m_fYawV = 0.0f;
m_UpdateControl = true;
}
Expand Down
8 changes: 8 additions & 0 deletions Interface/ViewTactical.h
Expand Up @@ -22,6 +22,13 @@ class ViewGame;

//----------------------------------------------------------------------------

enum YawStatePressed {
None,
Left,
Right,
Both
};

class ViewTactical : public WindowView::View
{
public:
Expand Down Expand Up @@ -149,6 +156,7 @@ class ViewTactical : public WindowView::View
bool m_UpdateControl; // ship manual controls
float m_fYaw;
float m_fYawV;
YawStatePressed m_yawState;
float m_SetHeading;
float m_SetHeadingV;
float m_SetVelocity; // desired ship velocity
Expand Down

0 comments on commit 61474d2

Please sign in to comment.