Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Circular Pong
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
iker




PostPosted: Tue Jan 03, 2006 3:30 pm   Post subject: Circular Pong

I'm currently working on a pong type single player game, and I need to figure out how to detect a collision along the whole paddle, or on the ball. I want it so that if you hit the left side of the paddle, the ball goes left, and if it hits the right side, it goes right, but also taking in to consideration the direction before. So say if the ball comes in at speed 2 from the left, and it hits the right side of the paddle, that adds a speed of 1 to the right.

Any comments will help too, but for the most part I just need to know what type of collision would be best.

Controls
left/right:move paddle
enter:start ball
esc:quit game(also frees all the pics to gain back that lost memory...)



plong.rar
 Description:
sry its a winrar file, but .zip would be to big

Download
 Filename:  plong.rar
 Filesize:  511.2 KB
 Downloaded:  222 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Tue Jan 03, 2006 5:54 pm   Post subject: (No subject)

Here! Very Happy
iker




PostPosted: Tue Jan 03, 2006 6:43 pm   Post subject: (No subject)

Thnx, but I already know basic collision detection, and I've worked out a way, but its going to take a while. Anyways, be back soon with a finished first version.
iker




PostPosted: Wed Jan 04, 2006 2:14 pm   Post subject: (No subject)

I completed the first version, and It works perfectly fine, except a few minor glitches here and there, none that realy effect gameplay. Anyways, same controls as before, and I added a 'debug' mode where it shows you how the game works... sort of. During the game press alt + d and it will go into debug mode, same to get out. I completely changed the type of ball movement from before, now using sin and cos. There are three detections along each paddle. If the ball hits the center, 180degrees are added to the balls movement, sending it strait back, if it hits the left, something like 145 and the right, 215.

Comments and suggestions would be greatly appreciated.

Controls
move: left/right arrows
start: enter
quit: esc
cool dude




PostPosted: Wed Jan 04, 2006 2:55 pm   Post subject: (No subject)

do u mind attaching it as a zip so i can see it, it looks interesting. if u can't then can u just email it to me please. thanks
iker




PostPosted: Thu Jan 05, 2006 12:16 am   Post subject: (No subject)

No problem, I had/have to upload a new one with a score counter that actualy works, and i fixed a 'glitch' where the ball will now reset when you exit and start again, instead of staying in the same spot. Deleated the second one because this one isn't much of an update, except for those two minor things.


plong.zip
 Description:
plong with least amount of glitches... and its .ZIP!

Download
 Filename:  plong.zip
 Filesize:  763.52 KB
 Downloaded:  540 Time(s)

iker




PostPosted: Thu Jan 05, 2006 8:48 pm   Post subject: (No subject)

I actualy just thought of this, can someone move this to the app page, because I don't need help nemore, and its an app, and i don't feel like making a new topic...
Cervantes




PostPosted: Thu Jan 05, 2006 10:03 pm   Post subject: (No subject)

iker wrote:
can someone move this to the app page

Certainly. Smile

Pretty good game. I like the concept. The collisions could use some work, however; sometimes the ball will hit the right side of the paddle, and yet it will be pushed to the left, to which it bounces off the same paddle again and again...

+10 bits
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Mon Jan 16, 2006 4:38 pm   Post subject: (No subject)

i found that the ball will sometimes "stick" to the paddle making uber points for the player and sometimes the ball doesnt quite bounce the right way but otherwise its great gj
GlobeTrotter




PostPosted: Mon Jan 16, 2006 7:09 pm   Post subject: (No subject)

I had tried making a game similar to this. I kind of gave up on it, anyone who wants to can continue it. I found a fundamental flaw with the game. If the ball starts in the centre, and travels in a random direction, it will always just travel in along a straight line. I also could not quite figure out how to make the collisions properly. There are the very beginnings of bricks for my game too. I never got around to implementing them.

code:

setscreen ("graphics:500;500;offscreenonly")
const RADIUS := maxx div 2
const DIAMETER := maxx
const PADDLE_WIDTH := 36 %In degrees
const PADDLE_THICKNESS := 10
var SIND, COSD : array 0 .. 360 of real

type BallType :
    record
        x : real
        y : real
        dir : int
        speed : real
        radius : int
        col : int
    end record
   
type BrickType :
    record
        Broken : int %0=dead, 1=not dead
        StartAngle : int
        EndAngle2 : int
        SmallRadius : int
        LargeRadius : int
    end record

function find_angle (x1, y1, x2, y2 : int) : real
    if x2 = x1 then
        if y2 >= y1 then
            result 90
        elsif y2 < y1 then
            result 270
        end if
    else
        if x2 > x1 and y2 >= y1 then %QUAD 1
            result (arctand ((y2 - y1) / (x2 - x1)))
        elsif x2 > x1 and y2 < y1 then %QUAD 2
            result 360 + (arctand ((y2 - y1) / (x2 - x1)))
        elsif x2 < x1 and y2 < y1 then %QUAD 3
            result 180 + (arctand ((y2 - y1) / (x2 - x1)))
        elsif x2 < x1 and y2 >= y1 then %QUAD 4
            result 180 + (arctand ((y2 - y1) / (x2 - x1)))
        end if
    end if
end find_angle

proc DrawBackground
    Draw.FillBox (0, 0, DIAMETER, DIAMETER, 7)
    %Draw.FillOval (RADIUS, RADIUS, RADIUS, RADIUS, 0)
    for decreasing i : RADIUS .. 0 by (RADIUS div 10)
        Draw.FillOval (RADIUS, RADIUS, i, i, RGB.AddColor(i/RADIUS,i/RADIUS,i/RADIUS))
    end for
    Draw.Dot(RADIUS, RADIUS,0)
end DrawBackground

proc DrawPaddle (mouse_x, mouse_y : int)
    for i : 0 .. PADDLE_THICKNESS - 1
        Draw.Arc (RADIUS, RADIUS, RADIUS - i, RADIUS - i, round (find_angle (RADIUS, RADIUS, mouse_x, mouse_y) - PADDLE_WIDTH / 2), round (find_angle (RADIUS, RADIUS, mouse_x, mouse_y) + PADDLE_WIDTH
            / 2), 12)
    end for
end DrawPaddle

proc DrawBall (tempball : BallType)
    Draw.FillOval (round (tempball.x), round (tempball.y), round (tempball.radius), round (tempball.radius), tempball.col)
end DrawBall


proc MoveBall (var tempball : BallType)
    tempball.x += COSD (round (tempball.dir)) * tempball.speed
    tempball.y += SIND (round (tempball.dir)) * tempball.speed
end MoveBall


function CheckCollision (tempball : BallType, mouse_x, mouse_y : int) : boolean
    if Math.Distance (RADIUS, RADIUS, tempball.x, tempball.y) >= RADIUS - PADDLE_THICKNESS then
        if round (find_angle (RADIUS, RADIUS, mouse_x, mouse_y) - PADDLE_WIDTH / 2) < find_angle (RADIUS, RADIUS, round(tempball.x), round(tempball.y)) and find_angle (RADIUS, RADIUS, round(tempball.x), round(tempball.y)) < round (find_angle (RADIUS, RADIUS, mouse_x, mouse_y) + PADDLE_WIDTH / 2) then
            result true
        else
            result false
        end if
    else
        result false
    end if
end CheckCollision

function CheckLose (tempball : BallType) : boolean
    if Math.Distance (round(tempball.x),round(tempball.y),RADIUS,RADIUS) > RADIUS + tempball.speed then
        result true
    else
        result false
    end if
end CheckLose

%%NEED TO FIX%%%%%%%%%%%%%%%%%%
proc BounceBall (var tempball : BallType)
    var angTangent := round(find_angle (RADIUS, RADIUS, round(tempball.x), round(tempball.y)) + 180) mod 360
    tempball.dir := (tempball.dir + angTangent * 2) mod 360
end BounceBall
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i : 0 .. 360
    SIND (i) := sind (i)
    COSD (i) := cosd (i)
end for



%%%%%%%%%%%%%%% Program Starts %%%%%%%%%%%%%%%%%

var mx, my, mb : int
var ball : BallType
var collided : boolean := false
var reboundcount : int := 0


ball.x := RADIUS
ball.y := RADIUS
ball.speed := 1
ball.dir := Rand.Int (0, 359)
ball.radius := 4
ball.col := yellow
loop
    cls
    Mouse.Where (mx, my, mb)
   
    MoveBall (ball)
    if CheckCollision (ball, mx, my) and ~ collided then
        BounceBall (ball)
        collided := true
        reboundcount := ceil(ball.speed * 2)
    end if
   
    if collided then
        if reboundcount > 0 then
            reboundcount -= 1
        else
            collided := false
        end if
    end if

    DrawBackground
    DrawPaddle (mx, my)
    DrawBall (ball)
    View.Update
    exit when CheckLose(ball)
end loop
iker




PostPosted: Mon Jan 16, 2006 7:17 pm   Post subject: (No subject)

Too bad I don't have the new turing or a math predef in my version of turing or else i would check that out for sure
Delos




PostPosted: Mon Jan 16, 2006 7:23 pm   Post subject: (No subject)

Not having those predefs is not a problem. Just make your own and change the code a little. After all, all that Math.Distance() is is Pythagorus' Theorem.
iker




PostPosted: Mon Jan 16, 2006 7:27 pm   Post subject: (No subject)

Delos wrote:
Not having those predefs is not a problem. Just make your own and change the code a little. After all, all that Math.Distance() is is Pythagorus' Theorem.


I would, but I don't know what each part is in the
Math.Distance (a, b, c, d)
where as I do not know what a b c and d are supposed to be

is it Math.Distance (x1, y1, x2, y2)?
Cervantes




PostPosted: Mon Jan 16, 2006 8:29 pm   Post subject: (No subject)

That is correct.
Read up on extending turing
codemage




PostPosted: Tue Jan 17, 2006 1:21 pm   Post subject: (No subject)

Perhaps instead of 3 zones on the paddle, you could scale the angle of deflection more smoothly.

If your deflection is between 145 to 215,

Angle of deflection =
145 degs + (70 degrees * Percent of the way down the paddle)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: