' One of the simplest DirectX program you'll see for Rapid-Q by William Yu
' It's a nice side scroller, but does nothing more.

$TYPECHECK ON
$INCLUDE "RAPIDQ.INC"

DIM Form AS QForm
    Form.ClientHeight = 480
    Form.ClientWidth = 640
    Form.Center
DIM TheScreen AS QDXScreen
    TheScreen.Parent = Form
    TheScreen.Init(640, 480)
    TheScreen.Align = alClient
DIM DXImageList AS QDXImageList
DIM DXTimer AS QDXTimer
DIM Font AS QFont
    Font.Name = "Arial"
    Font.Size = 14
    Font.AddStyles(fsBold)
DIM X AS DOUBLE, Y AS DOUBLE
DIM CarX AS DOUBLE, CarY AS DOUBLE
    CarX = 5: CarY = 150

SUB DXTimerExpired
'  TheScreen.Fill(0)    ' You'd normally want to do this, but since we're also
                     ' updating the background, this is not necessary.
  DXImageList.Draw(0, X, 0,    0)
                  '|     |- Y  |- Mask
                  '|- Image Index
  DXImageList.Draw(1, CarX, CarY, 0)
  TheScreen.Circle(260, 5, 315, 60, &H30FFFF, &H30FFFF)
  TheScreen.Font = Font
  TheScreen.TextOut(10,10,"FPS: "+STR$(DXTimer.FrameRate), &HFFFFFF, -1)
  X = X - 1
  IF X = -320 THEN   ' Reset position
    X = 0
  END IF
  TheScreen.Flip        ' Always remember to call this, or else nothing will be shown
END SUB

SUB KeyDown(Key AS BYTE, Shift AS INTEGER)
  SELECT CASE Key
    CASE 40  ' Down
      CarY = CarY + 1
    CASE 39  ' Right
      CarX = CarX + 1
    CASE 38  ' Up
      CarY = CarY - 1
    CASE 37  ' Left
      CarX = CarX - 1
    CASE 27  ' ESC
      Form.Close 
  END SELECT
END SUB

'' Remember, you can't do any drawing if the form is not visible

DXImageList.Parent = TheScreen
DXImageList.LoadFromFile("SCENE.DXG")

DXTimer.Enabled = True
DXTimer.Interval = 0               '' Let DirectX handle FPS
DXTimer.OnTimer = DXTimerExpired


Form.OnKeyDown = KeyDown
Form.BorderStyle = bsDialog        '' Nevermind resizing
Form.Caption = "DirectX for Rapid-Q!"
Form.ShowModal
