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

Username:   Password: 
 RegisterRegister   
 Bouncing a ball off a semi-circle ??
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CITC




PostPosted: Tue Jan 06, 2004 8:41 pm   Post subject: Bouncing a ball off a semi-circle ??

Hi everyone, first before I ask my question I'd like to say what an AMAZING site this is... truly INCREDIBLE!!!!!!!!!

k, with that being said, I'd like to make a turing version of a game I found on www.addictinggames.com called Slime Volleyball. If you haven't played it you can check it out here
http://tartarus.uwa.edu.au/%7Ewedgey/slime1/
the biggest problem I have with making this game is that in the game the players are semi-circles (slimes) and the ball bounces off of these semi circles, reflecting appropriately. I've thought and thought about this, but can't figure out how to do it. Anyone know how?

Thanks in advance!!
CITC
Sponsor
Sponsor
Sponsor
sponsor
Maverick




PostPosted: Tue Jan 06, 2004 8:47 pm   Post subject: (No subject)

Slime volleyball kinda sux, you shuld make slime soccer.
I think I know where to get the code for that bouncing thing.
I'll post in a day or two.
AsianSensation




PostPosted: Tue Jan 06, 2004 9:10 pm   Post subject: (No subject)

you kinda have to know a bit of physics or at least some math to be able to do this. Tell me what you know about projectiles or parabolas so I can help you out.
shorthair




PostPosted: Wed Jan 07, 2004 11:51 am   Post subject: (No subject)

the cheesy way out if you dont know alot about math and physics, is to make arbitraraly mabye 10 different angles so if the ballx = slimex or ballx = slimex + 10 then ........ make your angles , but asian is right there is a proprer way to do it
CITC




PostPosted: Wed Jan 07, 2004 5:00 pm   Post subject: (No subject)

hehe Slime soccer was good too. fortunately if i make slime volleyball i can fairly easily change it to slime soccer Smile

as for the math bit, I'm really good at math and physics, but I'm only in Grade 10 (I've taken Gr 10 science but Gr 10 math is next semester). don't know anything about projectiles or parabalas but tell me and I'll see if i can pick it up. Smile
if i can't, I can go with shorthair's suggestion Smile

oh yeah also I found the code for that game too but it was in Java and totally confused me
Homer_simpson




PostPosted: Wed Jan 07, 2004 8:40 pm   Post subject: (No subject)

that's not a bad game... i kinda like the idea...it's creative and everything, it's actually a good idea to hand in something like that for yer fp...


Any way if u wanna learn to do that... check out my tutorial on projectile physics... basically all u need is the velocity and the angle the ball hit's the player at...
Homer_simpson




PostPosted: Wed Jan 07, 2004 10:01 pm   Post subject: (No subject)

in fact i liked the simplicity of the idea so much... i'll give u something to start with...
code:
View.Set ("offscreenonly")
colorback (black)
cls
var time2 := 0

function distance (x1, y1, x2, y2 : real) : real
    result (((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5)
end distance


var chars : array char of boolean
type projectile_t :
    record
        startx, starty, x, y, angle, weight, velocity : real
    end record

type player_t :
    record
        x, y, w, v, t : real
    end record

var projectile_1 : projectile_t
var player_1 : player_t

player_1.x := 100
player_1.y := 100
player_1.v := 50
player_1.w := 10
player_1.t := 0

projectile_1.startx := 100
projectile_1.starty := 140
projectile_1.velocity := 80
projectile_1.angle := 90
projectile_1.weight := 10
var time1 := 0.0
var bjump_1 := false

procedure Projectile (var obj : projectile_t, t : real)
    obj.x := (obj.velocity * cosd (obj.angle) * t) + obj.startx
    obj.y := (obj.velocity * sind (obj.angle) * t - (obj.weight) * t ** 2 / 2) + obj.starty
end Projectile

procedure Jump (var obj : player_t)
    obj.y := (obj.v * sind (90) * obj.t - (obj.w) * obj.t ** 2 / 2) + 100
    obj.t += .1
end Jump

procedure ResetP (var obj : projectile_t, sx, sy, v, a, w : real)
    projectile_1.startx := sx
    projectile_1.starty := sy
    projectile_1.velocity := v
    projectile_1.angle := a
    projectile_1.weight := w
end ResetP
color (10)
loop
    if round (projectile_1.velocity) > 1 then
        time1 += .1
    else
        player_1.x := 100
        player_1.y := 100
        player_1.v := 50
        player_1.w := 10
        player_1.t := 0
        projectile_1.startx := 100
        projectile_1.starty := 140
        projectile_1.velocity := 80
        projectile_1.angle := 90
        projectile_1.weight := 10
        time1 := 0.0
        locate (10, 10)
        put "eeeshta!"
        cls
        delay (200)
    end if
    Projectile (projectile_1, time1)

    if projectile_1.y < 105 then
        ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 2), projectile_1.angle, projectile_1.weight)
        time1 := 0
    end if

    if projectile_1.x < 1 then
        ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 1.3), projectile_1.angle - 90, projectile_1.weight)
        time1 := 0
    end if
    if projectile_1.x > 639 then
        ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 1.3), projectile_1.angle + 90, projectile_1.weight)
        time1 := 0
    end if

    if projectile_1.y < 210 then
        if projectile_1.x > 310 and projectile_1.x < 320 then
            ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), projectile_1.angle - 90, projectile_1.weight)
            time1 := 0
        end if

        if projectile_1.x < 330 and projectile_1.x > 320 then
            ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), projectile_1.angle + 90, projectile_1.weight)
            time1 := 0
        end if

    end if

    if distance (player_1.x, player_1.y, projectile_1.x, projectile_1.y) < 40 then
        if projectile_1.x not= player_1.x then
            locate (1, 1)
            if arctand ((projectile_1.y - player_1.y) / (projectile_1.x - player_1.x)) < 0 then
                ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), 180 + arctand ((projectile_1.y - player_1.y) / (projectile_1.x - player_1.x)), projectile_1.weight)
            else
                ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), arctand ((projectile_1.y - player_1.y) / (projectile_1.x - player_1.x)), projectile_1.weight)
            end if
        else
            ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), 90, projectile_1.weight)
        end if
        time1 := 0
    end if

    if bjump_1 then
        Jump (player_1)
        if player_1.y < 100 then
            bjump_1 := false
            player_1.t := 0
            player_1.y := 100
        end if
    end if

    Input.KeyDown (chars)
    if chars ('w') then
        bjump_1 := true
    end if
    if chars ('a') then
        player_1.x -= 1
    end if
    if chars ('d') then
        player_1.x += 1
    end if

    drawline (320, 100, 320, 200, yellow)
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, 9)
    drawfillbox (0, 0, 640, 100, 10)
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, 12)
    View.Update
    delay (10)
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, black)
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, black)
    drawline (320, 100, 320, 200, black)
end loop
CITC




PostPosted: Thu Jan 08, 2004 7:53 pm   Post subject: (No subject)

wow thanks for that code! I haven't read through much of it yet but from running it in turing it looks like there isn't much else to do.

did you just make this now or was this a slightly altered part of your tutorial that you mentioned? Also, where can I look at this tutorial?
Sponsor
Sponsor
Sponsor
sponsor
Homer_simpson




PostPosted: Fri Jan 09, 2004 12:16 am   Post subject: (No subject)

well i didn't rewrite parts of the code i already had... Rolling Eyes
CITC




PostPosted: Sat Jan 10, 2004 11:36 am   Post subject: (No subject)

I've been working on the game and I've added the second player and made the ball bounce off him the same as it does off player 1.

the thing I don't get is why does the ball bounce oddly off of the walls and net? It bounces as though it had either a topspin or a backspin (its not just reflected, it will sometimes shoot quickly down or other times shoot pretty horizontally across the screen). I've been playing around with it but can't find any way to fix it.
CITC




PostPosted: Sat Jan 10, 2004 12:40 pm   Post subject: (No subject)

oh and theres one other kinda quirky thing.. sometimes the ball goes inside the slimes and bounces around for a half second or so building up velocity, then shoots out in some wierd direction.

I think I might be able to fix these things if I could understand the ResetP procedure. What are sx,sy,v,a, and w. I understand what they stand for, but when were they created and what are their values?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: