473,385 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What is wrong with this hit-line checking?

Hello all,

Can someone please give me some advice specifically in the hit-lines cos
i've been at them for for a while now and i still can't figure out a way to
solve the trouble the puck has around the border of the table. It basically
stutters around some areas of the border. But i think i figured out why this
is occuring:

(bear with me..)

If the puck is moving at a speed of 3, it will redraw the puck 3 pixels
(both x and y) further ahead each time. Basic motion!

If the puck is 1 pixel away from the border, it checks and sees it is not
outside the border and moves ahead 3 pixels. It is now outside the region.

It then checks if the puck is visible outside the region.. and it is, it
reverses it's direction. But when it checks again, it is still those 3
pixels outside the region. So that's how i'm getting those stutters in
motion around the border.

I'm trying to fix this by:
- checking the next puck position before i move the puck
- if the next puck position is not outside the table, move the puck as
normal
- if it is due to go outside the table, first check if the next puck
position is higher or lower than the current one.
- If higher, increase the x and y position of the point of the puck each
time until it is visible outside the border. If lower, decrease the x and y
position of the point of the puck each time until it is visible outside the
border.
- Then, take this position of the puck away from the original position and
that should be the distance from the puck to the border.
- increase the puck by this amount to get it touching the border. But it's
not working!

Please look at the game (address in above post) to understand more about
this problem.

Any help would be much appreciated as i'm at my wit's end!!

Brian

PS - Below is the code i've been working at:

private void GetNextPuckPosition()

{

flNextPuckXPos = puck_x + x_vel;

flNextPuckYPos = puck_y + y_vel;

intNextPuckXPos = Convert.ToInt32(flNextPuckXPos);

intNextPuckYPos = Convert.ToInt32(flNextPuckYPos);

nextPuckPos = new Point(intNextPuckXPos, intNextPuckYPos);

nextPuckPosOutsideTable = formRgn.IsVisible(nextPuckPos);

}

private void gameLoop(Object sender, EventArgs e)

{

CheckPlayer1HitPuck();

CheckPlayer2HitPuck();

GetNextPuckPosition();

if(nextPuckPosOutsideTable != true)

{

puck_x += x_vel;

puck_y += y_vel;

}

else

{

if(intPuck_x < intNextPuckXPos)

{

for(int i = intPuck_x; i <= intNextPuckXPos; i++)

{

for(int j = intPuck_y; j <= intNextPuckYPos; j++)

{

Point puckPosPt = new Point(i, j);

if(formRgn.IsVisible(puckPosPt))

{

int distXToBorder = intPuck_x - i;

int distYToBorder = intPuck_y - j;

puck_x+=distXToBorder;

puck_y+=distYToBorder;

break;

}

}

}

}

else

{

foundBorder = false;

for(int i = intPuck_x; i >= intNextPuckXPos; i--)

{

for(int j = intPuck_y; j >= intNextPuckYPos; j--)

{

Point puckPosPt = new Point(i, j);

if(formRgn.IsVisible(puckPosPt))

{

int distXToBorder = intPuck_x - i;

int distYToBorder = intPuck_y - j;

puck_x += distXToBorder;

puck_y += distYToBorder;
foundBorder=true;

break;

}

if(foundBorder==true)

break;

}

if(foundBorder==true)

break;

}

}

}

nextPuckPosOutsideTable = false;

//Called so the form will repaint itself.

Invalidate();

}
Nov 16 '05 #1
0 895

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

145
by: Mark Johnson | last post by:
Oddly enough, I found it difficult, using Google, to find a list of best-of sites based on the quality of their css packages. So I'd ask. Does anyone know of particularly good sites which are in...
29
by: asj | last post by:
Can you guess what this is? http://www.blueboard.com/phone/apache_sept_2003.gif It's a history of the IIs "Titanic", which is being slowly and painfully sunk by the open source Apache web...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
8
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
3
by: P1ayboy | last post by:
I have two forms on a page, one for logging in a user and a second one to search thesite. The problem is, when i enter data into the search and hit enter, it activates the login button. I need to...
4
by: tfsmag | last post by:
It acts like it sends, but nothing ever shows up... anything you guys can find glaringly wrong here? Thanks in advance, Jeff Here is the code that is supposed to send the mail. ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: ASP Developer | last post by:
I have a web service that returns a class when a web method is called. This class has a enum property with four values. These four values have default numbers. For example, Apple = 5 Orange...
1
by: =?Utf-8?B?TWlrZXkgQmFieQ==?= | last post by:
Greetings Hopefully, I can be clear and concise on this one, but I'm confused. I have a page with a ListBox <- ODS <- BusinessObject and a button. The Parameter Source is 'None'. The Default...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.