Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Go Back  Xtreme Visual Basic Talk > > > Paddle & Ball Algorithm Advice


Reply
 
Thread Tools Display Modes
  #1  
Old 10-07-2015, 03:03 AM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,795
Default Paddle & Ball Algorithm Advice


First this is an Android/Java app I'm creating(this is my favourite coding site so that's why I've posted it here), I know this has been done many times over the years but I thought it would be nice to have a go at a game, I've created the Map editor in .NET so I can create the classic map easily, it is working fine on a device I just wanted some advice on the paddle and ball algorithm, the hit collision is fine, but I was want a nice algorithm when the ball hits the paddle to bounce off

I've seen different examples but what some do is the following:

half/quarter the width of the paddle and give each half/quarter section a static degree/radian.

I'm no mathematical god, so I have to code the algorithm the easy way unless I can understand what is going on

This is my idea but I'm not sure if its good or will work correctly.

My idea is to have the ball fly off, at an angle that is a percentage(converted to degrees later) of the width of the paddle. so here goes

A half circle(remember 0 starts in the east not the north) from degrees 180 to 360.

Java uses Rect but the Width/Height as .Net knows it are absolute positions so that's why I've done it like that below.

So the Paddle Rect is: (352(x1), 300(y1), 352(x1)+250(w), 300(y1)+50(h))

PaddleWidth: (x2 - x1) = 250

BallLeft: = 530

Result: (BallLeft - x1) = 178

OnePercent: (100 / PaddleWidth) = 0.4

Percentage: (OnePercent * Result) = 71.2

180 = start of the half circle.

OneDegree: (180 / 100) = 1.8

SubDegree: (OneDegree * Percentage) = 128.16 degrees

TotalDegrees: (180 + SubDegree) = 308.16 degrees

so that will give me the position that the ball should fly off too.

How does this look?
Reply With Quote
  #2  
Old 10-08-2015, 06:39 AM
Cerian Knight's Avatar
Cerian KnightPaddle & Ball Algorithm Advice Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

See this thread containing a few code examples:
brick breaker game
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
Reply

Tags
paddle, ball, algorithm, degrees, .net, half/quarter, onepercent, map, result, ballleft, paddlewidth, width, fly, rect, fine, percentage, half, idea, advice, subdegree, nice, onedegree, percentageconverted, width/height, angle


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
 
Paddle & Ball Algorithm Advice
Paddle & Ball Algorithm Advice
 
-->