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

Username:   Password: 
 RegisterRegister   
 that volleyball game that dude wanted...
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Sat Jan 10, 2004 4:26 pm   Post subject: that volleyball game that dude wanted...

beat the comp... if u can Razz
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 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
Sponsor
Sponsor
Sponsor
sponsor
santabruzer




PostPosted: Sat Jan 10, 2004 4:30 pm   Post subject: (No subject)

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! Razz
AsianSensation




PostPosted: Sat Jan 10, 2004 5:51 pm   Post subject: (No subject)

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 Razz

+ bits
Homer_simpson




PostPosted: Sat Jan 10, 2004 7:01 pm   Post subject: (No subject)

santabruzer wrote:
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! Razz

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




PostPosted: Sat Jan 10, 2004 8:02 pm   Post subject: (No subject)

the ball went through the net...
CITC




PostPosted: Sat Jan 10, 2004 11:28 pm   Post subject: (No subject)

wahoo I'm that dude Very Happy

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) ) <--- this works for the right wall, its slightly different for the left wall

Thing is, in your program, projectile_1.angle (what I referred to as a) only changes its value upon contact with a player, the wall, or the net (ie. whenever the ResetP procedure is called). This means that if the ball travells in an arc then projectile_1.angle will be some angle up ( < 180 and > 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




PostPosted: Sun Jan 11, 2004 2:48 am   Post subject: (No subject)

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




PostPosted: Sun Jan 11, 2004 11:13 am   Post subject: (No subject)

hey look I can go over to the opponents side (right threw the net).... That is very good and fun
PaddyLong




PostPosted: Sun Jan 11, 2004 1:04 pm   Post subject: (No subject)

wicked game
Maverick




PostPosted: Sun Jan 11, 2004 3:10 pm   Post subject: (No subject)

When the ball hits the comps ground sometimes he doesnt lose. The comp kinda sucks, but good for winoot!
GJ Homer!
CITC




PostPosted: Sun Jan 11, 2004 5:33 pm   Post subject: (No subject)

I'm gunna try a few more things, I'll post in a few hours my thoughts.
ruff_riders91




PostPosted: Mon Jan 12, 2004 10:20 am   Post subject: (No subject)

does the computer jump at all i haven't seen him jump
shorthair




PostPosted: Mon Jan 12, 2004 10:45 am   Post subject: (No subject)

All you have to do is lok through the code for the answer , i mean you are in grade 11 computer science
McKenzie




PostPosted: Mon Jan 12, 2004 11:36 am   Post subject: (No subject)

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




PostPosted: Mon Jan 12, 2004 4:35 pm   Post subject: (No subject)

8) Very Happy
ruff_riders91 wrote:
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...
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 3  [ 32 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: