Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / [dbp] need help with my first program

Author
Message
nodeg
20
Years of Service
User Offline
Joined: 5th Jun 2004
Location:
Posted: 17th Jun 2004 00:52
I'm having some trouble with my first program. I'm trying to make a simple version of "nibbles". The problem I'm having is that i can't seem to get the program to draw a "tail" behind the player. All of this should be getting done in the drawwall function. Thanks in advance.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 17th Jun 2004 02:33
Hmmm....

As I recall Nibbles was program where you had a "head" and "tail" for the player programed, the "tail" of which followed the player's "head" to step around the screen, erasing itself as it went along. When a target was consumed (eaten by the worm) the "tail" would by-pass X number of steps in following the head, which made the worm longer. Most of this was done directly on the screen by detecting the 8 squares around the tail's point for the tail to follow the worm's body, while the head detected the 8 squares around it to detect both targets and the body of the worm for a failure condition. The head of course, followed the player's commands, but the tail always followed the lighted worm body.

Now, looking at your code. It looks like you've tried to use a matrix to save the "squares" (or pixels) of where the detection is made, but I don't see a "tail" or player "end point" in my first reading of it. Thus you have a "head" but no tail, meaning that to make the worm move properly you have to "walk down" the full length of the worm on each pass, and adjust how many "squares" or body segments the worm is allowed to be before erasing the tail. (This slows the code way down if you try it.)

Like I said, this game was orginally done "on screen" itself such that you didn't have to redraw the full screen all the time as you have done here. So, perhaps you'd best try to mimic the original as I have described it up above...

S.

Any truly great code should be indisguishable from magic.
nodeg
20
Years of Service
User Offline
Joined: 5th Jun 2004
Location:
Posted: 17th Jun 2004 03:39
You have the rules a little wrong. The idea is that you have a worm that goes around picking up gems... every time it gets a gem it gets bigger. If you crash into yourself you die.

Well, the way it supposed to work is that the screeninfo(800,500,2) stores a grid like you said. the screeninfo(x,y,1) portion of the array contains a value of 1, 2, or 3. 1 means that the square has nothing in it, 2 means that it has tail in it, and 3 means it has a gem. I haven't coded the gems yet.

screeninfo(x,y,2)contains a # that acts as a counter for any of the tail, and the drawwall function is supposed to delete any wall that is longer than variable determined by the amount of gems collected.

I know I shouldn't have to redraw the whole screen, but I don't know how to be selective about it yet. I've only done the 2d portion of the binary moon tutorial, which doesn't include anything about sprites or other things that would make my life easier. I figure this should still work despite all of that though.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 17th Jun 2004 07:08
No, I do not have the rules wrong.... what I described was how the game was created. This is a case of where your impression of playing the game is fooling you as to what the program is actually doing.

For instance;
1. the Worm is first drawn as being 3 segments long. As you command the head to move left, for each step it takes the "tail" part, 3 steps behind you, erases the worm's body. Thus creating the illusion of movement.

2. When you hit a target with a value of say "3" the tails stops making steps with you, thus making the worm graphic longer by those 3 steps. Eventually, the head of the worm runs into the sides of the play area, or part a the body as draw and not erased by the tail, and you lose.

Like I said, this was first implemeted on a machine that used large "oblong" boxes for its graphics, and all the program did was test the pixel boxes for being on or off directly on the screen. So long as you make a grid out of the screen--whether in a matrix or not--the head & tail pointers must still be used.

S.

Any truly great code should be indisguishable from magic.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 18th Jun 2004 19:18
Okay, I was half right...

...which also means I was half wrong.


But you still need a tail pointer however, to know where you are erasing. The program needs to implement a circular buffer where the coordinates of the worm body are being stored as it moves, thus each "step" taken by the graphic advances a head and tail pointer through the data. When a target (or gem as you call it) is eaten, the tail stops stepping so the buffer gets more full.

And after dinging around with my DBC for a while I've come to the same conclusion as you, that you need a world map array as well as the circular buffer. Seems the on screen detection doesn't work as well as I'd hoped.

Thanks for the project suggestion, it taught me a previously unknown quirk about my DBC, something made note of in the manual.
s.

Any truly great code should be indisguishable from magic.
Richard the_young
20
Years of Service
User Offline
Joined: 11th Jun 2004
Location: Uk
Posted: 19th Jun 2004 00:29
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 19th Jun 2004 15:56
Okay,

It took me a while what with my cold and all, but here is my version of the Nibbles game. One curiosity it has is that it declares multiple target hits from time to time, and I can't figure out where this is coming from. But it seems to be random enough to call it a "bonus" and leave it at that. If anyone figures out how this happens, let me know, please?

As you will see, I use both head & tail pointers like I was saying before. If nothing else, maybe it'll give you some ideas for your code.

Again, thanks for the idea, I found it educational.
Sandra.

Any truly great code should be indisguishable from magic.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 24th Jun 2004 07:48
I have finally figured out what happened.. after driving myself a lilttle crazy. I had the relationals wrong in the hit detection code and the target stack management.
here's the corrention;



(Decided not to post it all again, just the change.)
S.

Any truly great code should be indisguishable from magic.

Login to post a reply

Server time is: 2024-09-22 14:33:18
Your offset time is: 2024-09-22 14:33:18