473,396 Members | 1,990 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,396 software developers and data experts.

Some specific hit line problems..

Hello all..

Been having some more trouble with the hit lines in my Air Hockey
game.

I have some hit lines drawn (and loaded into an array, Lines) around
the borders of my table to repel the puck backwards when hit. However,
when i pass it the x and y position (puck_x and puck_y, respectively)
of the image of the puck on screen, it will not detect it touching a
hit line.

However, if i use that IsInLine() in my MouseMove() method and pass it
the e.X and e.Y mouse positions - it will recognise when the mouse
cursor touches the line. I'm guessing it's something to do with the
puck_x and puck_y positions i'm passing to the IsInLine() method?

Take a look at the source code excerpt (these are the four important
methods)below if you've a chance. Any suggestions or comments are very
much appreciated!

Thanks.
Brian

---------------------------------------------------------------------------

private void gameDraw(Graphics g)
{
// image of puck is loaded and drawn
Image image = Image.FromFile("Puck.png");
g.DrawImage(image, puck_x, puck_y, 35, 35);

// redraws hit lines
foreach(Line l in Lines)
{
l.DrawLine(g, Color.FromArgb(192,192,192));
}
}
private void gameLoop(Object sender, EventArgs e)
{
foreach(Line l in Lines)
l.IsInLine(new Point(puck_x, puck_y));

puck_x += x_vel;
puck_y += y_vel;

//Called so the form will repaint itself.
Invalidate();
}

public bool IsInLine(Point pnt)
{
Pen p = new Pen(Color.Black,PenWidth);
GraphicsPath pth=new GraphicsPath();
pth.AddLine(StartPoint, EndPoint);
pth.Widen(p);
p.Dispose();

if(pth.IsVisible(pnt))
{
this.hit=true;
return true;
}
else
{
this.hit=false;
return false;
}
}

public void DrawLine(Graphics g,Color c, int x_vel, int y_vel)
{
Pen p=new Pen(c,PenWidth);
if(hit)
x_vel *= -1;
y_vel *= -1;
g.DrawLine(p,StartPoint,EndPoint);
p.Dispose();
}
Nov 16 '05 #1
0 972

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

Similar topics

1
by: Sean | last post by:
For the last couple of months I have been reading and working throught the examples in Magnus Lie Hetland's Book "Practical Python" This for all practical purposes is the first computer...
2
by: Benji99 | last post by:
Hi guys, I'm starting to learn Python and so far am very impressed with it's possibilities. I do however need some help with certain things I'm trying to do which as of yet haven't managed to find...
3
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit >...
1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
4
by: Marquisha | last post by:
If this is off-topic, please forgive me. But I thought this might be the perfect spot to get some advice about how to proceed with a project. Working on a Web site design for a nonprofit...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
5
by: Niall | last post by:
I have an unmanaged C++ ray tracer which I am working to put a C# front end on. It runs fine as just the unmanaged code. I have made a MC++ wrapper DLL to expose the required types to the C#...
28
by: Yuri CHUANG | last post by:
"No newline at the end of your output" is really a problem? I've never learned that before. So I desire to know some tips about writting a program perfectly.Can anyone give me some tips which are...
2
by: chromis | last post by:
Hi there, I've been reading an OOP book recently and it gives some nice Adaptor / Template patttern code to wrap around the php Mysql functions. I thought that I'd try and create a Simple Address...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.