Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The Door
#1
I had fun noodling around with this little proggie. It's an open and shut case... Thanks again to @bplus for cracking circle aspects for me a while back.
I included the .bas and 3 sound files in the attached zip to make it more Halloweeny - and easy to load.

Code: (Select All)
Option _Explicit
Screen _NewImage(1280, 720, 32)
_Delay .25: _ScreenMove _Middle
_PrintMode _KeepBackground
$Color:32
' ------------------------------
Const DoorColor = LightSeaGreen
' ------------------------------
Type point: x As Integer: y As Integer: End Type
' ------------------------------
Dim Shared Points(1 To 4) As point
Dim Shared As Integer i, angle, num
Dim Shared As Integer semi_maj, semi_min, doorFarX
Dim As _Byte opening, closing
Dim As Long S(2)
' ------------------------------
Dim Shared asp(1 To 90) '          thanks again, b+
i = 1: asp(1) = 1 '                make an array of aspect values, Note: asp(i) = Cos(_D2R(i)) will spin on the other axis
While i < 90: i = i + 1: asp(i) = 1 / Cos(_D2R(i)): Wend
' ------------------------------                                    a doorway formed with the hinge side first then other points fall along ellipses
Points(1).x = 600: Points(1).y = 300 '                              assign points 1 & 2
Points(2).x = 600: Points(2).y = 600
semi_maj = 150: semi_min = 16 '                                    ellipse dimensions for door to follow
doorFarX = semi_maj * Cos(_D2R(angle)) + Points(2).x '              door width
' ------------------------------
S(0) = _SndOpen("creakyDoor.mp3") '                                a few sound effects
S(1) = _SndOpen("shuttingDoor.mp3")
S(2) = _SndOpen("swingBack.mp3")
' ------------------------------
Do: Cls , MediumTurquoise
    Points(3).x = semi_maj * Cos(_D2R(angle)) + Points(1).x '      assign points 3 & 4
    Points(3).y = semi_min * Sin(_D2R(angle)) + Points(1).y '      using ellipse dims & points 1 & 2
    Points(4).x = semi_maj * Cos(_D2R(angle)) + Points(2).x
    Points(4).y = semi_min * Sin(_D2R(angle)) + Points(2).y

    ShowDoor
    If angle = 1 _AndAlso opening Then _SndPlay S(0) '              sound FX triggers
    If angle = 6 _AndAlso closing Then _SndPlay S(1)
    If angle = 135 _AndAlso closing Then _SndPlay S(2)
    If closing _AndAlso _SndPlaying(S(0)) Then _SndStop S(0)
    '                                                              * user input *
    If _KeyDown(111) Then opening = _TRUE: closing = _FALSE '      "o" to open
    If _KeyDown(99) Then closing = _TRUE: opening = _FALSE '        "c" to close
    If opening And angle = 168 Then opening = _FALSE '              door swing limits
    If closing And angle = 0 Then closing = _FALSE
    If opening Then angle = angle + 1 '                            auto-open/close
    If closing Then angle = angle - 1
    If angle > 359 Then angle = 0 '                                control spin angle
    If angle < 0 Then angle = 360 + angle

    If angle > 0 _AndAlso angle < 90 Then '                                                    black rectangle for black room inside
        Line (Points(3).x + (angle \ 12), Points(1).y)-(doorFarX, Points(2).y), _RGB32(0), BF
    ElseIf angle = 90 _OrElse angle = 91 Then
        Line (Points(1).x + (angle \ 12), Points(1).y)-(doorFarX, Points(2).y), _RGB32(0), BF
    ElseIf angle >= 92 Then
        Line (Points(1).x, Points(1).y)-(doorFarX, Points(2).y), _RGB32(0), BF
    End If
    ' ---------------
    If angle > 18 _AndAlso angle <= 90 Then '                                                  door edge box
        Line (Points(3).x, Points(1).y)-(Points(3).x + (angle \ 12), Points(4).y), Black, B
        Paint (Points(3).x + 1, Points(1).y + 5), DoorColor, Black
    End If
    If angle > 90 Then
        num = 180 - angle '                                                                    90 back to zero
        Line (Points(3).x, Points(1).y)-(Points(3).x + (num \ 10), Points(4).y), Black, B
        Paint (Points(3).x + 1, Points(1).y + 5), DoorColor, Black
    End If
    ' ---------------
    _UPrintString (550, _Height - 80), "Press 'o' to open, 'c' to close."
    _Display
    _Limit 45
Loop Until _KeyDown(27)

For i = 0 To UBound(S): _SndClose S(i): Next '                  release the sounds, Smithers.

System
' -----------------------------------------
Sub ShowDoor ()

    Dim As Integer knobX, knobY

    Line (Points(1).x, Points(1).y)-(Points(3).x, Points(1).y), Black '            door frame
    Line -(Points(4).x, Points(4).y), Black
    Line -(Points(2).x, Points(2).y), Black
    Line -(Points(1).x, Points(1).y), Black
    If angle > 90 Then Paint (Points(1).x - 2, Points(1).y + 10), Peru, Black '    paint different door sides
    If angle < 90 Then Paint (Points(1).x + 2, Points(1).y + 10), DoorColor, Black
    knobX = (semi_maj - 20) * Cos(_D2R(angle)) + Points(2).x '                      door knob code
    knobY = semi_min * Sin(_D2R(angle)) + Points(2).y - 130
    If angle >= 0 _AndAlso angle <= 80 Then
        Circle (knobX, knobY), 7, Black, , , asp(angle + 1)
        Paint (knobX, knobY), Green, Black
    End If
    If angle > 109 Then
        Circle (knobX, knobY), 7, Black, , , asp(num)
        Paint (knobX, knobY), Green, Black
    End If
End Sub
' -----------------------------------------


Attached Files
.zip   The Door.zip (Size: 111.24 KB / Downloads: 34)
Reply
#2
I did a door once too but it stays closed, nobody home!
Code: (Select All)
Option _Explicit
_Title "MakeDoor& function image handle" 'bplus 2023-11-03
Screen _NewImage(800, 600, 32)
Dim As Long door, i
door = MakeDoor&
For i = 0 To 50 Step 5
    Cls
    _PutImage (400 - 100 + i, 300 - 200 + 2 * i)-Step(200 - 2 * i, 400 - 4 * i), door, 0
    Sleep
Next
Function MakeDoor& () ' door is width X 3*width
    ' make huge door and use putimage to shrink into rectangle needed
    Dim As Long saveD, rtn, hx, hy, i
    Dim rr
    saveD = _Dest
    rtn = _NewImage(280, 560, 32)
    _Dest rtn
    hx = 140: hy = 280 'center
    Line (hx - 140, hy - 280)-Step(280, 560), &HFFFFAA77, BF

    Line (hx - 100, hy - 240)-(hx - 20, hy - 20), &HFFDD8853, BF
    For i = 0 To 9
        Line (hx - 100 + i, hy - 240 + i)-(hx - 20 - i, hy - 20 - i), &HFF000000 + _RGB32(i * 12, 50), B
    Next
    Line (hx + 20, hy - 240)-(hx + 100, hy - 20), &HFFDD8853, BF
    For i = 0 To 9
        Line (hx + 20 + i, hy - 240 + i)-(hx + 100 - i, hy - 20 - i), &HFF000000 + _RGB32(i * 12, 50), B
    Next
    Line (hx - 100, hy + 20)-(hx + 100, hy + 240), &HFFDD8853, BF
    For i = 0 To 9
        Line (hx - 100 + i, hy + 20 + i)-(hx + 100 - i, hy + 240 - i), &HFF000000 + _RGB32(i * 12, 50), B
    Next
    For rr = 0 To 12 Step .25
        Circle (hx + 120, hy), rr, _RGB32(255 - rr * 17, 255 - rr * 17, 255 - rr * 17, 100)
    Next
    MakeDoor& = rtn
    _Dest saveD
End Function

But your's, @NakedApe, looks good for an opening to a Halloween app! Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#3
And that's a great looking shrinking door you have there, b+. I should know, I'm a carpenter.
Reply
#4
LOL I forgot I did that, oh hey you can make it look like you are walking up to the door and then walk away.

You know I was painting 6 panel doors all July!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Forum Jump:


Users browsing this thread: