Code/Example Codes and examples of codes to use in BAM

Coding and examples for future Pinball and BAM
I have some ideas of things you could do with BAM and I never posted.

Smooth flasher (or any other light), which turns on/off smoothly.

smooth-flasher.gif


Code:
Class SmoothLight
    Public Light, LightExt
    Public RampColors(), RampLength
    Public LitColor, UnlitColor, CurrentState
    Private bTurningOn, bTurningOff, RampIndex, BlinkPatternIndex

    Public Function Define(ByVal obj, ByVal r)
        ' Set Lights and color parameters
        Set Light = obj
        Set LightExt = Eval(obj.name + "Ext")
        LitColor = Light.LitColour
        UnlitColor = Light.UnlitColour
        RampLength = r
        ' Set default parameters
        CurrentState = BulbOff
        bTurningOn = False
        bTurningOff = False
        RampIndex = 0
        BlinkPatternIndex = 0
        Redim RampColors(RampLength)
        ' S_tart, E_nd, D_ifference and C_urrent variables of RBG values
        Dim sR, sG, sB, eR, eG, eB, dR, dG, dB, cR, cB, cG
        sR = UnlitColor Mod 256
        sG = ((UnlitColor - sR) / 256) Mod 256
        sB = ((((UnlitColor - sR) / 256) - sG) / 256) Mod 256
        eR = LitColor Mod 256
        eG = ((LitColor - eR) / 256) Mod 256
        eB = ((((LitColor - eR) / 256) - eG) / 256) Mod 256
        dR = eR - sR : dG = eG - sG : dB = eB - sB
        RampColors(0) = UnlitColor
        Dim i : For i = 1 To RampLength
            cR = CInt(sR + (dR / RampLength) * i)
            cG = CInt(sG + (dG / RampLength) * i)
            cB = CInt(sB + (dB / RampLength) * i)
            RampColors(i) = RGB(cR, cG, cB)
        Next
    End Function

    Property Get State
        State = CurrentState
    End Property

    Property Let State(ByVal Value)
        If (CurrentState = Value) Then Exit Property
        CurrentState = Value
        BlinkPatternIndex = 1
        If (Value > 0) Then
            bTurningOn = True
        Else
            bTurningOff = True
        End If
    End Property

    Public Function ForceState(ByVal Value)
        Light.State = Value
        If (Value > 0) Then
            RampIndex = RampLength
            CurrentState = BulbOn
        Else
            RampIndex = 0
            CurrentState = BulbOff
        End If
        SetLitColorFromIndex()
        bTurningOn = False
        bTurningOff = False
    End Function

    Private Function SetLitColorFromIndex()
        Dim color, cR, cG, cB
        color = RampColors(RampIndex)
        cR = color Mod 256
        cG = ((color - cR) / 256) Mod 256
        cB = ((((color - cR) / 256) - cG) / 256) Mod 256
        LightExt.SetLitColor cR, cG, cB
    End Function

    Private Function AdvanceBlinkPattern()
        If (CurrentState = BulbBlink) Then
            BlinkPatternIndex = BlinkPatternIndex + 1
            If (BlinkPatternIndex > Len(Light.BlinkPattern)) Then
                BlinkPatternIndex = 1
            End If
            If (Mid(Light.BlinkPattern, BlinkPatternIndex, 1) = "1") Then
                bTurningOn = True
            Else
                bTurningOff = True
            End If
        End If
    End Function

    Public Function Update()
        If (bTurningOn = True) Then
            If (RampIndex = RampLength) Then
                bTurningOn = False
                AdvanceBlinkPattern()
                Exit Function
            End If
            RampIndex = RampIndex + 1
            Light.State = BulbOn
            SetLitColorFromIndex()
            If (RampIndex = RampLength) Then
                RampIndex = RampLength
                bTurningOn = False
                AdvanceBlinkPattern()
            End If
            Exit Function
        End If
        If (bTurningOff = True) Then
            If (RampIndex = 0) Then
                bTurningOff = False
                AdvanceBlinkPattern()
                Exit Function
            End If
            RampIndex = RampIndex - 1
            Light.State = BulbOn
            SetLitColorFromIndex()
            If (RampIndex = 0) Then
                Light.State = BulbOff
                RampIndex = 0
                bTurningOff = False
                AdvanceBlinkPattern()
            End If
            Exit Function
        End If
    End Function
End Class

Dim SmoothFlasher1, SmoothFlasher2

Sub SmoothLightsDemo()
    ' Set smooth lights
    Set SmoothFlasher1 = New SmoothLight
    Set SmoothFlasher2 = New SmoothLight
    SmoothFlasher1.Define Flasher1, 16
    SmoothFlasher2.Define Flasher2, 16

    SmoothFlasher1.State = BulbBlink
    SmoothFlasher2.State = BulbBlink

    Flasher1Ext.Brightness = 2
    Flasher2Ext.Brightness = 2
End Sub

Sub SmoothLightTimer_Expired()
    SmoothFlasher1.Update()
    SmoothFlasher2.Update()
End Sub

You could also upgrade this to make lights that only turn on "partially" in some cases. I've seen that in some real pinball, for example in Monster Bash. It could even be used for advanced light sequences.

A Captive ball hitter would be similar to a Newton ball; something that has a captive ball behind which reacts to it being hit. In this case, though, it would be a target instead.

captive-ball.png


Code:
Dim CaptiveBall ' Captive balls

Sub CaptiveHitterDemo()
    ' Create captive balls
    CaptiveBallKicker.CreateCaptiveBall
    Set CaptiveBall = xBAM.BallCloseTo(CaptiveBallKicker.X, CaptiveBallKicker.Y, 0)
    CaptiveBallKicker.SolenoidPulse()
End Sub

' Function to get the arctangent between two numbers
Function Atn2(y, x)
    If (x > 0) Then
        Atn2 = Atn(y / x)
        Exit Function
    End If
    If (x < 0) And (y >= 0) Then
        Atn2 = Atn(y / x) + 3.1415
        Exit Function
    End If
    If (x < 0) And (y < 0) Then
        Atn2 = Atn(y / x) - 3.1415
        Exit Function
    End If
    If (x = 0) And (y > 0) Then
        Atn2 = 3.1415 / 2
        Exit Function
    End If
    If (x = 0) And (y < 0) Then
        Atn2 = -3.1415 / 2
        Exit Function
    End If
    Atn2 = Null
End Function

' Calculate the force returned by a Newton ball
' > ObjAngle - Newton ball's angle
' > ForceR   - Force ratio of transmission, from 0.0 to 1.0
' > MinPrec  - Minimum required precision, from 0.0 to 1.0
Function GetNewtonBallForce(ObjAngle, ForceR, MinPrec)
    Dim x, y, theta, r
    ' Get the angle of the hit
    x = xBAM.Ball.Velocity.X
    y = xBAM.Ball.Velocity.Y
    theta = (Atn2(x, y) * 360 / (3.1415 * 2))
    theta = (theta + 180) Mod 360
    theta = (ObjAngle + theta) Mod 360
    ' Get the force multiplier based on the angle
    If (theta > 180) Then r = 360 - theta Else r = theta
    r = Abs(1.0 - (theta / 180))
    If (r <= MinPrec) Then
        GetNewtonBallForce = 0
        Exit Function
    End If
    ' Return the force
    GetNewtonBallForce = xBAM.Ball.Speed * r * ForceR
End Function

' Newton Ball
Sub CaptiveHitter_Hit()
    ' If Bam is not defined ignore the effect entirely
    If (BAM_VERSION = 0) Then Exit Sub
    ' Play ball hit sound
    Playsound "Bumper1"
    ' Get the force and the angle in which the ball will recede (polar coordinates)
    ' The more centered and fast the hit was, the stronger will be the effect
    Dim r : r = GetNewtonBallForce(CaptiveHitter.Rotation, 1.0, 0.5) : If (r = 0) Then Exit Sub
    Dim theta : theta = ((180 - CaptiveHitter.Rotation) * (3.1415 * 2) / 360)
    ' Convert to cartesian coordinates
    CaptiveBall.SetVelocity r * Cos(theta), r * Sin(theta)
End Sub

A target either with a horizontal pole and string behind, or alternatively, a leaf target that can recede, with a drop target orn hole. I don't have a code for this one, but it may probably be done with an edit of the Bullseye target, but with an appearance similar to a Vari target.

spring-target.png

(Yes, I drew the spring directly on the screenshot, ain't doing extra work for this one :bonk:)

The idea is simple, the stronger you hit it, the harder it pushes the ball back. Another version of this could include a kicker hole that could only be accessed if the string is pushed to its end. Even though it's a basic idea, applying the appropriate forces may be challenging.

A spinning disk with leaf targets (and maybe a bulb for each target) attached around, so they also spin.
Even though I made a version of extended spinning disks with BAM, this mechanism would probably require a rotating Mini-playfield.

The Wide EM Kicker (I don't know its name) from The Shadow Pinball could be achieved with BAM with a Mini-playfield that moves horizontally with the flippers. The mechanism reminds me of the Zipper Flippers, which may be used as a basis.
 
@Wecoc Glad to see you back with more goodies!

If you haven't seen it yet, @SpacePirateScott submitted a neat SPS Color Sequencer example / demo here:



I think you are one of the few people who would fully understand how most of it works :)
 
Yes, I saw that, but not in deep detail. Actually, I posted about it back then, it's cool. I've been visiting the forum every once in a while, lurking in the shadows, but I don't have much to post lately. I haven't done any pinball-related stuff for a while.

I actually tried to make a script involving DMD image handling, because I've always felt the default options sometimes fall a bit short for advanced DMD effects... But I found too many performance problems, so I had to abandon the project. I don't know if WScript could allow for some GDI32 stuff that may be handy for DMD effects and transitions (Blt, StretchBlt, Blend modes, etc) but that's out of my scope.

The rest of "pending" things I had aren't very relevant either. If someone has ideas involving BAM, maybe I can look into them.
 
J'ai remarqué la boule lumineuse dans le Master of .., y a-t-il un moyen de le faire ?



Résultats de traduction​

Résultat de traduction​

I noticed the glowing ball in the Master of .., is there a way to do it? Never seen it before right?
 
J'ai remarqué la boule lumineuse dans le Master of .., y a-t-il un moyen de le faire ?



Résultats de traduction​

Résultat de traduction​

I noticed the glowing ball in the Master of .., is there a way to do it? Never seen it before right?

Gimli created a ball that glows on Avatar. I am not sure how he did it.
 
Nice Wecoc. I especially liked the spinning targets idea. A long time ago, when Steve and I did Tutenkem, we had this idea that the snake pit was suppose to spin the targets as well as the spin disk, but this was before bam and the mini playfield feature. If anyone does this, I would be interested as I have a design that could use this feature as it would be pretty awesome to see in action.
 
J'ai remarqué la boule lumineuse dans le Master of .., y a-t-il un moyen de le faire ?



Résultats de traduction​

Résultat de traduction​

I noticed the glowing ball in the Master of .., is there a way to do it? Never seen it before right?

I'm not near my PC to show code examples, so my wording may be off here.

For the light, I use a BAM "detach flasher" command for the flasher light I want to use with the ball. This allows the light source of the flasher to be positioned wherever you want in realtime without its model. I hide the model under the lockbar area.

Then I use the DrawFrame Sub to have the flasher light change it's position to where the ball's position is in realtime whenever the "glowball" is intended. All this being BAM commands.

The ball itself is a BAM custom ball, which I use to change the colour of the ball / texture as needed to match the glow light effect.

Look at MOTU CE's Drawframe sub, and from there follow the variables / names / commands I use to get an idea.
 
Last edited:
This is for very niche cases, but someone might find this useful...
I recreated every FP default camera but using BAM calls instead. :userfriendly:

With this you can tweak them, add custom ones, remove "undesired" ones, disable camera ball track, disable looking to the backglass, etc. You can also change these parameters based on the situation; on multiball the camera could stop tracking the ball, on attract mode instead of the backglass the camera could pan to the apron, etc.

It sadly comes with certain limitations; I couldn't do this with F1-F8 keys, and requires an extra step to enable the default Manual Camera (although that one could technically be also rewritten... ain't touching that though :lol:).
 

Attachments

  • BAM Default Camera Rewrite.fpt
    226 KB · Views: 4


Write your reply...
General chit-chat
Help Users
You can interact with the ChatGPT Bot in any Chat Room and there is a dedicated room. The command is /ai followed by a space and then your ? or inquiry.
ie: /ai What is a EM Pinball Machine?
  • No one is chatting at the moment.
  • Chat Bot Mibs Chat Bot Mibs:
    Cicero Silva has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    manstein has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    1000 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Destruck62 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    WeadlyDeapon has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    SaixXemnas has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Gege has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Fatmeatball has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    titomajo has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    daveseawater has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    rockin ray has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Citron68 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    hammerpower has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    max37170 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    OZZOLO has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    GG974 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    MSev has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    sghure has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    huik has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    ellitehaxor has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    KenF has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Mario1963 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    etherealmusic has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Snowstorm125 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    LBlackburn has left the room.


      Type /nick followed by the desired name to set your nickname.
      Chat Bot Mibs Chat Bot Mibs: LBlackburn has left the room.
      Back
      Top