
-----------------------------------
thainfamous
Sat Nov 27, 2004 1:04 pm

Need help with my slime volley ball
-----------------------------------
i need help with the ball and how to implement it, and im looking for suggestions or a code from someone that would work for my program. Well this is what i have so far, thx.

var winID := Window.Open ("graphics:720,400")
var Chars : array char of boolean
var jumpallowed : array 1 .. 2 of int := init (0, 0)
type Player :
    record
        x : real
        y : real
        team : string
        name : string
        clr : int
        dirx : string
        diry : string
    end record


fcn CreatePlayer (x, y : real, team, name : string, clr : int) : Player
    var temp_plyr : Player
    temp_plyr.x := x
    temp_plyr.y := y
    temp_plyr.team := team
    temp_plyr.name := name
    temp_plyr.clr := clr
    temp_plyr.dirx := "none"
    temp_plyr.diry := "none"
    result temp_plyr
end CreatePlayer

var plyrs : array 1 .. 2 of Player
plyrs (1) := CreatePlayer (50, 0, "team 1", "Bob", red)
plyrs (2) := CreatePlayer (550, 0, "team 2", "Joe", blue)

loop
    Time.Delay (10)
    for i2 : 1 .. 2
        if plyrs (i2).dirx = "right" then
            plyrs (i2).x += 2
        elsif plyrs (i2).dirx = "left" then
            plyrs (i2).x -= 2
        end if
        if plyrs (i2).diry = "jump" and jumpallowed (i2) = 0 then
            jumpallowed (i2) := 100
        end if
        if plyrs (i2).diry = "jump" and jumpallowed (i2) > 0 then
            if jumpallowed (i2) > 50 then
                plyrs (i2).y += 2
                jumpallowed (i2) -= 2
            end if
            if jumpallowed (i2) < 51 then
                plyrs (i2).y -= 2
                jumpallowed (i2) -= 2
            end if
            if jumpallowed (i2) = 0 then
                plyrs (i2).diry := "none"
            end if
        end if
    end for
    Draw.ThickLine (360, 0, 360, 50, 3, red)
    Pic.ScreenLoad ("black.jpg", round (plyrs (1).x), round (plyrs (1).y), picCopy)
    Pic.ScreenLoad ("black.jpg", round (plyrs (2).x), round (plyrs (2).y), picCopy)
    Input.KeyDown (Chars)
    if Chars (KEY_RIGHT_ARROW) then
        plyrs (1).dirx := "right"
    elsif Chars (KEY_LEFT_ARROW) then
        plyrs (1).dirx := "left"
    else
        plyrs (1).dirx := "none"
    end if
    if Chars (KEY_UP_ARROW) then
        plyrs (1).diry := "jump"
    end if
    if Chars ('d') then
        plyrs (2).dirx := "right"
    elsif Chars ('a') then
        plyrs (2).dirx := "left"
    else
        plyrs (2).dirx := "none"
    end if
    if Chars ('w') then
        plyrs (2).diry := "jump"
    end if
    if Chars (KEY_ESC) then
        Window.Close (winID)
        exit
    end if
    View.Update
end loop



-----------------------------------
Cervantes
Sat Nov 27, 2004 1:47 pm


-----------------------------------
What do you mean "i need help with the ball and how to impliment it"?
Do you mean, [url=http://www.compsci.ca/v2/viewtopic.php?t=5246]Circular Collision Data?

-----------------------------------
thainfamous
Sat Nov 27, 2004 4:54 pm


-----------------------------------
well, if u run my code i want to make  a ball for the volleyball and i dont know how, and i was looking for help or a source code

-----------------------------------
Cervantes
Sat Nov 27, 2004 5:52 pm


-----------------------------------
okay... well, what don't you understand about how to make a ball?
you are using records.  Well done.  Let's use a record for our ball:


var ball :
    record
        x, y, vx, vy : real
        radius, clr : int
    end record


There's your ball.  
Now, to apply gravity to it:


var ball :
    record
        x, y, vx, vy : real
        radius, clr : int
    end record

ball.x := 10
ball.y := 10
ball.vx := 3
ball.vy := 4
ball.radius := 6
ball.clr := brightblue

const gravity := 0.05
setscreen ("offscreenonly")
loop
    ball.vy -= gravity
    ball.x += ball.vx
    ball.y += ball.vy

    cls
    drawfilloval (round (ball.x), round (ball.y), ball.radius, ball.radius, ball.clr)
    View.Update
    delay (10)
end loop


Now, to make it bounce off a wall:

    if ball.x + ball.radius >= maxx or ball.x - ball.radius 