From 7d5a3c16c9ed4652245e93d1d78b1f628656b4f9 Mon Sep 17 00:00:00 2001 From: Nimra Bhatti Date: Fri, 17 Oct 2025 09:46:28 +0000 Subject: [PATCH] =?UTF-8?q?gamecube.cpp=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamecube.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 gamecube.cpp diff --git a/gamecube.cpp b/gamecube.cpp new file mode 100644 index 0000000..751af27 --- /dev/null +++ b/gamecube.cpp @@ -0,0 +1,66 @@ +#include "gamecube.h" + +gamecube::gamecube(const Vec3 &pos, Color col) + : position(pos), color(col) {} + +void gamecube::Update(float flipSpeed) +{ + if (flippingForward) + { + rotation += flipSpeed; + if (rotation >= 180.0f) + { + rotation = 180.0f; + flippingForward = false; + flipped = true; + } + } + else if (flippingBackward) + { + rotation -= flipSpeed; + if (rotation <= 0.0f) + { + rotation = 0.0f; + flippingBackward = false; + flipped = false; + } + } +} + +void gamecube::FlipForward() { flippingForward = true; } +void gamecube::FlipBackward() { flippingBackward = true; } + +bool gamecube::IsFlipped() const { return flipped; } +bool gamecube::IsMatched() const { return matched; } +void gamecube::SetMatched(bool m) { matched = m; } + +void gamecube::Draw() const +{ + rlPushMatrix(); + + // Matrizen für Rotation und Translation erzeugen + auto matrix_a = gameMatrix::translate({ position.x, position.y, position.z}); + auto matrix_b = gameMatrix::rot3D(rotation, 'y'); + + // Matrizen multiplizieren (Translation * Rotation) + auto model = gameMatrix::matmul(matrix_a, matrix_b); + + // transform for raylib matrix + float f[16]; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + f[j * 4 + i] = model[i][j]; + rlMultMatrixf(f); + + if (rotation < 90.0f) + DrawCube({0,0,0}, 1,1,1, GRAY); + else + DrawCube({0,0,0}, 1,1,1, color); + + DrawCubeWires({0,0,0}, 1,1,1, BLACK); + + rlPopMatrix(); +} + +Vec3 gamecube::GetPosition() const { return position; } +float gamecube::GetRotationY() const { return rotation; }