Need help with my slime volley ball
Author |
Message |
thainfamous
|
Posted: Sat Nov 27, 2004 1:04 pm Post subject: 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.
code: |
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
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Nov 27, 2004 1:47 pm Post subject: (No subject) |
|
|
What do you mean "i need help with the ball and how to impliment it"?
Do you mean, Circular Collision Data? |
|
|
|
|
![](images/spacer.gif) |
thainfamous
|
Posted: Sat Nov 27, 2004 4:54 pm Post subject: (No subject) |
|
|
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 |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Nov 27, 2004 5:52 pm Post subject: (No subject) |
|
|
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:
code: |
var ball :
record
x, y, vx, vy : real
radius, clr : int
end record
|
There's your ball.
Now, to apply gravity to it:
code: |
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:
code: |
if ball.x + ball.radius >= maxx or ball.x - ball.radius <= 0 then
ball.vx *= -1
end if
|
add that somewhere in the main loop. I suggest just before the bit involving gravity and updating the x and y pos. of the ball.
After that, you need to keep track of where the ball lands.
code: |
if ball.y - ball.radius <= 0 then
if ball.x < maxx div 2 then
%ball landed on the left side. Give player 2 a point and reset the players and the ball
else
%ball landed on the right side. Give player 1 a point and reset the players and the ball
end if
end if
|
add that code in somewhere in the main loop. I suggest after the previous bit about bouncing off the wall.
Next, you need to make the ball bounce off the players, which is by far the hardest thing to do. Visit my Circular Collision Data Tutorial and read up on some of compsci.ca's methods for achieving this. Pick one, or make your own, and try to get it to work.
Best of luck! I spent a long time trying to make a Slime Volleyball program. Know that it can be done.
Feel free to ask any more questions
-Cervantes |
|
|
|
|
![](images/spacer.gif) |
thainfamous
|
Posted: Sat Nov 27, 2004 6:06 pm Post subject: (No subject) |
|
|
wow thanks alot man, ya i was trying to figure that out, im only in gr 10 comp sci, and just finished learning about for loops:| in class so it is difficult for me |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Nov 27, 2004 6:15 pm Post subject: (No subject) |
|
|
I take it you are ahead of the class, given that you are using types, functions, Input.KeyDown, arrays, and double buffering. 8) |
|
|
|
|
![](images/spacer.gif) |
thainfamous
|
Posted: Sat Nov 27, 2004 6:19 pm Post subject: (No subject) |
|
|
maybe, wen i do the stuff u tell me it doesnt show my slimes on the screen and it only shows the ball do u know why, and have u tried the stuff u told me in my code? |
|
|
|
|
![](images/spacer.gif) |
thainfamous
|
Posted: Sat Nov 27, 2004 6:20 pm Post subject: (No subject) |
|
|
do you use msn messenger it would be easier to take to yu there |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Nov 27, 2004 6:58 pm Post subject: (No subject) |
|
|
This little image should tell you I use MSN: . Hover your mouse over it in one of my posts.
As for your program: I personally never saw the slimes when I ran your original code. Mind you, that's probably because I don't have black.jpg on my computer.
No, I have not tried my code in conjunction with yours. |
|
|
|
|
![](images/spacer.gif) |
thainfamous
|
Posted: Sat Nov 27, 2004 7:06 pm Post subject: (No subject) |
|
|
it does not show a @hotmail.com or @msn.com addresss so wut is the email id like to ask u questions on msn messenger |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Nov 27, 2004 7:23 pm Post subject: (No subject) |
|
|
True, it does not. I use mail @compsci.ca. I use it for MSN as well. try it, I guarantee it'll work ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|