Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
m_Zielx = asteroid->GetPositionX(); m_Ziely = asteroid->GetPositionY(); m_Raketerot_x = m_pSchuss->GetPosition().x - m_Zielx; m_Raketerot_y = m_pSchuss->GetPosition().y - m_Ziely; m_fResult = atan2 (m_Raketerot_x,m_Raketerot_y) * 180 / 3.14; if(m_fResult < 0) m_fResult = 360 + m_fResult; if(m_pSchuss->GetRotation() < m_fResult) m_pSchuss->Rotate(m_fSpeedX * g_pTimer->GetElapsed()); else if(m_pSchuss->GetRotation() > m_fResult) m_pSchuss->Rotate(-m_fSpeedX * g_pTimer->GetElapsed()); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
void CRocket::AutoMove(int Framerate) { m_Framerate = Framerate; m_AimX = 10.0f; m_AimY = 10.0f; // Dein Code float m_Raketerot_x = m_vPosition.x - m_AimX; float m_Raketerot_y = m_vPosition.y - m_AimY; float m_fResult = atan2 (m_Raketerot_x,m_Raketerot_y) * 180.0f / D3DX_PI; if(m_fResult < 0) m_fResult += 360; if(m_Rotation < m_fResult) m_Rotation += 0.1f; else if(m_Rotation > m_fResult) m_Rotation -= 0.1f; // Bewegung - schon älter, funktioniert Acc_VektX += sin(m_Rotation) * 0.5; Acc_VektY += cos(m_Rotation) * 0.5; if (m_ProportionalSpeed < 0) { m_vPosition.x -= (Acc_VektX * m_ProportionalSpeed) / Framerate; m_vPosition.y += (Acc_VektY * m_ProportionalSpeed) / Framerate; } else if (m_ProportionalSpeed > 0) { m_vPosition.x += (Acc_VektX * m_ProportionalSpeed) / Framerate; m_vPosition.y -= (Acc_VektY * m_ProportionalSpeed) / Framerate; } if (GetAbsoluteSpeed(m_Framerate) >= m_MaximumSpeed) { float Acc_Vect_Quotient = sqrt((pow(Acc_VektX, 2) + pow(Acc_VektY, 2)) / 400.0f); Acc_VektX /= Acc_Vect_Quotient; Acc_VektY /= Acc_Vect_Quotient; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
float m_Raketerot_x = m_vPosition.x - m_AimX; float m_Raketerot_y = m_vPosition.y - m_AimY; float m_fResult = atan2 (m_Raketerot_x,m_Raketerot_y); if(m_fResult < 0) m_fResult += 360; if (m_fResult > 360) m_fResult -= 360; if(m_Rotation < m_fResult) m_Rotation += 0.1f; else if(m_Rotation > m_fResult) m_Rotation -= 0.1f; |
C-/C++-Quelltext |
|
1 2 3 |
Xposi += speedx * sin (-(Schusss->GetRotation() * 3.14159265f) / 180.0) * g_pTimer->GetElapsed(); Yposi -= speedy * cos (-(Schusss->GetRotation() * 3.14159265f) / 180.0) * g_pTimer->GetElapsed(); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
float m_Result = atan2((m_vPosition.x - m_AimX), (m_vPosition.y - m_AimY)); m_Result = -m_Result; // Umdrehen - das war der "Hauptfehler" // Wenn die Rakete links ist, muss die Rotation umgedreht werden wenn sie kleiner 0 ist! Bei rechts ebenfalls, aber umgekehrt if ((m_vPosition.x < m_AimX) ) { if (m_TempRotation <= 0.0f) { m_TempRotation += 6.0f; } } if (m_vPosition.x > m_AimX) { if (m_TempRotation >= 0.0f) { m_TempRotation -= 6.0f; } } if(m_Rotation < m_Result) { m_TempRotation += 0.2f; // Genauigkeit } else if(m_Rotation < m_Result) { m_TempRotation -= 0.2f; // Genauigkeit } m_Rotation = m_TempRotation; |
Werbeanzeige