Results 1 to 22 of 22

Thread: Nibbles!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91

    Question

    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!
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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
    Code:
    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?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    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
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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:
    Code:
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Indeed.

    Making your own object would mean to make a class. It is however easier to use an UDT for this simple game

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    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
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  7. #7
    Guest
    Where did you put the code?

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    You probably didnt initialize the Snake:
    Code:
    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

  9. #9
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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.
    "People who think they know everything are a great annoyance to those of us who do."

  10. #10
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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...

  11. #11
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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.
    "People who think they know everything are a great annoyance to those of us who do."

  12. #12
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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...

  13. #13
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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
    "People who think they know everything are a great annoyance to those of us who do."

  14. #14
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Think so. Well, now hes got 2 solutions

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    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's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    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's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    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?
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  18. #18
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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:
    Code:
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    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...
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  20. #20
    Junior Member
    Join Date
    Jun 2000
    Posts
    16

    Wink I maked this game all ready!

    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
    Tal Zur!

  21. #21
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    There's also a demo on my website...

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    Thanks Fox and TalZ, much appreciate it!



    Fox, i love the description on ur site of the game, to the point!
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width