Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some spinning balls
#5
(03-02-2024, 07:24 PM)Marcus Wrote: Remember something very similar from n6, some balls spinning around in space.
...

3D BALLS PUZZLE
Make 3D Square 3x3
Input 0 to 26
You only have 10 attempts to solve this puzzle.

Example
14,17,19,20,22,23,24,25,26
Find other solutions !

Hint : Start with number 0

It gave me an idea to make a 3D Balls Puzzle game based on your code. Big Grin

Code:
'=====================================
' 3D BALLS PUZZLE
' Make 3D Square 3x3
' Input 0 to 26
'
' Example : 14,17,19,20,22,23,24,25,26
' Find other solutions !
'
' Reference (Marcus)
' - balls.n7
'======================================


'-------------------
'  INITIALIZATION
'-------------------
#win32
include "list.n7"
include "sfx.n7"
visible balls = List()
visible sfx = SFX() 'create an sfx instance

set window "3D BALLS PUZZLE", 600/2, 400/2,false,3
set redraw off

'color definition
visible black_alpha     = [0,0,0,64]
visible black           = [0,0,0]
visible white           = [255,255,255]
visible green           = [0,168,0]
visible red             = [255,0,0]

Setup()

temp = 0
try = 1

'-------------
'  MAIN LOOP
'-------------
do
    'Prepare Instruction
    set color green
    set caret 5,5;wln "Make 3D square 3x3"; wln "Input 0 to 26" ; wln "Attempt "+try
    set caret 5,height(primary)-50; wln "99 to clear screen"; wln "55 to quit"
    Sound(0.1,261.63*3);Sound(0.02,329.63*2)
   
    'choose balls
    set caret 5,50; temp = rln(2,TYPE_NUMBER)
    if temp>=0 and temp<=26 then ChooseBalls(temp)
    if temp = 99 then
        try = 0
        set color black; cls
    endif
    if temp = 55 end
    if try%10= 0 then
        set color green; set caret 5,100; wln "Try again !"
        try = 1
        temp = rln()
        set color black; cls
    else
        try = try + 1
    endif
    redraw; wait 2
   
    'clear input
    set color black; draw rect 5,50,40,20,1; draw rect 68,38,20,10,1;redraw
loop

'------------
' FUNCTIONS
'------------
function Ball(x, y, z)
    return [x: x, y: y, z: z, px: 0, py: 0, pz: 0]
endfunc

function Setup()
    'Balls in 3 x 3 x 3
    for z = -1 to 1 
        for y = -1 to 1 
            for x = -1 to 1 
                balls.Add(Ball(x, y, z))
            next
        next
    next

    'angles
    a1 = 5.76
    a2 = 3.76

    'calculate balls' coordinate
    for i = 0 to 26
        ball = balls[i]
       
        ball.px = ball.x
        ball.py = ball.y
        ball.pz = ball.z
       
        x = ball.px*cos(a1) - ball.py*sin(a1)
        y = ball.py*cos(a1) + ball.px*sin(a1)
       
        ball.px = x
        ball.py = y
       
        z = ball.pz*cos(a2) - ball.py*sin(a2)
        y = ball.py*cos(a2) + ball.pz*sin(a2)
       
        ball.pz = z
        ball.py = y
       
        ball.pz = ball.pz + 5.5
        ball.px = width(primary)/2+ 200*ball.px/ball.pz +70
        ball.py = height(primary)/2 + 200*ball.py/ball.pz
    next
   
    balls.SortByField("pz", balls.DESCENDING)
endfunc

function ChooseBalls(i)
    'radius of each ball
    s = 100/balls[i].pz
   
    'Draw 3D balls
    set color red; draw ellipse balls[i].px, balls[i].py, s, s,1
    set color white; draw ellipse balls[i].px, balls[i].py, s, s
    set caret balls[i].px, balls[i].py; wln i
       
    'Draw little dot of light reflection
    set color white; draw ellipse balls[i].px - s*0.4, balls[i].py - s*0.4, s*0.25, s*0.25,1
endfunc

function Sound(b,x)
    'SquareWave(duration,freq,volume)
    mytune = sfx.SquareWave(b,x,0.05)
    play sound mytune
    wait 50
    free sound mytune 'release sound from memory
endfunc

Edit
- added sound effect
- limit attempts to solve : 10 times only
Reply


Messages In This Thread
Some spinning balls - by Marcus - 03-02-2024, 07:24 PM
RE: Some spinning balls - by johnno56 - 03-03-2024, 02:02 AM
RE: Some spinning balls - by Marcus - 03-03-2024, 08:09 AM
RE: Some spinning balls - by johnno56 - 03-03-2024, 09:13 AM
RE: Some spinning balls - by 1micha.elok - 03-04-2024, 11:16 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)