Need help with my "VolleyBall" Game
Author |
Message |
xdanielx98
![](http://compsci.ca/v3/uploads/user_avatars/1350565375476aaac21b7f4.jpg)
|
Posted: Thu Dec 20, 2007 9:28 am Post subject: Need help with my "VolleyBall" Game |
|
|
Hi, this is my first attempt at making a game which incorporates simulated gravity and incorporates the balls relative position to an object to modify how the ball will react to the object, I have got it so that the ball will bounce off of the blobs correctly but every time I try to change the angle that the ball bounces at the ball just kinda goes crazy...
Quote: var width, height, XB, YB, xdir, ydir : int
var y, x : int
var theta2, tim3, velocity2 : real
var blobx1, bloby1, blobx2, bloby2 : int
var velocity, tim, tim2, theta, gravity, x2, y2, x3, y3 : real
var x1, y1 : int
var key : array char of boolean
var count : int
var jump : int
var serve, fserve : int
var pscore1, pscore2 : int
var timdir : int
timdir := 1
theta2 := 90
tim3 := 0
velocity2 := 2
x := 300
pscore1 := 0
pscore2 := 0
jump := 0
width := 50
height := 50
blobx1 := 150
bloby1 := 10
blobx2 := 490
bloby2 := 10
y := 200
randint (fserve, 1, 2)
tim := 0
tim2 := 0
theta := 90
gravity := 0.02
x2 := 1
y2 := 1
x3 := 1
y3 := 1
velocity := 2
xdir := 1
ydir := 1
YB := 200
View.Set ("offscreenonly")
%Blur Procedure to erase all objects with a fading design
procedure Blur (I, C : int)
for B : 1 .. I
drawline (Rand.Int (1, maxx), Rand.Int (1, maxy),
Rand.Int (1, maxx), Rand.Int (1, maxy), C)
end for
end Blur
loop
%Deciding on which player will server and how the ball reacts to server
if fserve = 1 then
XB := round (x + velocity2 * tim3 * cosd (theta2)) - 150
YB := round (y + velocity2 * tim3 * sind (theta2) - 0.5 * gravity * tim3 * tim3)
elsif fserve = 2 then
XB := round (x + velocity2 * tim3 * cosd (theta2)) + 190
YB := round (y + velocity2 * tim3 * sind (theta2) - 0.5 * gravity * tim3 * tim3)
end if
%All drawings contained within tha program
tim3 := tim3 + timdir
count := 1
Blur (100, brightblue)
drawfill (30, 30, brightblue, brightblue)
drawfillbox (0, 0, 640, 10, darkgray)
drawfillbox (305, 10, 335, 100, black)
drawfillarc (blobx1, bloby1, width, height, 0, 180, brightred)
drawfillarc (blobx2, bloby2, width, height, 0, 180, brightgreen)
drawfilloval (round (XB), round (YB), 10, 10, 14)
View.Update
Input.KeyDown (key)
delay (10)
%Causing ball to bounce into air by revercing timdir to the opposite of what it is.
%Requires reversal to have tim continue to function in positive numbers effecting gravity properly
if XB >= blobx1 - 10 and XB <= blobx1 + 10 and YB <= bloby1 + 60 and YB >= bloby1 then
theta2 := 90
if timdir = 1 then
timdir := -1
tim3 := tim3 - 5
elsif timdir = -1 then
timdir := 1
tim3 := tim3 + 5
end if
elsif XB <= blobx1 - 20 and XB >= blobx1 - 30 and YB <= bloby1 + 50 and YB >= bloby1 then
theta2 := 75
if timdir = 1 then
timdir := -1
tim3 := tim3 - 5
elsif timdir = -1 then
timdir := 1
tim3 := tim3 + 5
end if
elsif XB <= blobx1 - 30 and XB >= blobx1 - 40 and YB <= bloby1 + 40 and YB >= bloby1 then
theta2 := 50
if timdir = 1 then
timdir := -1
tim3 := tim3 - 5
elsif timdir = -1 then
timdir := 1
tim3 := tim3 + 5
end if
elsif XB <= blobx1 - 40 and XB >= blobx1 - 50 and YB <= bloby1 + 30 and YB >= bloby1 then
theta2 := 30
if timdir = 1 then
timdir := -1
tim3 := tim3 - 5
elsif timdir = -1 then
timdir := 1
tim3 := tim3 + 5
end if
elsif XB <= blobx1 - 50 and XB >= blobx1 - 60 and YB <= bloby1 + 20 and YB >= bloby1 then
theta2 := 20
if timdir = 1 then
timdir := -1
tim3 := tim3 - 5
elsif timdir = -1 then
timdir := 1
tim3 := tim3 + 5
end if
%Second Blob animation section
elsif XB >= blobx2 - 5 and XB <= blobx2 + 5 and YB <= bloby2 + 60 and YB >= bloby2 then
theta2 := 90
if timdir = 1 then
timdir := -1
tim3 := tim3 - 5
elsif timdir = -1 then
timdir := 1
tim3 := tim3 + 5
end if
end if
put pscore2
put pscore1
%Scoring system for player 1 and 2
if YB <= 0 and XB <= 305 then
pscore2 := pscore2 + 1
serve := 1
elsif YB = 0 and XB >= 335 then
pscore1 := pscore1 + 1
serve := 2
if serve = 1 then
elsif serve = 2 then
end if
end if
%if key is up arrow then it will cause the blob to jump
if key (KEY_UP_ARROW) then
jump := 1
end if
if jump = 1 then
bloby1 := round (y3 + velocity * tim * sind (theta) - 0.5 * gravity * tim * tim)
tim := tim + 1
if tim2 >= 50 then
bloby2 := round (y2 + velocity * tim2 * sind (theta) - 0.5 * gravity * tim2 * tim2)
tim2 := tim2 + 1
end if
drawfillarc (blobx1, bloby1, width, height, 0, 180, brightred)
drawfillarc (blobx2, bloby2, width, height, 0, 180, brightgreen)
if bloby1 <= 2 then
bloby1 := 10
jump := 0
end if
end if
%if key is left arrow then it will cause the blob to go left
if key (KEY_LEFT_ARROW) and blobx1 > 50 then
blobx1 := blobx1 - 1
%if key is right arrow then it will cause the blob to go left
elsif key (KEY_RIGHT_ARROW) and blobx1 < 250 then
blobx1 := blobx1 + 1
end if
%if key is "a" then it will cause the blob to go left
if key ('a') and blobx2 > 390 then
blobx2 := blobx2 - 1
%if key is "d" then it will cause the blob to go right
elsif key ('d') and blobx2 < 590 then
blobx2 := blobx2 + 1
end if
%if key is "w" then it will cause the blob to jump
if key ('w') then
jump := 3
end if
%x3 := blobx1
if jump = 3 then
if tim >= 50 then
bloby1 := round (y3 + velocity * tim * sind (theta) - 0.5 * gravity * tim * tim)
tim := tim + 1
end if
bloby2 := round (y2 + velocity * tim2 * sind (theta) - 0.5 * gravity * tim2 * tim2)
tim2 := tim2 + 1
drawfillarc (blobx1, bloby1, width, height, 0, 180, brightred)
drawfillarc (blobx2, bloby2, width, height, 0, 180, brightgreen)
if bloby2 <= 2 then
bloby2 := 10
jump := 0
end if
%text that has been placed to act as a debugger in program, allows me to watch all of the variables that effect
%ball bouncing and blobs jumping
end if
color (white)
locatexy (100, 300)
colorback (brightblue)
put tim
color (white)
colorback (brightblue)
locatexy (300, 300)
put tim2
color (white)
colorback (brightblue)
put tim3
color (white)
colorback (brightblue)
put timdir
color (white)
colorback (brightblue)
put YB
if tim >= 201 then
tim := 0
end if
if tim2 >= 201 then
tim2 := 0
end if
end loop
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Volley Ball (in work).t |
Filesize: |
6.18 KB |
Downloaded: |
81 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Zampano
![](http://compsci.ca/v3/uploads/user_avatars/123384421747e86c6cddac1.gif)
|
Posted: Thu Dec 20, 2007 9:50 am Post subject: Re: Need help with my "VolleyBall" Game |
|
|
Is this original? I feel that I have played this same game before in Turing with the same graphics, but I can't remember where.
|
|
|
|
|
![](images/spacer.gif) |
Gackt
![](http://compsci.ca/v3/uploads/user_avatars/692715419476846d0b1db8.gif)
|
Posted: Thu Dec 20, 2007 9:58 am Post subject: Re: Need help with my "VolleyBall" Game |
|
|
Zampano @ 20th December, 9:50 am wrote: Is this original? I feel that I have played this same game before in Turing with the same graphics, but I can't remember where.
Actually, he got the idea from the game from the other one on here. XD
|
|
|
|
|
![](images/spacer.gif) |
xdanielx98
![](http://compsci.ca/v3/uploads/user_avatars/1350565375476aaac21b7f4.jpg)
|
Posted: Thu Dec 20, 2007 11:26 am Post subject: Re: Need help with my "VolleyBall" Game |
|
|
yes, it is original, I got the idea from a game that had been posted on this site in the submition section, the game was called "Amazing Game" or something down those lines. I used the game to learn a lot of what I have put into this program except I wrote every line of it myself, I have to give credit to the original creator for the blur procedure though, I used practically the same code that was in the original game for the blur design... and as more proof that it is my own... my program doesnt work lol... the original program deffinately does
|
|
|
|
|
![](images/spacer.gif) |
xdanielx98
![](http://compsci.ca/v3/uploads/user_avatars/1350565375476aaac21b7f4.jpg)
|
Posted: Thu Dec 20, 2007 12:04 pm Post subject: Re: Need help with my "VolleyBall" Game |
|
|
Here is a slightly revised version of my program... I removed some un necisary lines of code from the program but I still havent been able to get the ball moving on an angle based on its impact with the blob.
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Volley Ball (in work).t |
Filesize: |
5.2 KB |
Downloaded: |
68 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
|
|