Tron or snake game
Tron or snake game
Tron or snake game
Tron or snake game
Tron or snake game
Tron or snake game Tron or snake game Tron or snake game Tron or snake game Tron or snake game Tron or snake game Tron or snake game Tron or snake game
Tron or snake game Tron or snake game
Tron or snake game
Go Back  Xtreme Visual Basic Talk > > > Tron or snake game


Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2007, 03:42 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default Tron or snake game


Hi Everyone,

I'm quite beginner in VB2005, but I would like to make a Tron or Snake game.
I think I have some knowledge about VB.

My problem is to catch the keystrokes to control the snake line.
I have just one form: Form1, and keypreview is enabled.
I don't want a keypress, or keydown control.

While my program drawing the bitmaps onto the form (While - End while loop), I just want to know what key was pressed, to control the line drawing.

I can handle form1_keypress event, but not during the line drawing.
So, now I have a line, which go trough the screen, while I push the keys, and after drawing end, I have a message box: you push a button.

I would to see this message box during drawing.

Could anybody help me?
Reply With Quote
  #2  
Old 02-23-2007, 02:34 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

KeyPress doesn't work right for the directions keys though...you'll need to use KeyDown and override controls.

Also, in the KeyDown event, just declare a Direction variable as Integer and make Up = 1, Down = 2, etc.

Then in the timer tick event, do a Select Case Direction, and move the line/picture/etc. accordingly.
Reply With Quote
  #3  
Old 02-24-2007, 10:25 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Thank you very much! If it will be perfect, I will upload somewhere.

Perhaps I will be some more questions.
Reply With Quote
  #4  
Old 02-26-2007, 04:02 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Hello again,

Is there any idea, for collision detection?
Can I somehow check the color of the next bitmap?
Or I have to collect every line's coordinates, in arrays, and check this?

I can make the second, but the I think the first would be better, and simplier.

Could anybody help me?
Reply With Quote
  #5  
Old 02-26-2007, 10:37 AM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

You could do either, but I've always used the 2nd method.
Reply With Quote
  #6  
Old 03-04-2007, 11:47 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Two new question:

My explosion effect draw a growing circle, to the last line coordinates. How could I clear the screen inside the circle? And the harder question is, how can I clear the saved line coordinates from the line coordinates array?

For example, I go to myself, and I draw a circle. Inside this I want to clear the screen (one part of my line, too). And I want to clear this cleared area's coordinates, for other players don't collision with the invisible line.
Reply With Quote
  #7  
Old 03-05-2007, 01:58 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Update: I could clear the screen inside the circle (but just the screen, not the saved line coordinates).

Can anybody ask, my second question?
Reply With Quote
  #8  
Old 03-09-2007, 10:47 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

draw the collision to a picturebox instead of to me (the form)
Reply With Quote
  #9  
Old 03-10-2007, 01:41 PM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Could you specify this? I never use picture box.
By the way, I can solve my problem (coordinates clear inside the explosion), with simple mathematic procedures. Unfortunately it is quite difficult.
If you know a simpler method with this picture box, please send me come code.
Reply With Quote
  #10  
Old 03-10-2007, 07:04 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

well...like i said, instead of drawing to the form (aka me), just replace me with the picturebox and locate that picturebox to the area.

example: dim g as graphics = picturebox1.creategraphics

then just draw to g.
Reply With Quote
  #11  
Old 03-11-2007, 12:32 PM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Sorry, I don't understand, why better to draw to a picturebox, instead of Me?
What will be simpler with picturebox drawing?
Reply With Quote
  #12  
Old 03-11-2007, 01:13 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

It's simple because you can create and remove the picturebox from a tiny area on the screen without all the math you said you didn't want to use to clear it from the form. You can do either, but just trying to offer you an easier alternative.
Reply With Quote
  #13  
Old 03-13-2007, 04:20 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Question

Hello Targe,

I upload my program to rapidshare. Please check this, and teach me, how can I change this source code to picturebox, instead of Me?

http://rapidshare.com/files/20801503/Lalitron.rar

I think I have to use the bitmap color checking method, instead of coordinates collecting in arrays (because it is too slow - but works perfect). I don't know how can I check the color of one bitmap?

Thank you very much!

Last edited by martonx; 03-13-2007 at 04:28 AM.
Reply With Quote
  #14  
Old 03-13-2007, 02:15 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

First off, the game play is extremely slow, you'll need to make it faster. I tried setting the timer to be quicker but it's still extremely slow. You'll need to just make the line move more each timer tick.

And like I've said twice already...the code you want to change is this:

rajzlap = Me.CreateGraphics()

Instead of Me, make it a PictureBox.

Dim PicBox As New PictureBox
With PicBox
.Height = ?
.Width = ?
.Location = ?
End With
Me.Controls.Add(PicBox)

Then:

rajzlap = PicBox.CreateGraphics()


But since I'm really unsure what you're trying to accomplish, maybe you could stick to the form vs. a picturebox. Just remember, you'll need to redraw whatever you drew over if you want it to be there after the explosion. With a picturebox, you'll need to do the same thing...so maybe you wouldn't want to use it. Again...it's really hard to tell what you're trying to do so I'm sorry I couldn't help more.

Also, a good way to check arrays is to just use a 2D boolean style array. Apparently Integers are the quickest things in VB so I've been using a 2D Integer array. The array uses X and Y coordinates and sets the value to 1, since the initial value is 0. If a coordinate ever comes up that's a 1, you know there's been a collision. It's extremely quick for me, you may want to try it. Your code uses multiple variables to check collisions when you all you really need is that. Also, using ReDim is efficient but it could be slowing your program down, not sure. I changed some things but the program is still slow.

I'm currently working on a Tron game as well but mine isn't fully working. When it is I'd be happy to upload it to you and give you some ideas.
Reply With Quote
  #15  
Old 03-14-2007, 04:04 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Thank you again,

I'm excited.
Reply With Quote
  #16  
Old 03-14-2007, 11:59 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

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

Just a note:

A picture box is not a game rendering surface and is meant only to hold/contain a visible picture with a friendly "fire and forget" methodology.

I would draw directly into a bitmap (or at least generate a bitmap from what I was really drawing on) and then directly render that to the form on demand. Keep in mind that GDI+ isnt really a speed demon (its NOT hardware accelerated)
Reply With Quote
  #17  
Old 03-15-2007, 04:30 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

Everybody,

Yesterday night I rewrite my tron code. I think it is much better then previous version.
Targe's idea about 2D boolean array was perfect.

Please check this code.

http://rapidshare.com/files/21129419/Lalitron.rar

This is the new version, the older version was deleted from rapidshare.
Reply With Quote
  #18  
Old 03-15-2007, 12:50 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

It's quicker but the arrow keys don't work right for movement.
Reply With Quote
  #19  
Old 03-16-2007, 09:46 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Martonx, maybe you could help me with somethin...I need a good cycle engine sound that can be looped. If ya got one send it my way Otherwise I'll keep looking. Btw, almost done with my version and will try to upload it soon to you.
Reply With Quote
  #20  
Old 03-18-2007, 10:53 AM
martonx martonx is offline
Centurion
 
Join Date: Jan 2007
Location: Szeged, Hungary
Posts: 129
Default

I'm sorry, but I don't know what is "cycle engine sound". Maybe, I would need one, too?
My tron version will be finish soon, but without sounds.
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
Tron or snake game
Tron or snake game
Tron or snake game Tron or snake game
Tron or snake game
Tron or snake game
Tron or snake game Tron or snake game Tron or snake game Tron or snake game Tron or snake game Tron or snake game Tron or snake game
Tron or snake game
Tron or snake game
 
Tron or snake game
Tron or snake game
 
-->