
-----------------------------------
Homer_simpson
Sat Jan 10, 2004 4:26 pm

that volleyball game that dude wanted...
-----------------------------------
beat the comp... if u can  :P 
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 zx, zy := -100.0
procedure AI (var player : player_t, projectile : projectile_t, t : real)
    var sl : real := 0
    var dy := ((projectile.velocity * sind (projectile.angle) * (t + 2) - (projectile.weight) * (t + 3) ** 2 / 2) + projectile.starty)
    var dx := ((projectile.velocity * cosd (projectile.angle) * (t + 2)) + projectile.startx)
    /*if dy > 95 and dy < 105 then
     zx := dx
     zy := dy
     end if%*/
    %drawline (round (projectile.x), round (projectile.y), round (dx), round (dy), 4)
    /*if player.x < projectile.x + 10 then
     player.x += 2
     elsif player.x > projectile.x + 10 and player.x > 350 then
     player.x -= 2
     end if%*/
    if zx not= -100 then
        if player.x < zx then
            player.x += 2
        elsif player.x > zx and player.x > 350 then
            player.x -= 2
        end if
        drawfilloval (round (zx), round (zy), 5, 5, 3)
    else
        if player.x < dx then
            player.x += 2
        elsif player.x > dx and player.x > 350 then
            player.x -= 2
        end if
    end if
end AI

procedure cleanAI (var player : player_t, projectile : projectile_t, t : real)
    var sl : real := 0
    var dy := ((projectile.velocity * sind (projectile.angle) * (t + 2) - (projectile.weight) * (t + 3) ** 2 / 2) + projectile.starty)
    var dx := ((projectile.velocity * cosd (projectile.angle) * (t + 2)) + projectile.startx)
    %drawline (round (projectile.x), round (projectile.y), round (dx), round (dy), black)
    if zx not= -100 then
        drawfilloval (round (zx), round (zy), 5, 5, 3)
    end if
end cleanAI

var projectile_1 : projectile_t
var player_1, player_2 : player_t
var score1, score2 := 0
player_1.x := 100
player_1.y := 100
player_1.v := 50
player_1.w := 10
player_1.t := 0

player_2.x := 540
player_2.y := 100
player_2.v := 50
player_2.w := 10
player_2.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)
    zx := -100
    zy := -100
    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
        if projectile_1.x < 320 then
            score2 += 1
        else
            score1 += 1
        end if
        zx := -100
        zy := -100
        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, 1, projectile_1.y, round (projectile_1.velocity / 1.7), projectile_1.angle - 90, projectile_1.weight)
        time1 := 0
    end if
    if projectile_1.x > 639 then
        ResetP (projectile_1, 639, projectile_1.y, round (projectile_1.velocity / 1.7), 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 (80), 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 (80), 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 (80), 90, projectile_1.weight)
        end if
        time1 := 0
    end if

    if distance (player_2.x, player_2.y, projectile_1.x, projectile_1.y) < 40 then
        if projectile_1.x not= player_2.x then
            locate (1, 1)
            if arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)) < 0 then
                ResetP (projectile_1, projectile_1.x, projectile_1.y, round (80), 180 + arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)),
                    projectile_1.weight)
            else
                ResetP (projectile_1, projectile_1.x, projectile_1.y, round (80), arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)), projectile_1.weight)
            end if
        else
            ResetP (projectile_1, projectile_1.x, projectile_1.y, round (80), 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
    AI (player_2, projectile_1, time1)
    Input.KeyDown (chars)
    if chars ('w') then
        bjump_1 := true
    end if
    if chars ('a') then
        player_1.x -= 2
    end if
    if chars ('d') then
        player_1.x += 2
    end if
    if chars ('q') then
        exit
    end if
    locate (1, 35)
    put score1, "/", score2
    drawline (320, 100, 320, 200, yellow)
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, 9)
    drawfilloval (round (player_2.x), round (player_2.y), 30, 30, 11)
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, 12)
    drawfillbox (0, 0, 640, 100, 10)
    View.Update
    delay (10)
    cleanAI (player_2, projectile_1, time1)
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, black)
    drawfilloval (round (player_2.x), round (player_2.y), 30, 30, black)
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, black)
    drawline (320, 100, 320, 200, black)
end loop

-----------------------------------
santabruzer
Sat Jan 10, 2004 4:30 pm


-----------------------------------
it's pretty buggy though.. for some reason i score like 2 points, and it totally removed them from the count.. plus you can go over the line.. or the net.. shouldn't be able to do that.. and why don't you do it with an arc like in the original version?

But either than that.. it's perfect!  :P

-----------------------------------
AsianSensation
Sat Jan 10, 2004 5:51 pm


-----------------------------------
very very nice, me and SilverSprite was about to do something like that for one of our project, but we got side-tracked with raycasting, so here are bits for something we were "suppose" to do  :P 

+ bits

-----------------------------------
Homer_simpson
Sat Jan 10, 2004 7:01 pm


-----------------------------------
it's pretty buggy though.. for some reason i score like 2 points, and it totally removed them from the count.. plus you can go over the line.. or the net.. shouldn't be able to do that.. and why don't you do it with an arc like in the original version?

But either than that.. it's perfect!  :P
lol... i know and sometimes ball gets stuck on the net or goes thru it... it's easy to fix but i just got bored after making the ai...

-----------------------------------
Andy
Sat Jan 10, 2004 8:02 pm


-----------------------------------
the ball went through the net...

-----------------------------------
CITC
Sat Jan 10, 2004 11:28 pm


-----------------------------------
wahoo I'm that dude :D

I really hate the way the ball bounces off the wall. It bounces as though it has a spin on it. I've been trying like mad to fix it, and have come up with a formula to use to figure out the proper angle of reflection.

a (initial angle)
ra (reflected angle)
ra = 360 - (90 - (a - 180) )       0 ) but when it is on the last leg of the arc it is coming down yet projectile_1.angle is still some upwards angle.  This means that the formula for the reflected angle off of a straight line is useless unless projectile_1.angle is accurate just before it hits the wall or the net.  

I can't find any way to get an accurate value of projectile_1.angle just before it hits the wall (or at any time when it isn't bouncing off of a player / wall / net).  Get me that and I can make it bounce true.

-----------------------------------
Homer_simpson
Sun Jan 11, 2004 2:48 am


-----------------------------------
no man... projectile.angle is the initial angle the projectile's thrown at...

so here's what u gotto do on collision with wall... u reset the startx and start y to the collision position reser the velocity if u want and change the angle and set the time to 0...

-----------------------------------
poly
Sun Jan 11, 2004 11:13 am


-----------------------------------
hey look I can go over to the opponents side (right threw the net).... That is very good and fun

-----------------------------------
PaddyLong
Sun Jan 11, 2004 1:04 pm


-----------------------------------
wicked game

-----------------------------------
Maverick
Sun Jan 11, 2004 3:10 pm


-----------------------------------
When the ball hits the comps ground sometimes he doesnt lose. The comp kinda sucks, but good for winoot!
GJ Homer!

-----------------------------------
CITC
Sun Jan 11, 2004 5:33 pm


-----------------------------------
I'm gunna try a few more things, I'll post in a few hours my thoughts.

-----------------------------------
ruff_riders91
Mon Jan 12, 2004 10:20 am


-----------------------------------
does the computer jump at all i haven't seen him jump

-----------------------------------
shorthair
Mon Jan 12, 2004 10:45 am


-----------------------------------
All you have to do is lok through the code for the answer , i mean you are in grade 11 computer science

-----------------------------------
McKenzie
Mon Jan 12, 2004 11:36 am


-----------------------------------
I always wondered what VB Mod stood for... VolleyBall Mod. Great game, lots of potential... imagine 2 players per side over the Internet perhaps???

P.S. Remind me to give Derek a high mark in EVERYTHING.

-----------------------------------
Homer_simpson
Mon Jan 12, 2004 4:35 pm


-----------------------------------
8)  :D 
does the computer jump at all i haven't seen him jump
nah he was doing good with out  jumping, so i just left it be...
and yes you can hit the ball off the ground... in fact u can hit it till it completely stops...

-----------------------------------
Cervantes
Mon Jan 12, 2004 5:38 pm


-----------------------------------
gah I can't do it  :(

-----------------------------------
DanShadow
Mon Jan 12, 2004 7:58 pm


-----------------------------------
That is nice! I never let the opponent have the ball, I hopped over the net, grabbed the ball, and spiked it down by going on top of it, lol. But that is seriously a great game!

-----------------------------------
agent_orange444
Thu Jan 22, 2004 6:35 pm


-----------------------------------
Nice job on the game.  Bye the way the correct name is slime volleyball.  It does need a bit of minor tweaking though.

-----------------------------------
kalin
Thu Jan 22, 2004 6:47 pm


-----------------------------------
cool. I like it

-----------------------------------
Cervantes
Thu Jan 22, 2004 7:06 pm


-----------------------------------
Homer the thing is you can do what you said about changing the velocity and resetting startx and starty and all but you can't change the angle to what it should be because in order to do that, you have to know its current angle (right before it hits the wall).

-----------------------------------
Cervantes
Thu Jan 22, 2004 8:03 pm


-----------------------------------
ahah I did it!  well it still bounces slightly wierd... maybe I can iron that out... but here's my version of Homer's game

View.Set ("position:centre;centre,graphics:640;500,offscreenonly")
colorback (black)
cls
var score1 : int := 0
var score2 : int := 0
var time2 := 0

var chars : array char of boolean
type projectile_t :
    record
        startx, starty, x, xp, y, yp, 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
var player_2 : player_t

player_1.x := 100
player_1.y := 100
player_1.v := 50
player_1.w := 10
player_1.t := 0

player_2.x := maxx - 100
player_2.y := 100
player_2.v := 50
player_2.w := 10
player_2.t := 0

projectile_1.startx := 100
projectile_1.starty := 140
projectile_1.x := 100
projectile_1.y := 140
projectile_1.velocity := 90
projectile_1.angle := 90
projectile_1.weight := 15
var time1 := 0.0
var bjump_1 := false
var bjump_2 := false

var currentangle : real
var slope : real
var bounceangle : real

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
    if projectile_1.starty > 110 then
        time1 += .105
    else
        if projectile_1.x < 320 then
            score2 += 1
        elsif projectile_1.x > 320 then
            score1 += 1
        end if
        player_1.x := 100
        player_1.y := 100
        player_1.v := 50
        player_1.w := 10
        player_1.t := 0
        player_2.x := maxx - 100
        player_2.y := 100
        player_2.v := 50
        player_2.w := 10
        player_2.t := 0
        projectile_1.startx := 100
        projectile_1.starty := 140
        projectile_1.velocity := 90
        projectile_1.angle := 90
        projectile_1.weight := 15
        time1 := 0.0
        delay (200)
    end if
    %end if
    projectile_1.xp := projectile_1.x
    projectile_1.yp := projectile_1.y
    Projectile (projectile_1, time1)
    if projectile_1.y not= projectile_1.yp and projectile_1.x not= projectile_1.xp then
        slope := (projectile_1.y - projectile_1.yp) / (projectile_1.x - projectile_1.xp)
        currentangle := arctand (slope)
        bounceangle := -currentangle
        locate (3, 2)
        put "Angle : ", currentangle
    end if

    if projectile_1.y < 105 then     %Ball hits ground
        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     %Ball hits left wall
        ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 1.3), bounceangle, projectile_1.weight)
        time1 := 0
    end if
    if projectile_1.x > 639 then     %Ball hits right wall
        ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 1.3), bounceangle, projectile_1.weight)
        projectile_1.angle += 180
        time1 := 0
    end if

    if projectile_1.y < 160 then     %ball lower than top of net
        if projectile_1.x > 310 and projectile_1.x < 320 then     %Ball hits left side of net
            ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), bounceangle, projectile_1.weight)
            time1 := 0
        end if

        if projectile_1.x < 330 and projectile_1.x > 320 then     %Ball hits right side of net
            ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), bounceangle, projectile_1.weight)
            projectile_1.angle += 180
            time1 := 0
        end if
    end if

    if Math.Distance (player_1.x, player_1.y, projectile_1.x, projectile_1.y) < 40 then     %Bouncing ball off Player 1
        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 Math.Distance (player_2.x, player_2.y, projectile_1.x, projectile_1.y) < 40 then     %Bouncing ball off Player 2
        if projectile_1.x not= player_2.x then
            locate (1, 1)
            if arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)) < 0 then
                ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), 180 + arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)),
                    projectile_1.weight)
            else
                ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.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
    %%%%Player Boundaries%%%
    if player_1.x < 30 then     %Player 1 Wall
        player_1.x := 30
    end if
    if player_1.x > 290 then     %Player 1 Net
        player_1.x := 290
    end if
    if player_2.x < 350 then     %Player 2 Net
        player_2.x := 350
    end if
    if player_2.x > 610 then     %Player 2 Wall
        player_2.x := 610
    end if

    if bjump_1 then     %Jumping of Player 1
        Jump (player_1)
        if player_1.y < 100 then
            bjump_1 := false
            player_1.t := 0
            player_1.y := 100
        end if
    end if

    if bjump_2 then     %Jumping of Player 2
        Jump (player_2)
        if player_2.y < 100 then
            bjump_2 := false
            player_2.t := 0
            player_2.y := 100
        end if
    end if

    Input.KeyDown (chars)
    %Player1 Controls
    if chars ('w') then
        bjump_1 := true
    end if
    if chars ('a') then
        player_1.x -= 3
    end if
    if chars ('d') then
        player_1.x += 3
    end if
    %Player2 Controls
    if chars (KEY_UP_ARROW) then
        bjump_2 := true
    end if
    if chars (KEY_LEFT_ARROW) then
        player_2.x -= 3
    end if
    if chars (KEY_RIGHT_ARROW) then
        player_2.x += 3
    end if

    drawline (320, 100, 320, 150, yellow)     % net
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, 9)     % player 1
    drawfilloval (round (player_2.x), round (player_2.y), 30, 30, 42)     % player 2
    drawfillbox (0, 0, 640, 100, 10)     %ground
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, 12)     %ball
    View.Update
    delay (10)
    drawfilloval (round (player_1.x), round (player_1.y), 30, 30, black)     %Player 1 Previously
    drawfilloval (round (player_2.x), round (player_2.y), 30, 30, black)     %Player 2 Previously
    drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, black)     % Ball Previously
    drawline (320, 100, 320, 150, brightred)     %Bright red of net
    /*var mx, my, mbutton : int
     Mouse.Where (mx, my, mbutton)
     locate (1, 1)
     put mx, " - ", my*/
    locate (1, 2)
    put "Score : ", score1
    locate (1, maxcol - 10)
    put "Score : ", score2
end loop

Cheers

-----------------------------------
Homer_simpson
Fri Jan 23, 2004 1:23 am


-----------------------------------
Homer the thing is you can do what you said about changing the velocity and resetting startx and starty and all but you can't change the angle to what it should be because in order to do that, you have to know its current angle (right before it hits the wall).

well u can get the angle on collision by: calculating the tangent to the curve at the last second of the collision...

-----------------------------------
Cervantes
Fri Jan 23, 2004 1:39 pm


-----------------------------------
yeah that's basically what I did.. only using arctand gives me a result with 90 being up and -90 being down... slightly different, still works though.

-----------------------------------
valor
Wed Mar 24, 2004 10:38 pm


-----------------------------------
cool. it has a few glitches in it that could probably be fixed if you put time into it but it is pretty nice umm im just wondering what does the score go up to? because i got like around 40

-----------------------------------
WhatAmIDoing
Thu Mar 25, 2004 12:24 pm


-----------------------------------
Cervantes what version of turing did you use because when i tried to run it i got Distance is not in the export list of math.

-----------------------------------
shorthair
Thu Mar 25, 2004 4:25 pm


-----------------------------------
leave old topic old , go ahead and look at em and get the files , BUT  dont post in them , there are enoug hactive posts to post in , its irritation to see old posts come back up

-----------------------------------
Cervantes
Thu Mar 25, 2004 5:06 pm


-----------------------------------
indeed :lol: two months old :P

I'm using Turing 4.0.5.  You get that error because Math.Distance is not in anything before 4.0.3.  You can fix it easily enough by making a variable called distance and using the distance formula.

-----------------------------------
the_short1
Fri Mar 26, 2004 6:00 pm


-----------------------------------
the first thing everyone should do in a program is do:

View.Set ("graphics:size;size,title:some name,nobuttonbar") 