473,396 Members | 1,871 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.

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

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 .

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
0 911

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

Similar topics

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...
3
by: Brian | last post by:
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...
6
by: jar13861 | last post by:
Create a game in a 3x3 HTML table that works as follows: * The goal of the game is to beat the computer by scoring more points than the computer. * The game starts when a hidden random number...
1
by: fowle040 | last post by:
I underlined and bold print my files. I need to know how to make this code into a working game. The object of the game is to have two players 1- belle and 2-beast. I want them to lose and gain...
8
by: Camellia | last post by:
Hi there this is an easy game which was inspired from my psychology class. I'll get 5/10 right prediction of your guess of head and tail at most time. If you could copy the code and run it that...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
2
by: serdar | last post by:
Hi, I'm designing a flash game and I have a text field to display the score as: 000000 I want to use a specific pixel font to display it. The only problem about this particular font is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.