[SOLVED] My Visual basics program isn't running properly, Why?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My Visual basics program isn't running properly, Why?
It's a form project pretty easy to test it. You can comment out the lines In DoGraphics and comment out the other ones and it works fine. One note, on my computer i'm running Visual Basics 2010 and the project program runs in the backround and I can't end the process I have to close Visual Basics, I think it's because of DrawGraphics().
It's just two files. I'll post the source code for the main file and some instructions on helping.
The first file Zelda Build.vb has a Form I Named ZeldaBuild that is 750 X 550 and Has the Text Zelda Build.
The Second file is called GFX.vb named pbGFX I made the text GFX atm but that's not to important. Anyways just make sure to add a picture box and size the window and the picture box to 640 X 480 Then you can sample it, I used a tileset bmp 640 X 480.
There's no code for GFX I'm just using it for the image at the moment but there will be. Ok here's the code for Zelda Build.vb
this is where the problem is.
I would be much oblidged if someone would shine some light on this subject.
filename: Zelda Build.vb
Code:
Imports System.Drawing
Public Class ZeldaBuild
' Grid Integers
Dim ResWidth As Integer = 750
Dim ResHeight As Integer = 550
Dim TileSize As Integer = 32
' Graphics Variables
Dim G As Graphics
Dim G2 As Graphics
Dim BBG As Graphics
Dim BB As Bitmap
Dim bmpTile As Bitmap
Dim sRect As Rectangle
Dim dRect As Rectangle
' FPS Counter
Dim tSec As Integer = TimeOfDay.Second
Dim tTicks As Integer = 0
Dim MaxTicks As Integer = 0
' Map Variables
Dim Map(100, 100, 10) As Integer
Dim MapX As Integer = 20
Dim MapY As Integer = 20
' Mouse integers
Dim mouseX As Integer
Dim mouseY As Integer
Dim mMapX As Integer
Dim mMapY As Integer
Dim PaintBrush As Integer = 0
' Game Running?
Dim IsRunning As Boolean = True
Private Sub ZeldaBuild_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Me.Focus()
'Initialize Graphics Objects
G = Me.CreateGraphics
BB = New Bitmap(ResWidth, ResHeight)
bmpTile = New Bitmap(GFX.pbGFX.Image)
StartGameLoop()
End Sub
Private Sub StartGameLoop()
Do While IsRunning = True
' Keep Application Responsive
Application.DoEvents()
'1.) Check User Input
'2.) Run AI
'3.) Update Object Data (Object Position, Status, etc.)
'4.) Check Triggers And Conditions
'TileSize.) Draw Graphics
DrawGraphics()
'6.) Play Sound Effects & Music
'7.) Update Tick Counter
TickCounter()
Loop
End Sub
Private Sub DrawGraphics()
' Fill The Backbuffer
' Draw Tiles
For x = 0 To 19
For y = 0 To 14
'sRect = New Rectangle(x * TileSize, y * TileSize, TileSize, TileSize)
'Select Case Map(MapX + x, MapY + y, 0)
' Case 0
' G.FillRectangle(Brushes.White, sRect)
' Case 1 ' Red
' G.FillRectangle(Brushes.Red, sRect)
' Case 2 ' Blue
' G.FillRectangle(Brushes.Blue, sRect)
'End Select
'G.DrawRectangle(Pens.Black, sRect)
GetSourceRect(MapX + x, MapY + y, TileSize, TileSize)
dRect = New Rectangle(x * TileSize, y * TileSize, TileSize, TileSize)
G.DrawImage(bmpTile, dRect, sRect, GraphicsUnit.Pixel)
Next
Next
' Highlight mouse sqaure
G.FillRectangle(Brushes.Red, 21 * TileSize, 4 * TileSize, TileSize, TileSize)
G.FillRectangle(Brushes.Blue, 21 * TileSize, 6 * TileSize, TileSize, TileSize)
G.DrawRectangle(Pens.Black, 21 * TileSize, 8 * TileSize, TileSize, TileSize)
G.DrawRectangle(Pens.Red, mouseX * TileSize, mouseY * TileSize, TileSize, TileSize)
' Draw Final Layers
' Guys, Menus, ETC.
' Draw TIcks And Ticks Per Second
G.DrawString("Ticks: " & tTicks & vbCrLf & _
"TPS: " & MaxTicks & vbCrLf & _
"Mouse X pos: " & mouseX & vbCrLf & _
"Mouse Y pos: " & mouseY & vbCrLf & _
"M Mouse X: " & mMapX & vbCrLf & _
"M Mouse Y: " & mMapY & vbCrLf & _
"", Me.Font, Brushes.Black, 19 * TileSize + TileSize, 0)
G = Graphics.FromImage(BB)
' Draw Backbuffer To Screen
BBG = Me.CreateGraphics
' Copy Backbuffer To Graphics Object
BBG.DrawImage(BB, 0, 0, ResWidth, ResHeight)
' Fix OverDraw
G.Clear(Color.White)
End Sub
Private Sub TickCounter()
If tSec = TimeOfDay.Second And IsRunning = True Then
tTicks = tTicks + 1
Else
MaxTicks = tTicks
tTicks = 0
tSec = TimeOfDay.Second
End If
End Sub
Private Sub ZeldaBuild_MouseClick() Handles Me.MouseClick
If mouseX = 21 And mouseY = 8 Then
PaintBrush = 0
ElseIf mouseX = 21 And mouseY = 4 Then
PaintBrush = 1
ElseIf mouseX = 21 And mouseY = 6 Then
PaintBrush = 2
End If
Select Case PaintBrush
Case 0
Map(mMapX, mMapY, 0) = 0
Case 1 ' Red
Map(mMapX, mMapY, 0) = 1
Case 2 ' Blue
Map(mMapX, mMapY, 0) = 2
End Select
End Sub
Private Sub ZeldaBuild_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
mouseX = Math.Floor(e.X / TileSize)
mouseY = Math.Floor(e.Y / TileSize)
mMapX = MapX + mouseX
mMapY = MapY + mouseY
End Sub
Private Sub GetSourceRect(ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer)
Select Case Map(x, y, 0)
Case 0 ' Grass
sRect = New Rectangle(32, 0, TileSize, TileSize)
Case 1 ' Tree
sRect = New Rectangle(32, 128, TileSize, TileSize)
Case 2 ' Mountain
sRect = New Rectangle(160, 128, TileSize, TileSize)
End Select
End Sub
End Class
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.