Click to See Complete Forum and Search --> : Nibbles!
Mag-Net
May 31st, 2000, 09:21 PM
Hey ppl,
does anyone remember that brilliant game called nibbles, it is on some mobile phones now calling itself snake.
well i want to write my own version in vb, but dont know how to make the worm move properly, what am i going to use as the sprite? and how can i tell the head from the tail and make him bend in the middle?
Please help me as i love that game!
Fox
May 31st, 2000, 10:27 PM
A friend wanted to make the same game and asked me the same thing... I however told him to make an array to store the points and draw them by simple PSet-ing. He made it and it became nearly the same as on mobile phones ;)
Type tCoord2D
x as Long
y as Long
End Type
Type tSnake
PointCount as Long
Point() as tCoord2D
Name as String
Score as Long
End Type
Global SnakeCount as Long
Global Snake() as tSnake
Got the idea? :)
Mag-Net
May 31st, 2000, 10:36 PM
yeah sorta, i have never done any of that coding with types and what you have said... creating my own objects, is that what it is?
how do i paint the snake then? That may be a completely strange question to you, if the code already does that, but as i said i havent ever done that before, thanks
kedaman
May 31st, 2000, 11:17 PM
A user defined type (UDT) is a bunch of standard data types you put together the way it suits your need. What fox have done is a set of UDT that simplifies the way you handle your snakes(s) so you can use the snakes like this:
Dim Magsnake as tsnake
magsnake.name="Mag-Net"
magsnake.score=magsnake.score+1
'To move your snake:
magsnake.point(0).x=magsnake.point(0).x+directionx
magsnake.point(0).y=magsnake.point(0).y+directiony
For n=0 to pointcount-2
magsnake.point(n)=magsnake.point(n+1)
next n
Fox
May 31st, 2000, 11:56 PM
Indeed.
Making your own object would mean to make a class. It is however easier to use an UDT for this simple game ;)
Mag-Net
Jun 1st, 2000, 04:43 AM
ok, so i followed that code and now i get a subscript out of range error with this line:
'To move your snake:
Magsnake.Point(0).x = Magsnake.Point(0).x + directionx
I dont have a clue why? any ideas?
thanks
Where did you put the code?
Fox
Jun 1st, 2000, 05:31 AM
You probably didnt initialize the Snake:
Dim MagSnake as tSnake
With MagSnake
'Set start values
.PointCount = 20
Redim .Point(.PointCount)
.Name = "Mag-Net"
.Score = magsnake.score+1
'To move your snake
.point(0).x = .point(0).x + directionx
.point(0).y = .point(0).y + directiony
'Move the points
For n=0 to pointcount-2
.point(n)= .point(n+1)
Next
End With
noone
Jun 1st, 2000, 06:21 AM
I did a game similar to this in Java a bit back and I found it made things a lot simpler to create a 2 Dimensional array of byte or something. You'll still want to use UDT's like the other guys are telling you but a two dimensional array might help too. Then you end up with the screen being a grid.
Fox
Jun 1st, 2000, 08:37 AM
I dont see why you want to make a 2D array. The screen is in our case not a grid coz were going to set and collide single pixels...
noone
Jun 1st, 2000, 08:47 AM
Well If your doing snakes I really dont think you need pixel by pixel collision detection. It really does depend on how you want to make your game. It worked out well for me becasue every spot on the grid would either be a snake, a wall or nothing. And each snake object had a reference to the grid. It made drawing and updating much easier for me.
Fox
Jun 1st, 2000, 10:10 AM
Since were talking about 1 pixel sized snakes were going to use the screen as grid, that means in our case we have a resolution as high as the screen. Thats why we dont need a grid, we can directly use the pixels...
noone
Jun 1st, 2000, 10:35 AM
I didnt realise you where using 1 pixel snakes, then using just pixels makes a lot more sense. I was using 10 pixels by 10 pixels and a game size of something like 300*250. This is a different case then
Fox
Jun 1st, 2000, 10:45 AM
Think so. Well, now hes got 2 solutions :)
Mag-Net
Jun 1st, 2000, 03:20 PM
Have i got this right? there will be the snake one pixel thick? that is a bit thin isn't it! I would rather have a big bulging snake, especially if what he has to collect is pies ;)
Mag-Net
Jun 1st, 2000, 03:26 PM
Thanks Fox, ur right i didnt initialise the snake, i must have been tired! I knew that it would need to be done...yeah lets put it down to tiredness! :)
Mag-Net
Jun 1st, 2000, 03:36 PM
Hey guess what, I am confused again...
...the code runs, but how do i get it to work so that i can see the snake on the screen?
kedaman
Jun 1st, 2000, 08:23 PM
Mag, you need to have a continous loop, or timer, (i hope you use the loop) Within it you call the mousemoving method, the collisiondetecting method, and the drawing method. You must also have a doevents (if you use a loop)
The drawing need your snake pixel size so you need to declare it
Private Snakepixel%
And let snakepixel=16 in form load
or just use
Const Snakepixel%=16
Then to the drawing method:
cls
With magsnake
for x=0 to .pointcount-1
line(snakepixel*.point(x).x,snakepixel*.point(x).y)-(snakepixel*(1+.point(x).x),snakepixel*(1+.point(x).y)),vbred,BF
next x
end with
Mag-Net
Jun 2nd, 2000, 03:11 AM
Now I get you, I can see this being a long thread! Hope not! Thanks, as I have said before I have never done it before and so dont know how to do these things... :(
TalZ
Jun 5th, 2000, 07:45 PM
Mag, I got this game
i made it all ready...
if you want the source email me, i send it to you.
hope to help
Fox
Jun 7th, 2000, 05:02 AM
There's also a demo (http://orion.spaceports.com/~mccloud/coding/general.htm#Snakes) on my website...
Mag-Net
Jun 7th, 2000, 07:07 PM
Thanks Fox and TalZ, much appreciate it!
:)
Fox, i love the description on ur site of the game, to the point! :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.