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

Username:   Password: 
 RegisterRegister   
 Pure Slime Volleyball
Index -> Programming, Turing -> Turing Submissions
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neo




PostPosted: Thu Dec 02, 2004 5:06 pm   Post subject: (No subject)

can u post the source so we can learn from it? or post some example code.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Dec 02, 2004 6:20 pm   Post subject: (No subject)

I posted it as a .exe because I may use this as my FP for next semester. I suppose I could post some example code, however. What would you like to see?
Carino




PostPosted: Thu Dec 02, 2004 6:22 pm   Post subject: (No subject)

Collision detection!!! heh heh heh Twisted Evil
Cervantes




PostPosted: Thu Dec 02, 2004 6:37 pm   Post subject: (No subject)

Already done.

code:

    %PLAYER 1
    if Math.Distance (player_1.x, player_1.y, ball.x, ball.y) < player_1.radius + ball.radius then
        if ~player_1.serving and player_1.ball_enter_player then
            player_1.hits_left -= 1
            player_1.ball_enter_player := false
        end if
        player_1.GFdist := Math.Distance (player_1.x, player_1.y, ball.x, ball.y)
        player_1.GFforce := player_1.GFstrength * (1 / player_1.GFdist * player_1.GFdist)
        if player_1.x = ball.x then
            player_1.GFangle := 0
        else
            player_1.GFangle := arctand ((player_1.x - ball.x) / (player_1.y - ball.y))
        end if
        if ball.y < player_1.y then
            player_1.GFangle += 180
        end if
        ball.vx += player_1.GFforce * sind (player_1.GFangle)
        ball.vy += player_1.GFforce * cosd (player_1.GFangle)
        player_2.hits_left := 3
        player_2.serving := false
    else
        player_1.ball_enter_player := true
    end if


That's just for player 1. Player 2 is the same, only reversed.
Sorry for the lack of comments. If you don't understand it, check out the tutorial. It should help. Wink
When I spoke about reducing the lines to around 200, I was referring to changing player_1 and player_2 into a player array consisting of 2 elements. Doing that would change this part.
MihaiG




PostPosted: Thu Dec 02, 2004 8:50 pm   Post subject: (No subject)

nice job Geoff i would give you bits... but it wouldn't matter.... try and make it 1 player make computer AI
zomg




PostPosted: Mon Dec 13, 2004 11:48 am   Post subject: (No subject)

u should have a 1 player mode and a 2 player mode
Cervantes




PostPosted: Tue Dec 14, 2004 9:20 pm   Post subject: (No subject)

I'm working on determining where the ball will land. Click Me

Actually, it would ultimately be best to be able to determine where it will land using any two points, not just a point and the vertex of the parabola. Anyone know how to do this? Or fix the problems in the program linked?
Paul




PostPosted: Tue Dec 14, 2004 9:47 pm   Post subject: (No subject)

What do u mean using any 2 points?
We have to do an projectile motion program, that involves using a formula to determine, which involves time, horizontal velocity and verticle velocity and gravity. The one I made increases the time by 0.01 each time, and plugs in the velocities, so it'd tell me the x and y coordinates. But I don't suppose such a simple thing is what ur looking for, for you'd have seen it already.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Dec 14, 2004 9:57 pm   Post subject: (No subject)

By any two points I mean:
In the program I posted, I used a point on the parabola (I assigned it immediately) and the vertex to determine where the ball will land. This, however, requires that the ball have reached the vertex before the computer slime can move into position. It would be best if I only needed two points on the parabola. ie. the first point is assigned immediately. The second point is assigned right after ball.x and ball.y have been updated once.

Sounds like an interesting program that you are making. Though I don't need to determine the horizontal velocity, verticle velocity, and gravity, because I already know those. I need to determine ahead of time where the ball is going to land so that I can move the computer slime into position to return the shot.
GlobeTrotter




PostPosted: Tue Dec 14, 2004 11:22 pm   Post subject: (No subject)

say your two points were (1,1) and (2,2) and you know the final y value will be 0 as well as your starting y value, to find where it will end do this

a(x-h)2 + k = y

a(1-h)2 + 0 = 1
a(2-h)2 + 0 = 2

sub the equations together to solve for 'a' then 'h'. That should give you a full equation. You can then find the roots.

This is assuming that he starts the jump and lands the jump at y = 0, remember.

Also, if you only check one step after it is launched, you will get skewed results. You should check a couple steps after.
Cervantes




PostPosted: Wed Dec 15, 2004 4:03 pm   Post subject: (No subject)

Why did you suddenly make k = 0? (k is the y vertex, right?)
GlobeTrotter wrote:
the final y value will be 0 as well as your starting y value

Well, the starting y is not necesasrily 0. The player can hit it in the air. Though this
GlobeTrotter wrote:

This is assuming that he starts the jump and lands the jump at y = 0, remember.

is correct.
(or I can make it correct, easily enough, by skewing the drawing parameters)
GlobeTrotter




PostPosted: Wed Dec 15, 2004 6:07 pm   Post subject: (No subject)

oops, you're right, sorry.

I mixed up a circle and a quadratic, yeah. I guess you're going to have to do this then. You're 'a' value will be a constant based on your gravity and jump speed. Calculate that then plug that into the equation along with the other 2 points. That should work

(Say you calculated a to be -1 and your two points were 1,1 and 2,2)

a(x-h)2 + k = y

-(1-h)2 + k = 1
-(2-h)2 + k = 2

1 + (1-h)2 = 2 + (2-h)2

Then solve for h. Use this value to solve for k. Then solve for the roots of the equation, or if you want to get more complex. Say you have a wall with the equation x = -20 another wall with the equation x = 20 and another wall w/ equation y = 0, you could find the points of intersection of the quadratic with the line. You'll have to do an if statement before plugging it in though, otherwise you might get an error of a negative root if they don't intersect.

I haven't really looked at your code, and if you have different jump speeds based on how quickly you press the jump button, you'll have problems.

edit: shit, didn't realize you wanted where the ball would land, I was talking about players. That sucks, you'll have different a values. I'm not sure then, sorry.
hdef




PostPosted: Mon Dec 20, 2004 6:22 pm   Post subject: (No subject)

runs smooth and fast on my comp... and its only an 800
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 3 of 3  [ 43 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: