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 / Simple Pong Example code issues

Author
Message
punkrockserfer
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location:
Posted: 28th Dec 2009 04:29
Hey everyone,

I'm completely new to DarkBasic Pro. I'm following a book that has example games to create as it teaches you. I'm on the first one, called "Simple Pong" and things keep going wrong.

First, after copying the code correctly (i quadruple checked, so I know it's right) I tried to run the game and all it did was crash. I searched around and found that someone mentioned I should upgrade to the latest version of DarkBasic pro. I downloaded the latest version and installed it, and now whenever I run the program, it no longer crashes but I have a new issue.

Everytime I run the game, the ball in the center only moves up and down, which of course is useless. It doesn't crash and the paddles move but the ball never strays from the enter of the screen. Can someone help me? Here is the code:

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Dec 2009 06:43 Edited at: 28th Dec 2009 06:48
unfortunately, that particular tutorial is askew. the error lies in the way it's checking for "collision" which is to see what color the pixel is below the "ball". here:



the way dbpro is working now (and this is probably a bug), point is always > 0, causing the ball to "bounce" every time it moves.

for further info, see this recent thread which deals with your situation.

and, where is this tutorial being published? which "book" are you guys finding this in?

Virtual Nomad @ California, USA
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
punkrockserfer
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location:
Posted: 28th Dec 2009 07:06
Thanks for the response Virtual Nomad. I'm not sure if my particular issue was resolved in that other thread, as my concern was not so much the collision-detection. While I was having that issue as well, my larger issue is that for some reason, this version of pong is unplayable because the ball refuses to move anywhere left or right. It only moves vertically constantly.

However, I'm sure once this is issue is resolved, I will need to look into the collision-detection as well because before I updated the DarkBasic Pro software, I was having collision-detection issue also. Do you have any ideas as to why DarkBasic Pro would be prohibiting my "ball" from moving horizontally?

Oh, and the example that everyone seems to be having issues with is from this book:

http://www.amazon.com/DarkBASIC-Game-Programming-Jonathan-Harbour/dp/1598632876/ref=sr_1_1?ie=UTF8&s=books&qid=1261979566&sr=8-1
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 28th Dec 2009 08:14 Edited at: 28th Dec 2009 08:19
@punkrockserfer: Actually, your concern is indeed the collision detection. As Virtual Nomad pointed out, the point() function is returning a different value for us now than it was when the tutorial was written. The new value being returned is greater than zero, and so the ball is always switching horizontal direction, thus appearing motionless in that direction.

@Virtual Nomad: This isn't a bug. Apparently the default background color used to be 0x00000000, but is now 0xFF000000. The point() function is returning 4278190080, which is 0xFF000000 in hex, which is 255,0,0,0 in ARGB, which is black with an opaque alpha.

Edit: Which means the conditional should look like this:
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Dec 2009 10:46 Edited at: 28th Dec 2009 10:49
@punkrockserfer,

it appears, to me, to be the exact same issue. try the "fix" in the older thread or the one kira provided above and see if it works as you'd expect.

also, i was hoping the author was a user here (i expect he/they are but i dunno their usernames) and could somehow be contacted and maybe announce some updates/fixes, etc, but... guess not. (i thought maybe it was a PDF "book" that was circulating vs a hard copy)

@kira,

point was 4278190090 the last time this was discussed? i've spent too much time playing with this already since i never use point for anything but there is still an issue when using cls... if you've inked ForeColor,0 , then cls is supposed to use the inked background color, 0...? ink 0 is 0,0,0,0 vs 255,0,0,0, i'm guessing? i dunno all that hex-mex stuff...

btw, welcome back, (if you've been gone awhile?). i haven't seen you post in a bit and i generally learn something new when you do, so....

Virtual Nomad @ California, USA
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Dec 2009 12:46
Hey, I had the same problem with the pong tutorial when I got the DB Programming book. Anyway, I created a very simple work around that even added more colour to the game. I just used the ink command to change the colour of the ball and changed the point condition to detect for the right colours. I would post source code but I'm on my phone at the moment. Just try experimenting with different colours.

Hope this helps

A clever person solves a problem, a wise person avoids it - Albert Einstein
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 28th Dec 2009 20:39
@Virtual Nomad: Hm, you sure about that? That doesn't make sense to me, 'cause that color wouldn't be exactly black, actually, it'd be a tad blue. The hex is 0xFF00000A, which would be 255,0,0,10 in ARGB. Who knows, maybe there was a bug and now there isn't.

The hex representation of colors is actually quite simple; it only looks a little cryptic. 0xFF000000 and 4278190080 are literally the same thing, just written in different number systems (hexadecimal (a hex number is pretty traditionally denoted by "0x" in front) is base 16 and decimal is base ten). With the hex representation, we can nicely divide the color up into four channels, A, R, G, and B, 'cause every two digits in hex is one byte. So, 0xFF000000 is 0xFF,0x00,0x00,0x00 in ARGB, which is 255,0,0,0 using decimal numbers.

But yes, apparently there is still an issue with cls. I ran this little bit of code and it printed 4278190080 when logically it should've printed 0.



However, when you manually specify a color for cls, it gets it right.



And... d'aww that's nice of you to say. Thanks
punkrockserfer
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location:
Posted: 29th Dec 2009 07:58
Hey everyone, thanks a TON for all the responses and help. For anyone curious, this example code is printed in the introductory chapter, as sort of a "look what you can do right now" exercise. The book doesn't explain at all why the code is written how it is, or how it works. So while your explanations make sense to each other, I can't make heads or tails of any of them YET. Hopefully that will change within the next few months.

Anyway, I entered the code provided by Kira Vakaan into the example and it now plays as would be expected. So, while I still don't yet understand why it works, it DOES in fact work, and I feel I can move on in the book to learn about how to use DarkBasic. Again, thanks everyone for all the help and quick responses.

Oh, and Virtual Nomad: I apologize profusely for posting this problem in two forums. I posted it in the general discussion first, and then realized I may have erred by posting it in the wrong place. As a newcomer and not wanting to offend anyone, I decided perhaps it would be best to post it here in the newcomers thread. It was then that I read the "what not to do" thread for newcomers where it mentions not posting the same issue in multiple forums...

Anyway, I'm very sorry for the general "muckiness" I've caused here and I assure you I'll try to be more orderly in my future here at these forums. Again, thanks everyone!

Login to post a reply

Server time is: 2024-11-24 20:17:35
Your offset time is: 2024-11-24 20:17:35