Tutorial [Snake using Picture boxes] NMs Game tutorial 0.4
This is a tutorial on how to make a basic snake game. There is plenty of ways to complete such a task. I have chosen to start off with probably one of the simplest ways I can imagine, so if you are new to games programming in VB, this is a great tutorial for you. So I think we should just jump in to it. I am using VB6 in this example. But VB 5 should do fine too. To make this game you should know a little bit about VB from before. I am using simple collision detection, and key presses, and a module. If you don't know at all how to use this from before you should try to read about it before starting. I will try to make some tutorials on the subject soon but for now this is all I got.
Setting form properties:
When making games it is always easier to handle the coordinates of the screen in pixels than twips (twips is the default one). So start by changing the ScaleMode property of the form to Pixels. And if you don't know it from before, it is nice to know that in VB the coordinates of your form is (0,0) in the upper left corner. It is not easy to think this way of the coordinate system at once, but you will get used to it.
Re: Tutorial [Snake using Picture boxes] NMs Game tutorial 0.4
Wow. Looks like I stumbled upon the most useful of ancient threads. Hopefully this will get a reply. Thanks for the tutorial, all the given code works great. I was wondering if anyone could tell me how I could generate some walls around the edge of the form as boundaries for the snake. Here's the code I have so far:
Code:
Option Explicit
Dim Wall(176) As Wallpart 'Wallpart is user-defined type with properties X and Y
Private Sub Form_Load()
'Generate Walls
For ib = 1 To 51 'Generate walls at the top
Load imgWall(ib)
Wall(ib).X = (8 + (ib * 10))
Wall(ib).Y = 8
Next
For ib = 52 To 104 'Generate walls at the bottom
Load imgWall(ib)
Wall(ib).X = (8 + (ib * 10))
Wall(ib).Y = 312
Next
For ib = 105 To 140 'Generate walls at the left
Load imgWall(ib)
Wall(ib).X = 8
Wall(ib).Y = (16 + (ib * 10))
Next
For ib = 141 To 17 'Generate walls at the right
Load imgWall(ib)
Wall(ib).X = 424
Wall(ib).Y = (16 + (ib * 10))
Next
imgWall(ib).Left = Wall(ib).X
imgWall(ib).Top = Wall(ib).Y
End Sub
imgWall(0) is already loaded in the form at position Left = 8, Top = 8, and I want the border to be a 52x38 rectangle made of individual boxes 10x10 pixels in size.
When I try to run the program, the error given is "Control array element "141" doesn't exist", and the line "imgWall(ib).Left = Wall(ib).X" is highlighted.
What am I doing wrong?
Also, I believe creating these borders changes the code for the PlaceFood sub since the food has to be placed within the walls, and I'm not sure how to do that either.
Re: Tutorial [Snake using Picture boxes] NMs Game tutorial 0.4
Hehe, yeah. It brings back good old memories this thread. Been a long time since I did any VB though, and a long time since I have been on this side of the Internet :).
But about your problem. I guess it is only a small typo from your side. It actually took me a few seconds to see what is wrong as I haven't had VB installed for years. I guess if I did, it would be easy to see that the wall blocks it complain about is never created because you have an ill-defined for loop.
You have:
Code:
For ib = 141 To 17 'Generate walls at the right
But I am sure you did not mean 17!
- ØØ -