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 / My first game - help needed

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Jul 2004 06:01
It seems traditional that everyone's first ever game should be a pong game - so I set about my own variant - 'bouncy pong'. I'm quite pleased with the result considering I'm new to this - except for one thing - the movement of the bat is jerky - it seems to get stuck at random intervals!

If anyone has time to look at the code, perhaps you could help me figure out how to prevent this. I tried using sync on before the main loop and sync before the loop command, but this didn't work.

If anyone also has any comments on the general way I've coded the program - ie. could I have done it more efficiently/neatly? Any help gratefully received.

Thanks,

Richard.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 19th Jul 2004 06:38
try putting the sync on command at the beginning of the program and replace your main loop with:


then use and image for the paddle like this:


(change the 600 to the x coordinate of the paddle.)

and change the move_paddle subroutine to:



I would also suggest replacing the opponents paddle with an image as well as the ball and walls.
this will make collision detection much easier as well as movement.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Jul 2004 09:56
Thanks - I changed the box and circle for image sprites as you suggested - and it made things work a lot smoother. Strange that though - you'd have thought two simple moving shapes wouldn't have caused much problem (even with sync on it wasn't smooth).

Next two problems - firstly why is the background now blue since I have changed from shapes to sprites? I tried 'CLS rgb(0,0,0)' but it still shows a blue background - and I want it black.

Secondly, now that I've changed to using the 'IF SPRITE COLLISION' command, which works most of the time, but occasionally strange things happen, like the ball sticking to the bat or the walls - any ideas?

Thanks

Richard
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 19th Jul 2004 11:32
Not sure about the collision problem

for the background problem try:

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Jul 2004 11:35 Edited at: 19th Jul 2004 11:36
Thanks

But now the movement of the paddle is all jerky again! Sync is on, and only two moving sprites!
Lzdude69
20
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 19th Jul 2004 12:00
try changing the sync rate

When I die...I want to be buried upside down...So thy critics can kiss my a$$...Oh yeah, Im not dying...
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Jul 2004 12:20
Aha! The game works!! I experimented with the places I put the sync command which made a difference. Thanks for the help, folks. Time for the next step - adding an A.I. opponent.
Sir Spaghetti Code
20
Years of Service
User Offline
Joined: 12th Jul 2004
Location: Just left of Hell
Posted: 19th Jul 2004 13:58 Edited at: 19th Jul 2004 17:05
OK, I'm new to this DB thing (hehe), but I do have some QBASIC experience (liek that REALLY means anything). I have a general idea for Pong AI. You could set up stages, with the requirement to reach the next stage being to reach score 7 before the computer (shouldn't be too high as to create boredom in one stage). In the first stage, you could set the AI paddle to follow the ball, therefore hitting it. You could add in a descently small sized random number (RND(7)). -EDIT: Oops, forgot to mention that the random number is determined each time the player hits the ball.-If 0 to 3, the center of the paddle will follow the ball at the pace of the ball. If 4, then the paddle will lose a little speed, most likely still able to return the ball. If 5 it get slower, 6 even slower, and 7 the slowest and will definetly miss the ball. The player (if they are not blind) will beat the level.

On the higher levels, you could add in another variable to the mix. The ball will undoubtably be coded to move faster at this point (building speed with each level), but also, for every time the player successfuly hits the ball in a row, the chances that AI will miss the ball increase. At higher levels, the first several hits from the AI are sure hits, whereas each continues volly will increase the AIs chance of failing (moving too slow to hit the ball). You could create a variable to keep track of every consecutive hit by the player, then add that into the formula for the CPU AI. I have not fully worked this into code, as this is just an idea. I feel that this would put in a very realistic AI, getting tougher each stage, but with an element of suprise, coming from the random number in the AI equation.

This would also make the game much more fun, adding more of a deminsion of challenge. In the original Pong (the first with the AI), you set the difficulty at the beginning of the game, and it remainded the same all the way through. This way, it gets more challenging, making the player want to keep playing.

This is just an idea for a Pong AI. If anybody would like to try this idea out in your game, please let me know how it goes!
Lzdude69
20
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 19th Jul 2004 23:46
Or you could just store the ball positions look at this:



then just use your random ball system , I dont know how that would work in your program

When I die...I want to be buried upside down...So thy critics can kiss my a$$...Oh yeah, Im not dying...
Lzdude69
20
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 19th Jul 2004 23:52
And spaghetti, qbasic is alot like db except for all the 3d. I started out on qbasic, so I felt really familiar with db. The only thing with db,(if your some that knows a basic language) they didnt add enough of the origanal basic commands, well the important ones are there, whew...

When I die...I want to be buried upside down...So thy critics can kiss my a$$...Oh yeah, Im not dying...
Sir Spaghetti Code
20
Years of Service
User Offline
Joined: 12th Jul 2004
Location: Just left of Hell
Posted: 20th Jul 2004 02:51
OK, I guess I shouldn't have said it was useless, it is actually helpful! And yes, I do feel like the original BASIC commands are a little lacking, but that doesn't bother me at all ! You know how I loved that spaghetti code (I always loved line numbers and keeping track of programs that way GOTO 560)! That was sarcasm of course ! That was one of my worries when I got DB, was that , since it is BASIC, it would have line numbers!

P.S.- What do you think about my theoretical Pong AI, as I have never made AI before?
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 20th Jul 2004 03:11
To make sure that the paddle goes up and down when it should, you could try this:

you can try placing these lines of code in your ai subroutine
if you ball is moving faster than 1 make the paddle movement speed (the number getting added or subtracted from its y coordinate) to about .5 less than the balls speed (that way it can miss). If you want to make some levels easier than others, just change how fast the paddle moves.
Lzdude69
20
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 20th Jul 2004 03:17
Not bad dude, but when you do that its always hard to make collision for the ball and the player, you dont need collision for the opponet obviously, but the random ball movement is exactly how I would have done it.

p.s._By the way, qbasic doesnt use line numbers, thats just basic, but I get your point.

p.s.s._spaghetti:I found you can almost learn db and use qb at the same time, since they are practically built around the same, well they are the same, except db has a few more tricks,Like 3-D-but you can fill in for dbc's lack of origanal commands with functions, thank the lord db has functions

When I die...I want to be buried upside down...So thy critics can kiss my a$$...Oh yeah, Im not dying...
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 20th Jul 2004 06:47
AlienMan & Sir Spaghetti Code, the major aspect I miss most from the original Basic is print formating, as in "print a, b, c" defined column alignments for the numbers displayed. Having to include ," ", between each value, particularly in CLI mode, is straining my fingers.

I'd also like a "print using" if possible, but that's just wishing...

ttfn
S.

Any truly great code should be indisguishable from magic.
Sir Spaghetti Code
20
Years of Service
User Offline
Joined: 12th Jul 2004
Location: Just left of Hell
Posted: 20th Jul 2004 09:33
@Sandra D
Hmmm, that's very odd. I could have sworn my old version of qBASIC used line #s. I remember IF condition THEN GOTO 32
could I just be getting senile in my early twenties?
Lzdude69
20
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 20th Jul 2004 23:07
@spaghetti!
Um...yeah, but I know for a fact, QB didnt use line numbers.

@sandra D. (your name wouldnt have anything to do with Greese, would it?)I know exactly what you mean, all that bull crap they took away from basic, actually, some good some bad. I think they made Qbasic (which actually means QuickBASIC, as you know) sort of the same as basic, it the freakin same language, except they left out some stuff, like line numbers, praise the lord, But they left out stuff the cool column system. But why would you use cli, I never used it, except when I was learning, I mean, why would you use it, if im gonna try something, im gonna run it with the whole program, not just a few measly commands?

When I die...I want to be buried upside down...So thy critics can kiss my a$$...Oh yeah, Im not dying...
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 21st Jul 2004 01:41
Well, I use the CLI mostly for debugging, like when I get so frustrated I insert a break command and play with the values to see what's going on. But I'd also like to have columns for lists of stuff now & then, and one of my first functions was a print_rs(a,x) for print A right justified in X columns. Course, using anything but a fixed font meant the columns didn't line up, but at least it tried to make a neat display.

And yes, praise god they got rid of line numbers!

The name, no--I don't even like that movie. (ugh!)
S.

Any truly great code should be indisguishable from magic.
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 21st Jul 2004 05:48
i know for a fact that qbasic has OPTIONAL line numbers...i used it for 2 years and i used the line numbers to accomodate my sloppy GOTOs


Formerly known as "DarkWing Duck"
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 21st Jul 2004 06:39
I actualy LIKED the line numbers, I like lines like

goto (x*10)+1250
gosub 1024+(index*10)

lovely, I can`t see why people rant over line numbers, labels...now they are pain in the *rse ,hate the things, I would love an option for line numbers, never turn it off, the other thing that puzzles me is that Spectrums used nothing but floats for everything, yet we didn`t have problems with compares or using lines like

for i=1.7 to 1.9 step 0.05

so why is it decades on with CPU`s running at microwave frequencys we still need to use integers to get a decent speed even though threeD co-ordinates and dimensions are in floating point, and we are told you can`t do the above line because of floating point errors, oh well, I just must have been at it too long when I start going "when I was a young man" LOL

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster.
Sir Spaghetti Code
20
Years of Service
User Offline
Joined: 12th Jul 2004
Location: Just left of Hell
Posted: 21st Jul 2004 10:41
OMG! Are you telling me that line numbers were optional in qbasic?!? Oh well, I learned to program with Apple IIe BASIC ad kinda carried it over form there.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 21st Jul 2004 13:41
Hehehe. Apple Basic is good.... but I never tried line numbers in QB, and never really missed them either.

Any truly great code should be indisguishable from magic.
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 21st Jul 2004 23:34 Edited at: 21st Jul 2004 23:36
i liked them becuase i spaced my line numbers in 10 increments i.e.

so at the end my code looked like it was 10000+ lines (anyway that's where i got my sense of ego)

i wonder if i can find those games i made in QBasic and convert them to DBPro(no media of course...just stick figures that move )

at one point to do the enemy AI i didn't know about For-Next loops so i made individual(i mean individual variable names and values also) AI code for every single one of my 20 Monsters!

when i could have made one for-next loop...(classic text-book example)


Formerly known as "DarkWing Duck"
Lzdude69
20
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 22nd Jul 2004 00:14
How can you say you like them? Always haveing to go back to figure out which which line you goto was going to. I thought they sucked, I never used them in QB, and I really didnt think they had them, I guess its possible, since it is a basic language.

When I die...I want to be buried upside down...So thy critics can kiss my a$$...Oh yeah, Im not dying...

Login to post a reply

Server time is: 2024-11-27 01:51:34
Your offset time is: 2024-11-27 01:51:34