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.

DarkBASIC Professional Discussion / Strange glitch problem in my game

Author
Message
Sli3her
15
Years of Service
User Offline
Joined: 20th Feb 2011
Location: Deep in code...
Posted: 29th Feb 2012 16:17
I'm currently working on a Pong clone game that I have many great ideas for. At the moment though I'm having problems with the AI paddle not stopping at the top of the screen. I've used this same code to stop sprites from moving off the screen before so I'm kinda baffled at what's going on. Below is the function that is supposed to be stopping the paddle. The paddle will stop at the bottom of the screen, but, for some odd reason when it hits the top of the screen it reappears at the bottom. I've also included the link to my game so you can see better what's happening.



Link to game: http://mrhtml16.angelfire.com
Penfold
22
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: RED postbox houses of parliment
Posted: 29th Feb 2012 19:44 Edited at: 29th Feb 2012 19:45
/try moddifying your code so it only checks if its too far up or down if it actually travels that way. at the moment it seems to triggering the line of code that makes the height the bbotom of the screen as if when the y goes into a negative it becomes greater than the bottom of the screen

try the following code

IF CenterOfPaddle < BallY
INC PaddleTwoY, PaddleTwoSpeed `PADDLE IS HIGHER THAN BALL- MOVE DOWN
IF PaddleTwoY > BottomOfScreen THEN PaddleTwoY = BottomOfScreen `BOTTOM OF SCREEN
Endif

..and alter the up code to similar style

'Ooh 'eck chief'...'crumbs'
Sli3her
15
Years of Service
User Offline
Joined: 20th Feb 2011
Location: Deep in code...
Posted: 1st Mar 2012 04:13
Thanks for your help. The problem wasn't with the code itself but rather the variable type I was using. I was using a WORD variable instead of an INTEGER. The paddle Y value must have been going past the top of the screen and since WORD variables don't support negative numbers it seems as though it was wrapping to the bottom of the screen, and then the code that is responsible for checking to see if the paddle is at the bottom was executing causing the paddle to "glitch" all the way down.
Penfold
22
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: RED postbox houses of parliment
Posted: 1st Mar 2012 12:31
glad its fixed

'Ooh 'eck chief'...'crumbs'

Login to post a reply

Server time is: 2026-07-10 20:58:20
Your offset time is: 2026-07-10 20:58:20