Option Explicit On
Option Strict On
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports Sunlight.DirectX.Graphics
Imports Sunlight.DirectX.Input
Imports Sunlight.DirectX.SoundMusic
Namespace DXTest
Public Class Form1
Inherits Sunlight.IdleForm
Private d3d As Direct3D = New Direct3D()
Private device As device
Protected WithEvents di As DirectInput = New DirectInput()
Protected manager As SpriteManager = New SpriteManager()
Protected dm As DirectMusic = New DirectMusic()
Private texBackground As Texture = New Texture()
Private texSprites As Texture = New Texture()
Private spriteBackground As Sprite
Private spriteFixed As Sprite
Private spriteMoving As Sprite
Private spritePlayer As Sprite
Private WithEvents soundMusic As BackgroundSound = New BackgroundSound()
Private xAutomaticSprite As Integer = 0
Private xPlayer As Integer = 0
Private bLeft As Boolean
Private bRight As Boolean
Private bQuit As Boolean
Private bPaused As Boolean
Private bShowHelp As Boolean
Private bModeSwitch As Boolean
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If Disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
Private components As System.ComponentModel.Container
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(640, 480)
Me.MaximizeBox = False
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Protected Sub OnInit(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Init
device = New Device(d3d)
device.ParentWindow = Me
device.Windowed = True
di.ActionMapName = "DXTest"
di.AppID = New Guid("{CA761232-ED42-11CE-BACD-00AA0057B223}")
di.Genre = Genres.ARCADE_SIDE2SIDE
di.Actions.Add(New ActionMap.Entry(0, Actions.AXIS_ARCADES_LATERAL, "Left/Right"))
di.Actions.Add(New ActionMap.Entry(1, Actions.KEYBOARD_LEFT, "Left"))
di.Actions.Add(New ActionMap.Entry(2, Actions.KEYBOARD_RIGHT, "Right"))
di.Actions.Add(New ActionMap.Entry(3, Actions.KEYBOARD_ESCAPE, "Quit"))
di.Actions.Add(New ActionMap.Entry(4, Actions.KEYBOARD_P, "Pause"))
di.Actions.Add(New ActionMap.Entry(5, Actions.KEYBOARD_F1, "Help"))
di.Actions.Add(New ActionMap.Entry(6, Actions.KEYBOARD_S, "Full Screen On/Off"))
di.ParentWindow = Me
di.Direct3DDevice = device
dm.ParentWindow = Me
dm.Create()
soundMusic.DirectMusicObject = dm
soundMusic.Filename = "passport.mid"
manager.DeviceObject = device
texBackground.DeviceObject = device
texBackground.Filename = "a.png"
texSprites.DeviceObject = device
texSprites.Filename = "sprites.png"
spriteBackground = New Sprite(manager, New Rectangle(0, 0, 640, 480), texBackground, New Point(0, 0))
spriteFixed = New Sprite(manager, New Rectangle(288, 208, 64, 64), texSprites, New Point(128, 0))
spriteMoving = New Sprite(manager, New Rectangle(288, 100, 64, 64), texSprites, New Point(0, 0))
spritePlayer = New Sprite(manager, New Rectangle(288, 150, 64, 64), texSprites, New Point(64, 0))
device.Create()
soundMusic.Play()
End Sub
Private Sub OnMusicFinished(ByVal sender As Object, ByVal e As EventArgs) Handles soundMusic.Finished
soundMusic.Play()
End Sub
Protected Sub OnIdle(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Idle
di.Check()
If (bQuit) Then
Close()
Return
End If
If (bModeSwitch) Then
device.Windowed = Not device.Windowed
device.Reset()
bModeSwitch = False
End If
If (bShowHelp) Then
bShowHelp = False
di.Display()
End If
If (Not bPaused) Then
If (bLeft) Then xPlayer -= 1
If (bRight) Then xPlayer += 1
spritePlayer.Left = 288 + xPlayer
xAutomaticSprite += 1
If (xAutomaticSprite > 100) Then xAutomaticSprite = -100
spriteMoving.Left = 288 + xAutomaticSprite
End If
spriteBackground.Draw()
spriteFixed.Draw()
spriteMoving.Draw()
spritePlayer.Draw()
device.BeginScene()
manager.FinishDraw()
device.EndScene()
device.Flip()
End Sub
Sub OnInputAction(ByVal sender As DirectInput, ByVal e As DirectInputEventArgs) Handles di.Action
Select Case (e.ID)
Case 0
If (e.AxisPosition < -20) Then
bLeft = True
bRight = False
ElseIf (e.AxisPosition > 20) Then
bRight = True
bLeft = False
Else
bLeft = False
bRight = False
End If
Case 1
bLeft = e.ButtonPressed
Case 2
bRight = e.ButtonPressed
Case 3
If (e.ButtonPressed) Then bQuit = True
Case 4
If (e.ButtonPressed) Then bPaused = Not bPaused
Case 5
If (e.ButtonPressed) Then bShowHelp = True
Case 6
If (e.ButtonPressed) Then bModeSwitch = True
End Select
End Sub
End Class
End Namespace
Module DXTestModule
Sub Main()
Dim form As DXTest.Form1 = New DXTest.Form1()
form.Run()
End Sub
End Module