VB.NET - Snake? Game - Development
I am currently in the process of making a snake game using VB.NET... I was just wanting to gather ideas on how to do the body of the snake...
Currently I have a class called SnakeBody which contains the following code:
Public Class SnakeBody
Dim yCoord As Integer
Dim xCoord As Integer
Dim body As PictureBox
End Class
I guess what I am asking is if Dim body As PictureBox
a logical thing to put in my class. As in, I am not sure if that is the correct thing to do? To create the actual body of the snake I will have an array of these SnakeBody objects.
If `'Dim body As PictureBox is valid How do I reproduce the same picturebox everytime my snake e开发者_C百科ats something?
I hop this makes sense... Thanks Alot
Well, it is okay but it is not going to work well in practice. PictureBox is a window, when snakes overlap each other, you'll obscure part of them with a rectangle. You'll essentially see one snake in a rectangle with bits of other snakes peeking out past that rectangle.
Use the form's Paint event to draw the snakes, don't use a control.
Don't use Winforms. Use vb.net and silverlight, you can design a template for the snake , you have silverlights sophisticated built in animation. It will be so much easier and better and it will run on a PC and Mac.
actually i don't know how to add a cube when the snake eat something
try to use System.drawing.graphics to draw cubes ( parts of the snake ) : it's a bit easier
if you want to make the snake moving you should make a script based on this :
REMEMBER : THIS IS ONLY A DIMOSTRATION OF WHAT HAVE THE CODE TO DO :
Dim CubeSelected as integer = 1 ' Selected cube
loop {
if right_key_pressed{
' You have to make this command : cube(number of the cube , direction)
cube(CubeSelected,right) ' Change the selected cube direction
MoveSelect = MoveSelect + 1 ' Select the next cube
Threading.Thread.Sleep(500) ' Wait
}
}
if you press the right key , the cubes will change the direction one for time . So the snake will make a curve and proceed to the right direction
it's a little more complicated actually , but i hope it helps
精彩评论