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

Thanks all.... game now all seems fixed...

[EDIT: Sorry for posting this initially as a new thread but i'm
posting via Google (terribly buggy!) as my account for reading
NewsGroups doesn't support this particular C-Sharp newsgroup]

Just to let you all know, got the issues with the puck straddling the
the hit-line's (jerking).

The error was that i was forgetting to add on the width of the image.

Let me elaborate... the puck is an image (puck.png) drawn and is set
at 35 pixels (height and width).

When the puck bounced at the top, it just read the puck_x which was
fine as that was the beginning of the image (the 0,0 in height and
width, in other words).

But when the puck wanted to bounce at the bottom, puck_y had to react
at the opposite end of the image (the 35,35 of height and width) and
was bouncing too late. It only reacted when it senses that puck_x was
at the bottom of the table, as opposed to puck_y.

So, i added on the dimension of the radius of the image (35) to the
puck_y to enable it actually takes the dimensions of the image into
account when bouncing at the bottom.

Probably could've worded that better but quite tough to explain.

Again, thanks all for the advice and suggestions.

PS - Cheers Jason for your advice regarding the smooth bouncing. Will
be starting into user interaction next week, so your useful advice
will come into it then.

PPS - Here's the entire GameDraw() method's updated code, for those of
you interested:

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);

// create a rectangle from the image of the puck
puckRect = new Rectangle(puck_x, puck_y, 35, 35);

// create a region out of the form (and exclude the table-top)
formRect = new Rectangle(0, 0, 983, 683);
formRgn = new Region(formRect);
formRgn.Exclude(pth);

// intersect the two regions (table-top and the puck)
intersection = new Region(pth);
intersection.Intersect(puckRect);

// if the puck is visible outside the table-top region, return true!
boundaryHit = formRgn.IsVisible(puckRect);

// if boundary hit, check whether it was hit in a goal
if(boundaryHit == true)
{

// if puck hits either player's goal, increment the opponent's score
if(puck_y <= 76 && (puck_x >= 341 && puck_x <= 454))
{
IncrementPlayer1Score();
}

else if(puck_y + 35 >= 595 && (puck_x >= 333 && puck_x <= 461))
{
IncrementPlayer2Score();
}

// if puck hits the top or bottom of the table, bounce the puck back
in opposite direction!
if(puck_y <= 76 || puck_y + 35 >= 595)
{
y_vel*=-1;
Sound.PlaySoundContinue(@"bounce.wav");
}

else
{
x_vel*=-1;
Sound.PlaySoundContinue(@"bounce.wav");
}
}
}
Nov 16 '05 #1
3 1528
[OT]

If you want to get to this newsgroup without google.

Open Outlook Express, and add the news server "msnews.microsoft.com", which
is available to all for free.
This is done under the menu Tools->Accounts...
Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Ebook at http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html
"Brian" <br************@gmail.com> wrote in message
news:c2*************************@posting.google.co m...
[EDIT: Sorry for posting this initially as a new thread but i'm
posting via Google (terribly buggy!) as my account for reading
NewsGroups doesn't support this particular C-Sharp newsgroup]

Just to let you all know, got the issues with the puck straddling the
the hit-line's (jerking).

The error was that i was forgetting to add on the width of the image.

Let me elaborate... the puck is an image (puck.png) drawn and is set
at 35 pixels (height and width).

When the puck bounced at the top, it just read the puck_x which was
fine as that was the beginning of the image (the 0,0 in height and
width, in other words).

But when the puck wanted to bounce at the bottom, puck_y had to react
at the opposite end of the image (the 35,35 of height and width) and
was bouncing too late. It only reacted when it senses that puck_x was
at the bottom of the table, as opposed to puck_y.

So, i added on the dimension of the radius of the image (35) to the
puck_y to enable it actually takes the dimensions of the image into
account when bouncing at the bottom.

Probably could've worded that better but quite tough to explain.

Again, thanks all for the advice and suggestions.

PS - Cheers Jason for your advice regarding the smooth bouncing. Will
be starting into user interaction next week, so your useful advice
will come into it then.

PPS - Here's the entire GameDraw() method's updated code, for those of
you interested:

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);

// create a rectangle from the image of the puck
puckRect = new Rectangle(puck_x, puck_y, 35, 35);

// create a region out of the form (and exclude the table-top)
formRect = new Rectangle(0, 0, 983, 683);
formRgn = new Region(formRect);
formRgn.Exclude(pth);

// intersect the two regions (table-top and the puck)
intersection = new Region(pth);
intersection.Intersect(puckRect);

// if the puck is visible outside the table-top region, return true!
boundaryHit = formRgn.IsVisible(puckRect);

// if boundary hit, check whether it was hit in a goal
if(boundaryHit == true)
{

// if puck hits either player's goal, increment the opponent's score
if(puck_y <= 76 && (puck_x >= 341 && puck_x <= 454))
{
IncrementPlayer1Score();
}

else if(puck_y + 35 >= 595 && (puck_x >= 333 && puck_x <= 461))
{
IncrementPlayer2Score();
}

// if puck hits the top or bottom of the table, bounce the puck back
in opposite direction!
if(puck_y <= 76 || puck_y + 35 >= 595)
{
y_vel*=-1;
Sound.PlaySoundContinue(@"bounce.wav");
}

else
{
x_vel*=-1;
Sound.PlaySoundContinue(@"bounce.wav");
}
}
}

Nov 16 '05 #2
As an optimization Brian you should consider cacheing the puck image instead
of loading it from file every draw cycle. Probably a good place to do this
is in the OnLoad of the game form.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian" <br************@gmail.com> wrote in message
news:c2*************************@posting.google.co m...
[EDIT: Sorry for posting this initially as a new thread but i'm
posting via Google (terribly buggy!) as my account for reading
NewsGroups doesn't support this particular C-Sharp newsgroup]

Just to let you all know, got the issues with the puck straddling the
the hit-line's (jerking).

The error was that i was forgetting to add on the width of the image.

Let me elaborate... the puck is an image (puck.png) drawn and is set
at 35 pixels (height and width).

When the puck bounced at the top, it just read the puck_x which was
fine as that was the beginning of the image (the 0,0 in height and
width, in other words).

But when the puck wanted to bounce at the bottom, puck_y had to react
at the opposite end of the image (the 35,35 of height and width) and
was bouncing too late. It only reacted when it senses that puck_x was
at the bottom of the table, as opposed to puck_y.

So, i added on the dimension of the radius of the image (35) to the
puck_y to enable it actually takes the dimensions of the image into
account when bouncing at the bottom.

Probably could've worded that better but quite tough to explain.

Again, thanks all for the advice and suggestions.

PS - Cheers Jason for your advice regarding the smooth bouncing. Will
be starting into user interaction next week, so your useful advice
will come into it then.

PPS - Here's the entire GameDraw() method's updated code, for those of
you interested:

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);

// create a rectangle from the image of the puck
puckRect = new Rectangle(puck_x, puck_y, 35, 35);

// create a region out of the form (and exclude the table-top)
formRect = new Rectangle(0, 0, 983, 683);
formRgn = new Region(formRect);
formRgn.Exclude(pth);

// intersect the two regions (table-top and the puck)
intersection = new Region(pth);
intersection.Intersect(puckRect);

// if the puck is visible outside the table-top region, return true!
boundaryHit = formRgn.IsVisible(puckRect);

// if boundary hit, check whether it was hit in a goal
if(boundaryHit == true)
{

// if puck hits either player's goal, increment the opponent's score
if(puck_y <= 76 && (puck_x >= 341 && puck_x <= 454))
{
IncrementPlayer1Score();
}

else if(puck_y + 35 >= 595 && (puck_x >= 333 && puck_x <= 461))
{
IncrementPlayer2Score();
}

// if puck hits the top or bottom of the table, bounce the puck back
in opposite direction!
if(puck_y <= 76 || puck_y + 35 >= 595)
{
y_vel*=-1;
Sound.PlaySoundContinue(@"bounce.wav");
}

else
{
x_vel*=-1;
Sound.PlaySoundContinue(@"bounce.wav");
}
}
}

Nov 16 '05 #3
Thanks Mike.. been looking for a free newsgroup's account that i can use in
OE.

And cheers for your advice also, Bob. I never even considered the effect
that re-drawing that puck every time would have.

Much appreciated!

Nov 16 '05 #4

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

Similar topics

21
by: BlackHawke | last post by:
My name is Nick Soutter, I own a small game development company (www.aepoxgames.net) making our first game (www.andromedaonline.net) in java. I am writing because we are having a very...
138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
1
by: Antimon | last post by:
Hi, I am working on a browser based space simulation game. I think about two different architectures but i cannot decide, First one is to use and rdbms to store persistent world data. But i...
18
by: jaso | last post by:
Hi, I'm making this video game in C. The game contains a player, enemies and bullets. These objects, which are arrays of structures, are initialized, updated and drawn in a game loop. Now I am...
4
by: COHENMARVIN | last post by:
Are there any good sources on video game programming in vb.net? Is "DirectX" a set of libraries for video game programmers? The reason I ask is that I'd like to convert a board game into a...
5
by: colin | last post by:
Hi, Ive got a 3d model editor wich im developing with XNA c# development environment, using the game window to display the wireframe mesh in 3d. however I need to use some other windows too,...
6
by: pereges | last post by:
I want to begin by making simple 2D games for Dos. What particular features of C should I look to strengthen ? I am not asking about the graphics bit but in general.
10
by: Humakt | last post by:
I'm trying to figure a good way to handle saving game state to file (common save/load game function in games). ObjectOutput/InputStream seems most promising so far. However,the object I'm saving...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.