Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev)
Where to start!? (Game Dev) Where to start!? (Game Dev)
Where to start!? (Game Dev)
Go Back  Xtreme Visual Basic Talk > > > Where to start!? (Game Dev)


Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2006, 02:20 AM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Cool Where to start!? (Game Dev)


I have done a simple bitblt game before in VB6.0 but now I want to do something (starting from scratch) with VB .net. I need to know where to start and where to find tutorials.
What is the simplest way to write a game? is bitblt the simplest way? How about most popular way?
For the first game I want to something like the simple asteroids game. Where should I start?

EDIT:
I need to know how to write my game loop.
I did something like:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load While exit = 0 paintBall System.Windows.Forms.Application.DoEvents() end while End Sub
How do I write the paintBall function? I just want to draw something (anything!) on the form.
Thanx.
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum

Last edited by Pooyae; 05-02-2006 at 03:33 AM.
Reply With Quote
  #2  
Old 05-03-2006, 03:56 PM
Iceplug's Avatar
IceplugWhere to start!? (Game Dev) Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

I think this method will give you the most power and control while drawing (may not be very graceful with two graphics objects).

GDI+ Backbuffers in VB.NET - Projectile Demo
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 05-04-2006, 04:14 AM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

Ok...
Here is what I have until now:

Code:
Imports System Imports System.Drawing Imports Microsoft.VisualBasic.Devices.Keyboard Public Class Form1 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) 'This is the declare of the Graphics object Dim g As Graphics = e.Graphics 'Declare the pen Dim pPen As Pen = New Pen(Color.Maroon, 4) 'counter Dim i As Double For i = 0 To 100 'Let's draw us a line g.DrawLine(pPen, 10, 10, 110, 110) System.Windows.Forms.Application.DoEvents() Next End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim EndGame As Boolean = False Do Until EndGame Application.DoEvents() Loop End Sub End Class

Is everything correct and how it should be?
Also, How do I scan for keypresses? I tried the KeyPress(...) but I didn't work .
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum

Last edited by Pooyae; 05-04-2006 at 05:52 AM.
Reply With Quote
  #4  
Old 05-04-2006, 02:58 PM
Iceplug's Avatar
IceplugWhere to start!? (Game Dev) Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Scan for key presses? Typically, I handle the Keydown and Keyup event to see if a key is pressed and use booleans (set in those events) to determine if a key is pressed.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 05-06-2006, 12:37 AM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

This gives me a null reference exception on eg.keycode...

How can I initialize it?

Also, is this the right way to scan for the escape key? (in the form1_load and inside the game loop?)

Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim EndGame As Boolean = False Dim eg As System.Windows.Forms.KeyEventArgs Do Until EndGame If (eg.KeyCode = Keys.Escape) Then EndGame = True End If 'Application.DoEvents() Loop End Sub
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum
Reply With Quote
  #6  
Old 05-06-2006, 05:17 AM
Iceplug's Avatar
IceplugWhere to start!? (Game Dev) Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Quote:
This gives me a null reference exception on eg.keycode...
Because you need to handle the KeyDown and KeyUp event.
Quote:
Also, is this the right way to scan for the escape key? (in the form1_load and inside the game loop?)
No...
You must have a KeyDown and KeyUp event in order to handle the KeyDown and KeyUp event. Do you know how to add those to your form?
What you would do is handle the KeyDown event (select from comboboxes at the top) and the KeyUp event, declare a bunch of booleans (corresponding to keys), set the appropriate boolean to True in the KeyDown and to False in the KeyUp.
In the game loop, you check the condition of the booleans to determine if a key is pressed.

You could use GetKeyState if you really wanted to, but remember to convert the Longs into Integers, and I like the above method better.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #7  
Old 05-06-2006, 06:09 AM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

like this?
Code:
Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Dim isESCdown As Boolean If e.KeyCode = Keys.Escape Then isESCdown = True End If End Sub

but then how can I call isESCdown from my game loop to see if it is pressed or not?

should i make the isESCdown global?
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum
Reply With Quote
  #8  
Old 05-06-2006, 07:32 AM
elnerdo's Avatar
elnerdo elnerdo is offline
Contributor
 
Join Date: Jul 2004
Location: Northern New Jersey
Posts: 490
Default

Yes, you could make siescapedown global, also make sure to set isescapedown to false in the keyup sub.
__________________
nerds unite!
Reply With Quote
  #9  
Old 05-06-2006, 09:05 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

Quote:
Originally Posted by Pooyae
should i make the isESCdown global?
It would be better to have a single global object (a singleton) that maintains all key states. The event handlers for keyup and down would simply keep this singleton up-to-date.

Benefits:

The code that uses the key state information is oblivious to both the method of collection and the storage of that information.

The code that stores the information is oblivious to the methods of both collection and the usage of the information.

The code that collects the key state information is oblivious to both the method of storage and the use of that information.


To bring it all together, this object can maintain ALL forms of user input. Keyboard, Mouse, voice recognition and so on..

It would also not be hard to update the collection method later to use DirectInput (for example) without breaking the storage or usage methodology.
Reply With Quote
  #10  
Old 05-06-2006, 09:10 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

One other thing, it then becomes a breeze to impliment user-defined keyboard controls. The input manager class performs the conversion from raw key state information (ESC, ENTER, SPACE, W, A, S, D, etc..) to more generalized (CANCEL, ACCEPT, JUMP, FORWARD, STRAFELEFT, BACKWARD, STRAFERIGHT, etc..)
Reply With Quote
  #11  
Old 05-07-2006, 05:32 PM
Iceplug's Avatar
IceplugWhere to start!? (Game Dev) Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Better than making it global, declare it in your Declarations section (at the top before your subroutines). This is how you can check and set it from and between the KeyDown, KeyUp, and Timer events.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #12  
Old 05-07-2006, 10:39 PM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

Ok... here is what I have until now:
Code:
Imports System Imports System.Drawing Public Class Form1 Dim isESCdown As Boolean Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) Dim GFX As Graphics = e.Graphics Dim pPen As Pen = New Pen(Color.Maroon, 4) Dim i As Double For i = 0 To 100 GFX.DrawLine(pPen, 10, 10, 110, 110) System.Windows.Forms.Application.DoEvents() Next End Sub Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.Escape Then isESCdown = True End If End Sub Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp If e.KeyCode = Keys.Escape Then isESCdown = False End If End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim EndGame As Boolean EndGame = isESCdown Do Until EndGame Me.Show() Application.DoEvents() Loop Me.Close() End Sub End Class

First problem: The form does not show!
Solution: I put the Me.Show() in the game loop
Results: Form is shown, but when closed it gives me this exception which cannot be catched: System.ObjectDisposedException

Second problem: When ESC is pressed nothing happens!
Solution: I DON'T KNOW!

Any ideas?!
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum
Reply With Quote
  #13  
Old 05-07-2006, 10:59 PM
reboot's Avatar
rebootWhere to start!? (Game Dev) reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

I don't know where to start. Why would you have your gameloop in FormLoad? Why would you reshow your form over and over in your loop? What do you expect to happen when you show your form over and over in FormLoad? Why would you set your variable True in KeyDown and immediately False again in KeyUp? Not that it matters since you're setting the variable isESCdown and your loop is looking for the variable EndGame.... wow....
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #14  
Old 05-07-2006, 11:40 PM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

Quote:
Originally Posted by reboot
I don't know where to start. Why would you have your gameloop in FormLoad?
Didn't know where else to put it! Where do you suggest I put it?

Quote:
Originally Posted by reboot
Why would you reshow your form over and over in your loop?
A mistake really! It was supposed to be outside the game loop!

Quote:
Originally Posted by reboot
What do you expect to happen when you show your form over and over in FormLoad?
Again, a mistake!

Quote:
Originally Posted by reboot
Why would you set your variable True in KeyDown and immediately False again in KeyUp?
Why not?! I only want to say quit once and only when the ESC is down. I would appreciate your suggestion.

Quote:
Originally Posted by reboot
Not that it matters since you're setting the variable isESCdown and your loop is looking for the variable EndGame.... wow....
I have this in my code:
Code:
EndGame = isESCdown
Why doesn't this get executed?
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum

Last edited by Pooyae; 05-07-2006 at 11:50 PM.
Reply With Quote
  #15  
Old 05-08-2006, 05:38 AM
elnerdo's Avatar
elnerdo elnerdo is offline
Contributor
 
Join Date: Jul 2004
Location: Northern New Jersey
Posts: 490
Default

It does get executed.. Once.

Try putting it in your gameloop to fix that problem ( Basically switch the locations of 'endgame = isescdown' and me.show )

Now, make a new sub and put your gameloop in it. It will make everything a little better. (Be sure to declare endgame in the declarations section, if you do)

Also, what reboot was getting at when he was asking why you have isescdown in the keyup AND keydown, it's because if the program ENDS once you press escape, what's the point of doing anything else with escape?
__________________
nerds unite!
Reply With Quote
  #16  
Old 05-08-2006, 07:20 AM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

Ok, I think I progressed a bit:
Code:
Option Explicit On Imports System Imports System.Drawing Public Class Form1 Dim isESCdown As Boolean Dim isLeftArrowDown As Boolean Dim isRightArrowDown As Boolean Dim isDownArrowDown As Boolean Dim isUpArrowDown As Boolean Dim GFX As System.Drawing.Graphics Dim pPen As Pen = New Pen(Color.Maroon, 4) Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.Escape Then isESCdown = True End If If e.KeyCode = Keys.Left Then isLeftArrowDown = True End If If e.KeyCode = Keys.Right Then isRightArrowDown = True End If If e.KeyCode = Keys.Up Then isUpArrowDown = True End If If e.KeyCode = Keys.Down Then isDownArrowDown = True End If End Sub Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp If e.KeyCode = Keys.Escape Then isESCdown = False ElseIf e.KeyCode = Keys.Left Then isLeftArrowDown = False ElseIf e.KeyCode = Keys.Right Then isRightArrowDown = False ElseIf e.KeyCode = Keys.Up Then isUpArrowDown = False ElseIf e.KeyCode = Keys.Down Then isDownArrowDown = False End If End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Show() Me.Focus() GFX = Me.CreateGraphics Do Until isESCdown GFX.DrawLine(pPen, 10, 10, 20, 10) 'Checks for key strokes and does approperiate action KeyStrokeActions() 'detects collisions inside the program CollisionDetection() Application.DoEvents() Loop Me.Close() End Sub Private Sub KeyStrokeActions() If isLeftArrowDown = True Then Label1.Text = "<<" If Label1.Left > 0 Then Label1.Left = Label1.Left - 1 End If End If If isRightArrowDown = True Then Label1.Text = ">>" If Label1.Left < Me.Width - Label1.Width - 10 Then Label1.Left = Label1.Left + 1 End If End If If isUpArrowDown = True Then Label1.Text = "^^" If Label1.Top > 0 Then Label1.Top = Label1.Top - 1 End If End If If isDownArrowDown = True Then Label1.Text = "vv" If Label1.Top < Me.Height - (Label1.Height * 4) Then Label1.Top = Label1.Top + 1 End If End If End Sub Private Sub CollisionDetection() If Label1.Top < 20 Then Label2.Text = "You hit 20!!!" Else Label2.Text = "" End If End Sub End Class

Any ideas of how I can make it more efficient?
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum
Reply With Quote
  #17  
Old 05-08-2006, 03:10 PM
blastoboy1000's Avatar
blastoboy1000 blastoboy1000 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 220
Default

Instead of using all of those If...Then statements, you could have a Select Case statement replacing it, i.e.:

instead of:
Code:
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp If e.KeyCode = Keys.Escape Then isESCdown = False ElseIf e.KeyCode = Keys.Left Then isLeftArrowDown = False ElseIf e.KeyCode = Keys.Right Then isRightArrowDown = False ElseIf e.KeyCode = Keys.Up Then isUpArrowDown = False ElseIf e.KeyCode = Keys.Down Then isDownArrowDown = False End If End Sub

you could have:
Code:
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp Select Case e.KeyCode Case Keys.Escape isESCdown = False Case Keys.Left isLeftArrowDown = False Case Keys.Right isRightArrowDown = False Case Keys.Up isUpArrowDown = False Case Keys.Down isDownArrowDown = False End Select End Sub

Last edited by blastoboy1000; 05-08-2006 at 03:10 PM. Reason: forgot closing [vb] tag
Reply With Quote
  #18  
Old 05-09-2006, 12:45 AM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

Ok, So I figured out how to move a label around the form with the arrows. (Thanks for all the help :-) )

Next step is to move a GDI+ rectangle around the page.

So I changed the code to draw a rectangle and used the same methods to moving them.

Problem: The rectangle does not "move" but rather it is "extended", for example if you press the up arrow the rectangle is extended from the top. (I think it is redrawn over and over)

How can I actually move the rectangle around the page?

here is my code:

Code:
Option Explicit On Imports System Imports System.Drawing Public Class Form1 Dim isESCdown As Boolean Dim isLeftArrowDown As Boolean Dim isRightArrowDown As Boolean Dim isDownArrowDown As Boolean Dim isUpArrowDown As Boolean Dim GFX As System.Drawing.Graphics Dim pPen As Pen = New Pen(Color.Maroon, 4) 'rectangle coordinates Dim rectX1 = 50 Dim rectY1 = 50 Dim rectX2 = 70 Dim rectY2 = 50 Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 'set keysdown to true Select Case e.KeyCode Case Keys.Escape isESCdown = True Case Keys.Left isLeftArrowDown = True Case Keys.Right isRightArrowDown = True Case Keys.Up isUpArrowDown = True Case Keys.Down isDownArrowDown = True End Select End Sub Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp 'sets keysdown to false Select Case e.KeyCode Case Keys.Escape isESCdown = False Case Keys.Left isLeftArrowDown = False Case Keys.Right isRightArrowDown = False Case Keys.Up isUpArrowDown = False Case Keys.Down isDownArrowDown = False End Select End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Show() Me.Focus() GFX = Me.CreateGraphics Do Until isESCdown 'create graphics here ............................................................. GFX.DrawLine(pPen, rectX1, rectY1, rectX2, rectY2) '.................................................................................. 'Checks for key strokes and does approperiate action KeyStrokeActions() 'do events - makes the stupid windows not hang up! Application.DoEvents() Loop Me.Close() End Sub Private Sub KeyStrokeActions() If isLeftArrowDown = True Then Label1.Text = "<<" rectX1 = rectX1 - 1 rectX2 = rectX2 - 1 End If If isRightArrowDown = True Then Label1.Text = ">>" rectX1 = rectX1 + 1 rectX2 = rectX2 + 1 End If If isUpArrowDown = True Then Label1.Text = "^^" rectY1 = rectY1 - 1 rectY2 = rectY2 - 1 End If If isDownArrowDown = True Then Label1.Text = "vv" rectY1 = rectY1 + 1 End If End Sub End Class
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum
Reply With Quote
  #19  
Old 05-09-2006, 01:05 AM
Pooyae's Avatar
Pooyae Pooyae is offline
Junior Contributor
 
Join Date: Nov 2003
Location: Birmingham, AL
Posts: 206
Default

I tried putting
Code:
Me.Refresh
in the game loop but the rectangle becomes overly flickery when moved.
__________________
"Imagination is more important than knowledge." -Albert Einstein
Survived Hero! - Electrical & Computer Engineering Forum
Reply With Quote
  #20  
Old 05-09-2006, 01:44 PM
JNewt's Avatar
JNewt JNewt is offline
Centurion
 
Join Date: Apr 2003
Location: KY (Home), ID (College)
Posts: 138
Default

You need to clear the Graphics object before you paint new stuff. Use
Code:
GFX.Clear
before you draw the rectangle.
__________________
Erat autem fuenum multum in loco. -John 6:10
Please forgive my English -I'm a modern American.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev) Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev) Where to start!? (Game Dev)
Where to start!? (Game Dev)
Where to start!? (Game Dev)
 
Where to start!? (Game Dev)
Where to start!? (Game Dev)
 
-->