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 / Pong tutorial not working

Author
Message
Arty
15
Years of Service
User Offline
Joined: 26th Oct 2009
Location:
Posted: 26th Oct 2009 21:07
Hi all.

I've just started with Dark Basic and have been following through a tutorial book making simple games.

I've gotten to making pong, but i can't get it to work. Even the code they have produced doesn't seem to work. It is not picking up the collision between the paddles and the ball for some reason.

All i can think of is there is something wrong in the following lines:





I know there is another way of detecting collisions ( sprites? ) but i'd like to do it the way the tutorial has done, if still possible, by fixing it.

Anyone got any ideas? Thanks.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Oct 2009 13:17
Quote: "but i can't get it to work"


Hardly the best description of your problem if you want someone to help you is it?

"Please fix my car - it doesn't work" won't get you very far with a mechanic...

Why not tell us exactly what happens and what error(s) you get - especially as we can't run your full code snippet without the missing files.

There's nothing wrong with the two lines you highlight either.

TDK

Arty
15
Years of Service
User Offline
Joined: 26th Oct 2009
Location:
Posted: 28th Oct 2009 14:30
Quote: "It is not picking up the collision between the paddles and the ball for some reason."


The issue is that no collision is detected when the ball hits the paddle. There are no errors as such, just the ball passes straight through the paddle. [I'm sorry i fogot the code couldn't be run.]

I linked the two pieces of code as i believe at least one of them is not functioning in the way i intended. As intended i mean that the paddle is set to the colour yellow. When the midpoint of the ball comes into contact with a colour that is not black then it should change direction.

My only idea is that the code i have written is not detecting change in colour, possibly because it's not setting the background colour of the paddle to yellow, only the foreground? I'm not sure, i am not common with exactly what the INK or POINT command do, i only know the general idea of when they are used.

I hope that is enough infomation this time. =)
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Oct 2009 19:36 Edited at: 28th Oct 2009 19:39
Quote: "All i can think of is there is something wrong in the following lines"


arty, you're right...

apparently INK 0 is not the same as INK RGB(0,0,0)
(i always used ink 0 but i don't use point much, so)...

at the top under "Define Environment Settings", if you change:

INK RGB(255, 255, 0), 0

to

INK RGB(255, 255, 0), RGB(0,0,0)


then, in the ProcessPlayerHits() function, change it to:

IF POINT(BallX, BallY) <> RGB(0,0,0)

...it works as intended.


Arty
15
Years of Service
User Offline
Joined: 26th Oct 2009
Location:
Posted: 28th Oct 2009 20:39
ahh great thanks!!!
works perfectly, you're a star! hehe
I'll make a mental note of that for the future.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Oct 2009 23:07
Quote: "apparently INK 0 is not the same as INK RGB(0,0,0)"


But it is... or at least should be!

Sounds like a DBP bug to me.

Never-the-less, well spotted Virtual Nomad.

TDK

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Oct 2009 08:25 Edited at: 29th Oct 2009 08:36
one of the things i'd done with the code above was change the looping cls to cls 0 and it works (it was something i did after posting the "fix" above. cls is supposed to use the background color declared in the ink command which was:

INK RGB(255, 255, 0), 0

if you point the black areas, it's value is 4278190090, which triggers the collision:


same goes if you:

INK RGB(255, 255, 0), RGB(0,0,0)

...

using CLS 0, point returns 0

i found the "0" shortcut for rgb(0,0,0) a long time ago and use it quite a bit (again, i don't point much so never had an issue like this. i get black when i expect to get black). point is supposed to return a dword but ink is confusing since the help files state the fore- and background parameters accept integers yet goes on to show use of rgb (again, dword) for the parameters in the example code.

as TDK stated, it might be a bug, but it's also a matter of some of us using incorrect datatypes for the parameters (causing unexpected results, just like using integers instead of reals/floats when working with 3d coordinates).

btw, i'm using 7.2 and i'm pretty sure newer releases allow ink to run with only the foreground color declared now, right? so, if CLS uses the background color declared in ink, who knows what will show when you point... (i'm guessing the fact that black is the default background color has something do to with this, too... there's a value stored somewhere, obviously, whether we declare it or not).

ah, fun stuff, eh?


pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 29th Oct 2009 14:28
In the case of me, a cord of the first post works.
I use DBP Ver1.074.


I found another bug.
kuljot
15
Years of Service
User Offline
Joined: 2nd Jan 2009
Location: sacramneto, ca united states
Posted: 1st Nov 2009 16:51
Hey just wondering, what book is the tutorial from?

Gateway GT5628 Quad Core Desktop Intel Core 2 Q6600 2.4GHz Quad Core 3072MB RAM / 500GB 7200 SATA II Hard drive DVD RW 18X multi dual NVIDIA GeForce 8500GT ....

Login to post a reply

Server time is: 2024-11-24 00:52:27
Your offset time is: 2024-11-24 00:52:27