Zum Inhalt springen

Creating a 3D Puzzle Game Like Geraniums Pot

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

💡 Having trouble with Scratch block assembly? Don’t know how to implement code logic? 🚀 Get Help Now

PM

PuzzleMaster_Dev

Posted on January 5, 2025 • Advanced

🧩 Need help creating a complex 3D puzzle game

I would like to make something similar to Geraniums Pot (a complex 3D puzzle with rotating pieces), but I don’t know how to approach this in Scratch. The challenges I’m facing:

  • How to represent 3D puzzle pieces in Scratch
  • Managing multiple rotating axes and plates
  • Collision detection between complex shapes
  • Tracking which pieces are connected to which plates
  • Implementing smooth 3D-like rotations

Could anyone with experience in complex puzzle mechanics help me understand the approach? 🤔

3D

ThreeDimensional_Expert

Replied 2 hours later • ⭐ Best Answer

Excellent challenge @PuzzleMaster_Dev! Creating a Geraniums Pot-style puzzle is definitely advanced, but totally doable in Scratch. Here’s a comprehensive approach:

📊 3D Puzzle Game System Flow

Here’s how the complex 3D puzzle mechanics work:

flowchart TD A[🎮 Game Start] --> B[Initialize Puzzle Data] B --> C[Create Puzzle Pieces] C --> D[Set Up Rotation Plates] D --> E[🔄 Game Loop] E --> F{Player Input?} F -->|Click Plate| G[Identify Clicked Plate] F -->|No Input| E G --> H[Find Connected Pieces] H --> I[Calculate Rotation Center] I --> J[Start Rotation Animation] J --> K[Update Piece Positions] K --> L[Apply 3D Transformation] L --> M[Check Collision Detection] M --> N{Pieces Overlap?} N -->|Yes| O[Resolve Collision] N -->|No| P[Update Visual Display] O --> P P --> Q{Puzzle Solved?} Q -->|No| E Q -->|Yes| R[🎉 Victory Animation] R --> S[Show Completion Message] style A fill:#e1f5fe style B fill:#f3e5f5 style G fill:#e8f5e8 style J fill:#fff3e0 style R fill:#fce4ec

🏗️ Step 1: Data Structure Setup

First, create lists to store your puzzle data:

    when flag clicked
// Initialize puzzle data lists
delete all of [Piece IDs v]
delete all of [Piece X v]
delete all of [Piece Y v]
delete all of [Piece Rotation v]
delete all of [Piece Plate v]
delete all of [Plate Centers X v]
delete all of [Plate Centers Y v]
delete all of [Plate Angles v]

// Set up initial puzzle state
set [Total Pieces v] to [12]
set [Total Plates v] to [3]
broadcast [Initialize Puzzle v]
  

🧩 Step 2: Piece Management System

Create a system to manage individual puzzle pieces:

    define Create Piece (id) (x) (y) (plate)
add (id) to [Piece IDs v]
add (x) to [Piece X v]
add (y) to [Piece Y v]
add [0] to [Piece Rotation v]
add (plate) to [Piece Plate v]

// Create visual representation
create clone of [Puzzle Piece v]
set [Piece ID v] to (id)
go to x: (x) y: (y)
switch costume to (join [piece_] (id))
show
  

🔄 Step 3: Rotation Mechanics

Implement the core rotation system:

    define Rotate Plate (plate_id) (angle)
set [Current Plate v] to (plate_id)
set [Rotation Angle v] to (angle)

// Get plate center coordinates
set [Plate X v] to (item (plate_id) of [Plate Centers X v])
set [Plate Y v] to (item (plate_id) of [Plate Centers Y v])

// Rotate all pieces connected to this plate
set [i v] to [1]
repeat (length of [Piece IDs v])
if <(item (i) of [Piece Plate v]) = (plate_id)> then
// Calculate new position after rotation
set [Old X v] to (item (i) of [Piece X v])
set [Old Y v] to (item (i) of [Piece Y v])

// Translate to origin
set [Rel X v] to ((Old X) - (Plate X))
set [Rel Y v] to ((Old Y) - (Plate Y))

// Apply rotation
set [New X v] to (((Rel X) * ([cos v] of (angle))) - ((Rel Y) * ([sin v] of (angle))))
set [New Y v] to (((Rel X) * ([sin v] of (angle))) + ((Rel Y) * ([cos v] of (angle))))

// Translate back
set [New X v] to ((New X) + (Plate X))
set [New Y v] to ((New Y) + (Plate Y))

// Update piece position
replace item (i) of [Piece X v] with (New X)
replace item (i) of [Piece Y v] with (New Y)

// Update piece rotation
set [Old Rotation v] to (item (i) of [Piece Rotation v])
replace item (i) of [Piece Rotation v] with ((Old Rotation) + (angle))
end
change [i v] by [1]
end

broadcast [Update Piece Positions v]
  

🎯 Step 4: Collision Detection

Implement collision checking before allowing rotations:

    define Check Rotation Valid (plate_id) (angle)
set [Rotation Valid v] to [true]

// Temporarily store current positions
set [Temp Positions v] to []
set [i v] to [1]
repeat (length of [Piece IDs v])
add (join (item (i) of [Piece X v]) (join [,] (item (i) of [Piece Y v]))) to [Temp Positions v]
change [i v] by [1]
end

// Perform test rotation
Rotate Plate (plate_id) (angle)

// Check for collisions
set [i v] to [1]
repeat (length of [Piece IDs v])
set [j v] to [1]
repeat (length of [Piece IDs v])
if <not <(i) = (j)>> then
set [Distance v] to ([sqrt v] of (((item (i) of [Piece X v]) - (item (j) of [Piece X v])) * ((item (i) of [Piece X v]) - (item (j) of [Piece X v]))) + (((item (i) of [Piece Y v]) - (item (j) of [Piece Y v])) * ((item (i) of [Piece Y v]) - (item (j) of [Piece Y v]))))
if <(Distance) < [30]> then
set [Rotation Valid v] to [false]
end
end
change [j v] by [1]
end
change [i v] by [1]
end

// If collision detected, revert positions
if <(Rotation Valid) = [false]> then
set [i v] to [1]
repeat (length of [Piece IDs v])
set [Pos Data v] to (item (i) of [Temp Positions v])
set [Comma Pos v] to [1]
repeat until <(letter (Comma Pos) of (Pos Data)) = [,]>
change [Comma Pos v] by [1]
end
replace item (i) of [Piece X v] with (letters [1] to ((Comma Pos) - [1]) of (Pos Data))
replace item (i) of [Piece Y v] with (letters ((Comma Pos) + [1]) to (length of (Pos Data)) of (Pos Data))
change [i v] by [1]
end
end
  

🖱️ Step 5: User Interaction

Add mouse controls for plate rotation:

    when flag clicked
forever
if <mouse down?> then
// Determine which plate is being clicked
set [Clicked Plate v] to [0]
set [i v] to [1]
repeat (Total Plates)
set [Plate X v] to (item (i) of [Plate Centers X v])
set [Plate Y v] to (item (i) of [Plate Centers Y v])
set [Distance to Plate v] to ([sqrt v] of (((mouse x) - (Plate X)) * ((mouse x) - (Plate X)) + ((mouse y) - (Plate Y)) * ((mouse y) - (Plate Y))))
if <(Distance to Plate) < [50]> then
set [Clicked Plate v] to (i)
end
change [i v] by [1]
end

// If a plate is clicked, rotate it
if <(Clicked Plate) > [0]> then
set [Rotation Angle v] to [15] // 15 degree increments
Check Rotation Valid (Clicked Plate) (Rotation Angle)
if <(Rotation Valid) = [true]> then
play sound [click v]
broadcast [Update Piece Positions v]
else
play sound [error v]
end
wait until <not <mouse down?>>
end
end
end
  

🎨 Step 6: Visual Updates

For each puzzle piece sprite, add this script:

    when I receive [Update Piece Positions v]
if <(Piece ID) > [0]> then
set [Index v] to [1]
repeat (length of [Piece IDs v])
if <(item (Index) of [Piece IDs v]) = (Piece ID)> then
go to x: (item (Index) of [Piece X v]) y: (item (Index) of [Piece Y v])
point in direction ((item (Index) of [Piece Rotation v]) + [90])
stop [this script v]
end
change [Index v] by [1]
end
end
  

🏆 Step 7: Win Condition

Check if the puzzle is solved:

    define Check Puzzle Solved
set [Puzzle Solved v] to [true]
set [i v] to [1]
repeat (length of [Piece IDs v])
set [Target X v] to (item (i) of [Target X Positions v])
set [Target Y v] to (item (i) of [Target Y Positions v])
set [Current X v] to (item (i) of [Piece X v])
set [Current Y v] to (item (i) of [Piece Y v])

set [Distance v] to ([sqrt v] of (((Current X) - (Target X)) * ((Current X) - (Target X)) + ((Current Y) - (Target Y)) * ((Current Y) - (Target Y))))
if <(Distance) > [5]> then
set [Puzzle Solved v] to [false]
end
change [i v] by [1]
end

if <(Puzzle Solved) = [true]> then
broadcast [Puzzle Complete v]
play sound [victory v]
end
  

This system provides:

  • ✅ Complex 3D-style puzzle mechanics
  • ✅ Multiple rotating plates with collision detection
  • ✅ Smooth piece movement and rotation
  • ✅ Robust data management system
  • ✅ Interactive mouse controls
  • ✅ Win condition checking

Start with a simple 3-piece, 2-plate version and gradually add complexity! 🧩

PM

PuzzleMaster_Dev

Replied 3 hours later

@ThreeDimensional_Expert This is absolutely incredible! 🤯

I never thought about using lists to manage the puzzle state like this. The collision detection system is brilliant, and I love how you broke down the rotation mathematics.

Quick question: How would I handle pieces that can be affected by multiple plates simultaneously?

AL

AdvancedLogic_Coder

Replied 1 hour later

@PuzzleMaster_Dev For pieces affected by multiple plates, you can use a list-based approach:

    // Instead of single plate per piece, use plate lists
delete all of [Piece Plates v] // This becomes a list of lists

// For a piece affected by plates 1 and 3:
add [1,3] to [Piece Plates v]

// When rotating, check all plates for each piece
define Get Piece Plates (piece_index)
set [Plate String v] to (item (piece_index) of [Piece Plates v])
delete all of [Current Piece Plates v]
set [i v] to [1]
repeat (length of (Plate String))
if <(letter (i) of (Plate String)) = [,]> then
// Found separator, process previous number
else
add (letter (i) of (Plate String)) to [Current Piece Plates v]
end
change [i v] by [1]
end
  

This way pieces can belong to multiple rotation groups! 🔄

VB

Vibelf_Community

Pinned Message • Moderator

🚀 Ready to Build Complex Puzzle Games?

Amazing discussion on advanced 3D puzzle mechanics! For those looking to create even more sophisticated puzzle games, our community can help you implement:

  • 🎯 Advanced 3D rendering techniques
  • 🌟 Complex physics simulations
  • 🎨 Procedural puzzle generation
  • 🏆 Multi-level puzzle progression systems

📚 Related Discussions

Ready to create mind-bending puzzle games? Get expert guidance from our advanced programming tutors in the Vibelf app!