Ball Collision Game
Author |
Message |
FeZbOy
![](http://70.84.92.67/esports/img/avatars/0003166_small.jpg)
|
Posted: Tue Mar 08, 2005 12:41 pm Post subject: Ball Collision Game |
|
|
I am a fairly new programmer and i need a little help. My program is almost finished, but i need to add a few things. Here is the code...
code: | var x, y : int := 10
var chars : array char of boolean
var cx, dx : int := 30
var cy, dy : int := 30
var score, count : int := 0
var p1health, p2health : int := 20
loop
dx += 1
dy += 1
delay (2)
View.Set ("offscreenonly")
cls
Draw.FillBox (cx, cy, cx + 20, cy + 20, green)
Draw.FillOval (x, y, 10, 10, red)
Draw.FillOval (dx, dy, 10, 10, blue)
View.Update
Input.KeyDown (chars)
if x < 15 then
x += 1
elsif x > maxx - 15 then
x -= 1
elsif y < 15 then
y += 1
elsif y > maxy - 15 then
y -= 1
else
if chars (KEY_UP_ARROW) then
y := y + 2
elsif chars (KEY_DOWN_ARROW) then
y := y - 2
elsif chars (KEY_LEFT_ARROW) then
x := x - 2
elsif chars (KEY_RIGHT_ARROW) then
x := x + 2
end if
if cx < 5 then
cx += 1
elsif cx > maxx - 25 then
cx -= 1
elsif cy < 0 then
cy += 1
elsif cy > maxy - 25 then
cy -= 1
else
if chars ('w') then
cy := cy + 2
elsif chars ('s') then
cy := cy - 2
elsif chars ('a') then
cx := cx - 2
elsif chars ('d') then
cx := cx + 2
end if
end if
if dx + 10 < 0 or dx > maxx then
dx *= -1
elsif dy + 10 < 0 or dy > maxy then
dy *= -1
end if
end if
end loop
|
In this program, I need 2 things:
- When the balls collide, they lose health
and
- The 3 ball, Ball DX, keeps going out off the edge!
Any help will be appreciated!
Thx
P.S. Feel Free to modify this program! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Tue Mar 08, 2005 12:48 pm Post subject: (No subject) |
|
|
var this
code: |
var difx, dify : int := 1
|
then change this
code: |
dx += difx
dy += dify
|
and this
code: |
if dx - 10 <= 0 or dx + 10 >= maxx then
difx *= -1
elsif dy - 10 < 0 or dy + 10 >= maxy then
dify *= -1
end if
| [/code] |
|
|
|
|
![](images/spacer.gif) |
FeZbOy
![](http://70.84.92.67/esports/img/avatars/0003166_small.jpg)
|
Posted: Tue Mar 08, 2005 12:50 pm Post subject: (No subject) |
|
|
Thanks Alot! |
|
|
|
|
![](images/spacer.gif) |
Martin
![](http://www.compsci.ca/wiki/images/4/46/CanadianStickUp.jpg)
|
Posted: Tue Mar 08, 2005 1:23 pm Post subject: (No subject) |
|
|
You should really comment your code. |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Tue Mar 08, 2005 2:20 pm Post subject: (No subject) |
|
|
yeah i should, people always ask me too, it'd save time... |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Wed Mar 09, 2005 8:39 am Post subject: (No subject) |
|
|
code: |
var difx, dify : int := 1 % larger the number, faster the ball, determines how many pixels it goes by (bothx x and y values)
dx += difx
dy += dify %adding the difference to the ball variables to make them move
if dx - 10 <= 0 or dx + 10 >= maxx then
difx *= -1
elsif dy - 10 < 0 or dy + 10 >= maxy then
dify *= -1
end if % if the ball hits a wall, change direction
|
I hope this helps you out a lil bit if you didn't understand what it ment b4. |
|
|
|
|
![](images/spacer.gif) |
FeZbOy
![](http://70.84.92.67/esports/img/avatars/0003166_small.jpg)
|
Posted: Wed Mar 09, 2005 9:25 pm Post subject: (No subject) |
|
|
jamonathin wrote: I hope this helps you out a lil bit if you didn't understand what it ment b4.
I got it the first time... thaks again ne ways! |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Thu Mar 10, 2005 6:43 am Post subject: (No subject) |
|
|
np. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|