QB64 Phoenix Edition
Dice Demo - Two Versions of Rolling Dice. - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Prolific Programmers (https://staging.qb64phoenix.com/forumdisplay.php?fid=26)
+---- Forum: TheBOB (https://staging.qb64phoenix.com/forumdisplay.php?fid=27)
+---- Thread: Dice Demo - Two Versions of Rolling Dice. (/showthread.php?tid=232)



Dice Demo - Two Versions of Rolling Dice. - Pete - 04-27-2022

Dice-Demo.bas by Bob Seguin.
[Image: Screenshot-609.png]
Description: Two version of a dice rolling demo. The first roll effect is square, the second is diagonal.


Code: (Select All)
_Title "Dice Demo by Bob Seguin"
Dim DiceBOX(6000) As Integer '6 elements of 600 integers
Screen 12
Palette 0, 5120 'background becomes dark green
Palette 4, 63 'attribute 4 (red) becomes bright red
Palette 5, 53 'slightly darker red for shine effect
Palette 6, 42 'dark red for shading
For x% = 102 To 402 Step 60 'draw 6 dice
    PSet (x%, 100), 4
    Draw "R37 F2 D37 G2 L37 H2 U37 E2 BD P4,4"
Next x%
SpotDATA:
Data 121,121,173,130,190,112,241,121,230,133
Data 252,109,290,132,312,109,290,109,312,132
Data 361,120,350,132,372,109,350,109,372,132,410
Data 133,432,109,410,109,432,133,410,121,432,121
'Draw spots on dice
Restore SpotDATA
For Spots = 1 To 21
    Read x, y
    Circle (x, y), 5, 15
    Paint Step(0, 0), 15
    Circle Step(0, 0), 5, 7, 1, 3
Next Spots
'Draw alternative view of dice
'LINE (462, 95)-(502, 145), 15, B
'LINE (462, 120)-(502, 120), 15
PSet (462, 97), 5
Draw "E2 R38 F2 d23 G2 L38 H2 U23 bF3 P4,5 BH3 c5"
Draw "D27 R42 U4 D27 G2 L38 H2 U25 BF20 P6,5"
Paint (500, 123), 4, 5
'Add shading
For x% = 100 To 400 Step 60
    Line (x% + 3, 100)-(x% + 38, 102), 4, BF
    Line (x%, 103)-(x% + 2, 138), 4, BF
    Line (x% + 39, 103)-(x% + 41, 138), 6, BF
    Line (x% + 3, 139)-(x% + 38, 141), 6, BF
    Line (x% + 39, 139)-(x% + 40, 140), 6, BF
    PSet (x% + 39, 141), 6
    PSet (x% + 41, 139), 6
Next x%
'Add shine to dice
x% = 0
Do
    xx% = x%: y% = 140: Hop% = Fix(Rnd * 20)
    For Span% = x% To x% + Hop%
        Do
            If Point(xx%, y%) = 4 Then PSet (xx%, y%), 5
            xx% = xx% + 1: y% = y% - 1
        Loop While y% > 80
        xx% = Span%: y% = 140
    Next Span%
    x% = x% + Hop% + Fix(Rnd * 12)
Loop While x% < 600
Line (465, 96)-(500, 96), 4
Line (465, 125)-(500, 126), 4, B

'a$ = INPUT$(1) 'remove REM if you want to see the dice before they're used

For x% = 100 To 400 Step 60 'GET dice to array
    Get (x%, 90)-(x% + 43, 153), DiceBOX(Index%)
    Put (x%, 90), DiceBOX(Index%)
    Index% = Index% + 800
Next x%
Get (462, 90)-(505, 154), DiceBOX(4800)
Put (462, 90), DiceBOX(4800)
Randomize Timer
Locate 2, 2: Print "PRESS [SPACE] TO ROLL DICE, ANY OTHER KEY TO QUIT"
Do
    For Reps = 1 To 10
        Put (40, 30), DiceBOX(4800), PSet
        Put (100, 30), DiceBOX(4800), PSet
        Play "MBT120O6L64a"
        For Pause = 1 To 5
            Wait &H3DA, 8
            Wait &H3DA, 8, 8
        Next Pause
        Put (40, 30), DiceBOX(Fix(Rnd * 6) * 800), PSet
        Put (100, 30), DiceBOX(Fix(Rnd * 6) * 800), PSet
        Play "MBT120O6L64a"
        For Pause = 1 To 5
            Wait &H3DA, 8
            Wait &H3DA, 8, 8
        Next Pause
    Next Reps
    LD% = Fix(Rnd * 6) + 1 'Left die value
    RD% = Fix(Rnd * 6) + 1 'Right die value
    Total% = LD% + RD% 'Combined value
    Put (40, 30), DiceBOX((LD% - 1) * 800), PSet
    Put (100, 30), DiceBOX((RD% - 1) * 800), PSet
    Locate 7, 7: Print LD%
    Locate 7, 12: Print "+"
    Locate 7, 15: Print RD%
    Locate 7, 20: Print "="
    Locate 7, 23: Print Total%
    a$ = Input$(1)
    Locate 7, 7: Print Space$(19)
Loop While a$ = " "


Code: (Select All)
_Title "Dice Demo by Bob Seguin"
Dim DiceBOX(6000) As Integer
Screen 12
Palette 0, 5120 'background becomes dark green
Palette 4, 63 'attribute 4 (red) becomes bright red
Palette 5, 53 'slightly darker red for shine effect
Palette 6, 42 'dark red for shading
For x% = 102 To 402 Step 60 'draw 6 dice
    PSet (x%, 100), 4
    Draw "R37 F2 D37 G2 L37 H2 U37 E2 BD P4,4"
Next x%
SpotDATA:
Data 121,121,173,130,190,112,241,121,230,133
Data 252,109,290,132,312,109,290,109,312,132
Data 361,120,350,132,372,109,350,109,372,132,410
Data 133,432,109,410,109,432,133,410,121,432,121
'Draw spots on dice
Restore SpotDATA
For Spots = 1 To 21
    Read x, y
    Circle (x, y), 5, 15
    Paint Step(0, 0), 15
    Circle Step(0, 0), 5, 7, 1, 3
Next Spots
'Draw alternative view of dice
PSet (460, 110), 4
Draw "E20 r3 F20 d3 G20 L3 H20 U3 D23 F20 nU20 R3 Nu20 E20 U20"
PSet (463, 110), 4
Draw "E18 rf19 d G19 l H19 u"
Paint (470, 110), 4
Paint (461, 110), 5, 4
Paint (470, 140), 6, 4
Paint (481, 140), 5, 4
Paint (490, 140), 6, 4
'Add shine to dice
x% = 0
Do
    xx% = x%: y% = 140: Hop% = Fix(Rnd * 20)
    For Span% = x% To x% + Hop%
        Do
            If Point(xx%, y%) = 4 Then PSet (xx%, y%), 5
            xx% = xx% + 1: y% = y% - 1
        Loop While y% > 80
        xx% = Span%: y% = 140
    Next Span%
    x% = x% + Hop% + Fix(Rnd * 12)
Loop While x% < 600
'Add shading
For x% = 100 To 400 Step 60
    Line (x% + 3, 100)-(x% + 38, 102), 4, BF
    Line (x%, 103)-(x% + 2, 138), 4, BF
    Line (x% + 39, 103)-(x% + 41, 138), 6, BF
    Line (x% + 3, 139)-(x% + 38, 141), 6, BF
    Line (x% + 39, 139)-(x% + 40, 140), 6, BF
    PSet (x% + 39, 141), 6
    PSet (x% + 41, 139), 6
Next x%

'a$ = INPUT$(1) 'remove REM to view the dice before they're used

For x% = 100 To 400 Step 60 'GET dice to array
    Get (x%, 90)-(x% + 43, 153), DiceBOX(Index%)
    Put (x%, 90), DiceBOX(Index%)
    Index% = Index% + 800
Next x%
Get (460, 90)-(504, 154), DiceBOX(4800)
Put (460, 90), DiceBOX(4800)
Randomize Timer
Locate 2, 2: Print "PRESS [SPACE] TO ROLL DICE, ANY OTHER KEY TO QUIT"
Do
    For Reps = 1 To 10
        Put (40, 30), DiceBOX(4800), PSet
        Put (100, 30), DiceBOX(4800), PSet
        Play "MBT120O6L64a"
        For Pause = 1 To 4
            Wait &H3DA, 8
            Wait &H3DA, 8, 8
        Next Pause
        Put (40, 30), DiceBOX(Fix(Rnd * 6) * 800), PSet
        Put (100, 30), DiceBOX(Fix(Rnd * 6) * 800), PSet
        Play "MBT120O6L64a"
        For Pause = 1 To 4
            Wait &H3DA, 8
            Wait &H3DA, 8, 8
        Next Pause
    Next Reps
    LD% = Fix(Rnd * 6) + 1 'Left die value
    RD% = Fix(Rnd * 6) + 1 'Right die value
    Total% = LD% + RD% 'Combined value
    Put (40, 30), DiceBOX((LD% - 1) * 800), PSet
    Put (100, 30), DiceBOX((RD% - 1) * 800), PSet
    Locate 7, 7: Print LD%
    Locate 7, 12: Print "+"
    Locate 7, 15: Print RD%
    Locate 7, 20: Print "="
    Locate 7, 23: Print Total%
    a$ = Input$(1)
    Locate 7, 7: Print Space$(19)
Loop While a$ = " "